accept problem

Hi, there
On HP-UX IA server, when calling 'accept' function in my program, the server never wait the client's connection. Each time, it accepted the request from IP address 0.0.0.0 even there is no client's connection. The server program looks like :

main()
{
.
.
.

listen();

for (;:wink:
{
accept();
.
.
.
}

}

Anyone could explain and solve it?

What I mean is that the function 'accept' returned sucessfully without waiting client connection, I also do error checking for all function calling, but there is no error reported. The returned IP address from 'accept' call is 0.0.0.0.
I do not known whether it is descripted clearlly, thanks

The program runs normally on the othe OS, such as AIX, Solaris, True 64, but ... ; The source code looks like the following:

void handle2(int signo) 
{ 
     printf("signal number: %d\n",signo); 
    return; 
} 

main(int argc,char **argv) 

 { 
   int sockfd,newsockfd,cli_len; 
   struct sockaddr_in cli_addr,serv_addr; 
   int maxseg,sendbufsize,recvbufsize,optlen; 
   int bufsize; 
   int ret; 
   struct servent *sp;          // point of services 
   char command[500]; 
   char hostname[34]; 

    

  // Open a socket of TCP(an internet stream socket) 

   signal(SIGALRM,handle2); 
   signal(SIGINT,handle2); 
   signal(SIGABRT,handle2); 
   signal(SIGFPE,handle2); 
   signal(SIGSEGV,handle2); 

        gethostname(hostname,34); 
if ((sockfd=socket(AF_INET,SOCK_STREAM,0))<0) 
    err_dump("server: can't open stream socket!"); 

  // Bind our local address so that the clint can connect to us 

  bzero((char*)&serv_addr,sizeof(serv_addr)); 
  serv_addr.sin_family=AF_INET; 
  serv_addr.sin_addr.s_addr =htonl(INADDR_ANY); 
  if((sp=getservbyname("rtereset","tcp"))==NULL){ 
      perror("tcp_init:unkown service\n"); 
      return(-1); 
      } 
  serv_addr.sin_port=sp->s_port; 

   bufsize=131072; 
  if(setsockopt(sockfd,SOL_SOCKET,SO_SNDBUF,&bufsize,sizeof(bufsize))<0) 
   { 
    perror("tcp_init setopt err:"); 
     return(-1); 
   } 
  if(setsockopt(sockfd,SOL_SOCKET,SO_RCVBUF,&bufsize,sizeof(bufsize))<0) 
   { 
    perror("tcp_init setopt err:"); 
     return(-1); 
   } 

 if(setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&bufsize,sizeof(bufsize))<0) 
   { 
       perror("tcp_init setopt err:"); 
       return -1; 
   } 
 if(setsockopt(sockfd,SOL_SOCKET,SO_REUSEPORT,&bufsize,sizeof(bufsize))<0) 
      { 
       perror("tcp_init setopt err:"); 
       return -1; 
   } 


  if (bind(sockfd, 
          (struct sockaddr *)&serv_addr, 
          sizeof(struct sockaddr_in))<0) 
     { 
        err_dump("server: can't bind local address!"); 
        return(-1); 
     } 
  listen(sockfd,8); 

  for(;;){ 
        // waiting for connection from clint process. 
        newsockfd=accept(sockfd, 
                        (struct sockaddr *)&cli_addr, 
                        &cli_len); 
        if (newsockfd<0)     //  Here it returned IP 0.0.0.0 and no error report. 
         { 
          if (errno == EINTR) 
               continue; 
           else 
           err_dump("server :accept error!"); 
             return(-1); 
         } 
       ret=recv(newsockfd,(char *)command ,500,0); 
        if (ret < 0) 
           { 
             err_dump("server : recv error!"); 
             return -1; 
           } 
   } 
 close(sockfd); 
        close(newsockfd); 
  }

I replaced the third arg of accept with socklen_t, and it does not be effective. The accept function returned 'newsockfd' is -1 and the errno=14(Bad address), the cli_addr is 0.0.0.0!

In addition to that, I'd like to point out that there is a "Disable smilies in this post" checkbox. I have edited the thread to add code tags and disable smilies where appropiate.