getnameinfo specifies socklen_t
Posted
by bobby
on Stack Overflow
See other posts from Stack Overflow
or by bobby
Published on 2010-05-04T12:15:03Z
Indexed on
2010/05/04
12:18 UTC
Read the original article
Hit count: 300
The 2nd arg for the getnameinfo prototype asks for a socklen_t type but sizeof uses size_t. So how can I get socklen_t ?
Prototype:
int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
char *restrict node, socklen_t nodelen, char *restrict service,
socklen_t servicelen, int flags);
Example:
struct sockaddr_in SIN;
memset(&SIN, 0, sizeof(SIN)); // This should also be socklen_t ?
SIN.sin_family = AF_INET;
SIN.sin_addr.s_addr = inet_addr(IP);
SIN.sin_port = 0;
getnameinfo((struct sockaddr *)&SIN, sizeof(SIN) /* socklen_t */, BUFFER, NI_MAXHOST, NULL, 0, 0);
© Stack Overflow or respective owner