#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>