inet_ntop()¶
Purpose¶
inet_ntop() converts a binary network address to a printable string.
It is useful for logging peer IP addresses after accept().
Header¶
Prototype¶
Minimal Example¶
char ip[INET_ADDRSTRLEN];
if (!inet_ntop(AF_INET, &peer.sin_addr, ip, sizeof(ip))) {
perror("inet_ntop");
return -1;
}
Common Pitfalls¶
- Using a buffer that is too small.
- Passing the wrong address family.
- Passing the address of the wrong field inside
sockaddr_in.