getaddrinfo Reading IP Address value from res->ai_addr

Martin McCormick martin at dc.cis.okstate.edu
Fri Jan 13 16:59:02 UTC 2012


I am experimenting with getaddrinfo and getnameinfo and have
gotten a little confused as to the best way to extract the
IP address recovered after the function runs. The element in the
structure 
res->ai_addr is a socket address which, if I am reading the
documentation correctly, will give me the binary form of the
internet address of the host I just looked up.

	Is that correct? Also, what is the easiest way to
extract that value in to an unsigned long?

	Wikipedia has an excellent sample program that uses
getaddrinfo to resolve a name to an IP address and then
getnameinfo to reverse the lookup back to a name, but
getnameinfo just takes res->ai_addr as an argument and works
great, but one doesn't see how it extracted the IP address.

	Thanks for all good suggestions.

Martin McCormick WB5AGZ  Stillwater, OK 
Systems Engineer
OSU Information Technology Department Telecommunications Services Group



More information about the bind-users mailing list