accept problem


 
Thread Tools Search this Thread
Operating Systems HP-UX accept problem
# 1  
Old 07-20-2004
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 (;;)
{
accept();
.
.
.
}

}


Anyone could explain and solve it?

Last edited by Perderabo; 07-22-2004 at 08:31 AM..
# 2  
Old 07-21-2004
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
# 3  
Old 07-21-2004
The program runs normally on the othe OS, such as AIX, Solaris, True 64, but ... ; The source code looks like the following:


Code:
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); 
  }


Last edited by Perderabo; 07-22-2004 at 08:29 AM..
# 4  
Old 07-22-2004
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!
# 5  
Old 07-22-2004
Quote:
Originally posted by Driver
By the way, the next time you post code, enclose it between code tags.
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX script can accept 1 to n parameters

Just for my leaning purpose, I appreciate if someone answer my question: A UNIX script can accept 1 to n parameters. For each of these parameters, write out the parameter id number and its value. (1 Reply)
Discussion started by: shumail
1 Replies

2. Emergency UNIX and Linux Support

Solaris LDAPCLIENT accept CA

Hey Guys, How can I make the Solaris native ldapclient trust a CA? I am trying to use a selfsigned cert and it is not working. WHen I use ssltap to monitor the ssl traffic it shows this for the last client communication: 0: 15 03 01 00 02 02 30 | ......0 (7... (1 Reply)
Discussion started by: s ladd
1 Replies

3. UNIX for Advanced & Expert Users

ln -s accept wildcards?

Does ln -s accept wildcards? It doesn't seem like it is working when I use wildcards. (9 Replies)
Discussion started by: cokedude
9 Replies

4. Programming

socket accept() keeps looping

I'm using C/ C++ with gcc on Linux. I've a server socket where accept() is called on the socket inside a while() loop. The problem I am facing is that the first call to accept is blocking (i.e., the program waits for the first connection) but as soon as I fork afterwards (so that the child process... (2 Replies)
Discussion started by: jaywalker
2 Replies

5. Infrastructure Monitoring

Accept SNMP Packets...

hi guys I've configured snmp on some linux snmpd.conf rocommunity com_read x.x.x.10 rwcommunity com_write x.x.x.10 Now one of my coworkers asked to do the same that he does on windows for my linux.... But I have no idea how to configure that basically when SNMP is configure there... (5 Replies)
Discussion started by: karlochacon
5 Replies

6. UNIX for Dummies Questions & Answers

accept user input?

how would i accept user input from the keyboard? (2 Replies)
Discussion started by: JamieMurry
2 Replies

7. UNIX for Dummies Questions & Answers

Command to accept input

I am trying to write a one line command for Oracle grid control. I am using a semi-colon to separate the commands. But, I am having a problem with a shell script accepting input. Wondering if you can help. Here is what I am trying to do: (PGPRD5432)@prd01:/> cd /export/home/postgres ##... (3 Replies)
Discussion started by: rexmabry
3 Replies

8. Programming

problem with accept() on Fedora 8

hi, accept() seems to be still blocking after socket is being closed on our Fedora 8 build. not sure if this is a common problem because i have never experienced this on any other platforms, however i have seen someone else having this issue on Redhat 7 and 9. so is there a socket option fedora... (10 Replies)
Discussion started by: Akimaki
10 Replies

9. Shell Programming and Scripting

Accept input parameters

Dear All, I got a table creation file in a standard format. I need to accept parameters from the user & then based on the input change the data in the file. For. eg. i will accept the database name, dbspace name & user name from the user and accordingly change the same in the table creation... (2 Replies)
Discussion started by: lloydnwo
2 Replies
Login or Register to Ask a Question