Modern code should not use struct in_addrdirectly, but rather sockaddr_in. It would be even better to never create or not create any structures at all sockaddr, but to do everything through library calls getaddrinfoand getnameinfo. For example, to search for a host IP address or text form:
struct addrinfo *ai;
if (getaddrinfo("8.8.8.8", 0, 0, &ai)) < 0) goto error;
And to get the name (or the address of the ip-form of the text form, if it does not cancel, resolve) the address:
if (getnameinfo(ai.ai_addr, ai.ai_addrlen, buf, sizeof buf, 0, 0, 0) < 0) goto error;
, , sockaddr, getpeername getsockname recvfrom. sockaddr_storage, .
:
- , ( ip ..) .
- IPv6 (, , , IPv4).
gethostbyname gethostbyaddr POSIX, //.
source
share