天道酬勤,学无止境

socklen-t

getnameinfo指定socklen_t(getnameinfo specifies socklen_t)

问题 getnameinfo原型的第二个arg要求使用socklen_t类型,但sizeof使用size_t。 那我怎么能得到socklen_t? 原型: int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags); 例子: 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); 这将导致编译器错误: socklen_t VAR; getnameinfo((struct sockaddr *)&SIN, &VAR, BUFFER, NI

2021-06-01 02:40:55    分类:技术分享    c   linux   networking   posix   socklen-t

getnameinfo specifies socklen_t

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); This will give compiler

2021-04-30 06:00:37    分类:问答    c   linux   networking   posix   socklen-t