From http://udrepper.livejournal.com/16116.html :
/*getaddrinfo is not just for IPv6*/ I've heard far too often that getaddrinfo is only interesting for IPv6 and therefore can be ignored since one does not have IPv6. Aside from the fact that all programs should be protocol independent this statement is bogus. gethostbyname etc do not perform correctly in some situations where only ever IPv4 is involved. Assume you have an internal IPv4 network with, say, 192.168.x.y addresses. In addition you have a server (web server, for instance) which is also visible on the Internet. This server has two addresses: one 192.168.x.y address and one global address. The client is a NATed machine on the intranet. Now what happens if the nameserver returns both addresses to a query for the addresses of said server? With gethostbyname the addresses are returned to the caller in the order they are received from the DNS server. Maybe some randomization is applied. In short, it is possible that the internal machine gets sees the public IPv4 address and then connects to it. This is not only wasteful (the request has to be routed through a switch), it might even be dangerous (the traffic might actually have to go through the Internet). With getaddrinfo this is not the case. The sorting according to RFC 3484 makes sure that the internal address of the server is returned first. The sorting function will notice that the source address used on the client is also an internal address and therefore the internal address of the server is a better match than the global address. In summary, gethostbyaddr is not only about IPv6. The old interfaces were simply completely inadequate and should never be used. If you /still/ haven't converted your programs to use getaddrinfo instead of gethostbyname and gethostbyname2 do it now. I have written some time ago a brief intro <http://people.redhat.com/drepper/userapi-ipv6.html>. -- Best regards, Lucian Adrian Grijincu Software Developer Avira Soft srl [EMAIL PROTECTED] http://www.avira.com ----------------------------------------------------------- DISCLAIMER: This message is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. If you have received it by mistake please let us know by reply and then delete it from your system; you should not copy the message or disclose its contents to anyone. -----------------------------------------------------------
signature.asc
Description: OpenPGP digital signature
