recvfrom: Bad address

对于函数:

	if(len = recvfrom(sockfd,buf,BUFSIZ,0,(struct sockaddr *)&remote_addr,size_len)<0){
		perror("recvfrom");
		return 1;
	}
编译出现警告:

udpserver.c: In function ‘main’:
udpserver.c:31: warning: passing argument 6 of ‘recvfrom’ makes pointer from integer without a cast
/usr/include/sys/socket.h:166: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int’

运行之后出现:

recvfrom: Bad address
通过man recvfrom
      ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
                        struct sockaddr *src_addr, socklen_t *addrlen);
修改如下:

	if(len = recvfrom(sockfd,buf,BUFSIZ,0,(struct sockaddr *)&remote_addr,&size_len)<0){
		perror("recvfrom");
		return 1;
	}

你可能感兴趣的:(TCP/IP)