Linux中套接口socket,bind函数测试,bzero警告解决方法
#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;
#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>
相关推荐
lzzyok 2020-10-10
无情的你无情的雨 2020-06-16
chunianyo 2020-06-04
grantlee 2020-05-28
xjp 2020-05-26
Roka 2020-05-25
天空一样的蔚蓝 2020-05-02
nangongyanya 2020-04-19
shufen0 2020-04-14
humanbeng 2020-03-05
Alanxz 2020-03-04
liwf 2020-02-17
歆萌 2020-02-10
tianchaoshangguo 2020-01-04
julien 2020-01-02
齐天大圣数据候 2019-12-28
杨友山 2019-12-25
GavinZhera 2019-12-19
oLeiShen 2019-12-15