Example: Translate sockaddr into string char hbuf[1024], pbuf[1024]; /* string if possible, like www.kame.net/http */ if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), 0) != 0) errx(1, "invalid address"); /* numeric address, like 127.0.0.1/80 */ if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), NI_NUMERICHOST|NI_NUMERICSERV) != 0) errx(1, "invalid address");