Discussion:
How to get IP address will be used by HTTP in C++
(too old to reply)
j***@yahoo.com
2008-02-01 22:22:03 UTC
Permalink
At the client side, when my client machine talks to server, the server
will see the IP address of my machine as part of HTTP request. My
question is how I can programmatically get this IP address which will
be used in HTTP request? I could use gethostname to get IP addresses,
but that is a list. How can I tell which one will be used?

Thanks very much in advance.

Leo
Volodymyr Shcherbyna
2008-02-01 23:22:55 UTC
Permalink
Use getsockname(...) in your client on connected socket to retrieve local
(source) address which is used by system.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by j***@yahoo.com
At the client side, when my client machine talks to server, the server
will see the IP address of my machine as part of HTTP request. My
question is how I can programmatically get this IP address which will
be used in HTTP request? I could use gethostname to get IP addresses,
but that is a list. How can I tell which one will be used?
Thanks very much in advance.
Leo
j***@yahoo.com
2008-02-02 00:34:33 UTC
Permalink
Basically I need to get the packet source IP address seen by
the server. The locally IP addres may be different from IP address
seen by
the server (consider the ISP case), right? Will getsockname still
work?

Leo
Kun Niu
2008-02-02 02:12:00 UTC
Permalink
In such case, you should implement your own protocol to get the nat ip used
by the client.
Add an HTTP header etc.
Hope this helps.
Post by j***@yahoo.com
Basically I need to get the packet source IP address seen by
the server. The locally IP addres may be different from IP address
seen by
the server (consider the ISP case), right? Will getsockname still
work?
Leo
Volodymyr Shcherbyna
2008-02-02 12:17:38 UTC
Permalink
I don't think so. You may return the global address of a client from server
in a header.
--
V
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by j***@yahoo.com
Basically I need to get the packet source IP address seen by
the server. The locally IP addres may be different from IP address
seen by
the server (consider the ISP case), right? Will getsockname still
work?
Leo
Alexander Nickolov
2008-02-15 20:56:20 UTC
Permalink
You can try talking the IGD protocol to a home Internet router
(more commonly known as UPnP for routers). Of course that only
works with home Internet routers where UPnP is enabled...

You can also talk to a public STUN or STUNT server.

Finally, you can have your own server return that information to
your clients (typically you'd just host a STUN/STUNT server).
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: ***@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by j***@yahoo.com
Basically I need to get the packet source IP address seen by
the server. The locally IP addres may be different from IP address
seen by
the server (consider the ISP case), right? Will getsockname still
work?
Leo
Scott Landsman
2011-03-23 20:48:33 UTC
Permalink
This post might be inappropriate. Click to display it.
Continue reading on narkive:
Loading...