红联Linux门户
Linux帮助

Linux中套接口socket,bind函数测试,bzero警告解决方法

发布时间:2014-12-03 15:16:44来源:linux网站作者:koutatu

#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
main()
{
int nSocket;
struct sockaddr_in sin;
//struct sockaddr_in *p = &sin;
nSocket = socket(PF_INET,SOCK_STREAM,0);
bzero(&sin,sizeof(struct sockaddr_in));
//memset(p,0x00,sizeof(struct sockaddr_in));
sin.sin_family=AF_INET;
sin.sin_addr.s_addr=htonl(INADDR_ANY);
sin.sin_port=htons(5678);
bind(nSocket,(struct sockaddr *)&sin,sizeof(struct sockaddr_in));
printf("Bind success! \n");
close(nSocket);
return;
}


警告内容:
testSocketBind.c: In function ‘main’:

testSocketBind.c:13: warning: incompatible implicit declaration of built-in function ‘bzero’


解决方法:

加上#include <string.h>