Click to See Complete Forum and Search --> : how to get the host ip


wyy_cq
October 15th, 1999, 04:23 AM
when i connect to internet through dial,
how can i get the host's ip address

October 15th, 1999, 05:29 AM
I don't know if you want know yourself address when you connect on ppp and achive a ip address.
you can input
"route print"
under dos window.

wyy_cq
October 15th, 1999, 11:02 PM
thanks a lot,
can you teach how to get it through c code

mdangers
October 16th, 1999, 11:54 AM
Hi !

try using gethostname(*) which fills a buffer with the name
of the local host.
Once you have the name, use gethostbyname(*) which
returns a pointer to a HOSTENT structure.
Next to other things this structure contains a list of
IP-addresses used by the host specified in the
call to gethostbyname.
if your computer is not part of an ip-network it should
only return the ip-address given to you by your provider.

regards,

Matthias.

wyy_cq
October 16th, 1999, 09:39 PM
thank you a lot,
and can you teach me how to get the ISP's ip address?

mdangers
October 17th, 1999, 10:01 AM
Hi again !

for what you want to do I think you need to get a bit deeper into the internals
of TCP/IP.
TCP/IP supports numerous options which you can fill in the header of
a TCP/IP-packet. One of these options lets you record the route that
a packet takes from a source host to a destination host. The IP-addresses
of all hosts along the route of the paket are actually written to the header
of the packet ( the header's length is not fixed ). The problem with
this option is that it's not supported by all IP-stacks ( that's what I know ).
Take a look at the RFCs for TCP/IP to get to the details.

Regards,

Matthias.