能得到正确的端口,可是得到的IP却是0.0.0.0
为什么?请教大家,很急
3 个解决方案
#1
因为该SOCKET还没有与其它地址连接,而且在本地也没有用bind()。
#2
想获得本机IP地址可用一下代码:
char buff[100];
char *b, *bu;
HOSTENT * host;
gethostname(buff, 100);
host = gethostbyname(buff);
b = host->h_addr_list[0];
bu = inet_ntoa(*(struct in_addr *)b);
sUserIP = bu;
char buff[100];
char *b, *bu;
HOSTENT * host;
gethostname(buff, 100);
host = gethostbyname(buff);
b = host->h_addr_list[0];
bu = inet_ntoa(*(struct in_addr *)b);
sUserIP = bu;
#3
明白了,搞定,谢谢
#1
因为该SOCKET还没有与其它地址连接,而且在本地也没有用bind()。
#2
想获得本机IP地址可用一下代码:
char buff[100];
char *b, *bu;
HOSTENT * host;
gethostname(buff, 100);
host = gethostbyname(buff);
b = host->h_addr_list[0];
bu = inet_ntoa(*(struct in_addr *)b);
sUserIP = bu;
char buff[100];
char *b, *bu;
HOSTENT * host;
gethostname(buff, 100);
host = gethostbyname(buff);
b = host->h_addr_list[0];
bu = inet_ntoa(*(struct in_addr *)b);
sUserIP = bu;
#3
明白了,搞定,谢谢