linux下运行C程序的错误信息为 invalid argument
我在linux下运行一段C程序 出现的错误信息是accept error:invalid argument
程序的原代码是:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/wait.h>
#define SERVPORT 3333
#define BACKLOG 10
main()
{
int sockfd,client_fd,sin_size;/*sockfd:listen to socket;client_fd:data transmit*/
struct sockaddr_in my_addr;/*root adress massage*/
struct sockaddr_in remote_addr;/*client server address massage*/
if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1)
{
perror( "socket error! ");
exit(1);
}
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(SERVPORT);
my_addr.sin_addr.s_addr=INADDR_ANY;
bzero(&(my_addr.sin_zero),8);
if(bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr))==-1)
{
perror( "bind error ");
exit(1);
}
while(1)
{
sin_size=sizeof(struct sockaddr_in);
if((client_fd=accept(sockfd,(struct sockaddr *)&remote_addr,&sin_size))==-1)
{
perror( "accept error ");
continue;
}
printf( "received a connection from %s\n ",inet_ntoa(remote_addr.sin_addr));
if(!fork())
{
if(send(client_fd, "Hello,you are connected!\n ",26,0)==-1)
perror( "send error! ");
close(client_fd);
exit(0);
}
close(client_fd);
}
}
有知道的请帮帮忙好吗 非常非常感谢!
------解决方案--------------------该错误是由于安装了 PHNE_27886 补丁程序而没有安装相关补丁 PHNE_27651 导致的。
此问题可通过安装下列 ARPA 补丁程序和相关补丁解决:
PHNE_27886 s700_800 11.00 cumulative ARPA Transport patch
相关补丁:
PHNE_27651 s700_800 11.00 Cumulative STREAMS Patch
PHKL_21857 s700_800 11.00 enable IDS/9000, fix accept() syscall errors
PHKL_22142 s700_800 11.00 Cumulative LOFS, select(), IDS/9000 support
------解决方案--------------------while之前加个
if(listen(sockfd,3) < 0){
perror( "listen ");
exit(1);
}