Sponsored Content
Full Discussion: accept problem
Operating Systems HP-UX accept problem Post 53669 by Frank2004 on Wednesday 21st of July 2004 10:55:16 PM
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..
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
SIGSETOPS(3)						   BSD Library Functions Manual 					      SIGSETOPS(3)

NAME
sigemptyset, sigfillset, sigaddset, sigdelset, sigismember -- manipulate signal sets LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <signal.h> int sigemptyset(sigset_t *set); int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signo); int sigdelset(sigset_t *set, int signo); int sigismember(const sigset_t *set, int signo); DESCRIPTION
These functions manipulate signal sets stored in a sigset_t. Either sigemptyset() or sigfillset() must be called for every object of type sigset_t before any other use of the object. The sigemptyset() function initializes a signal set to be empty. The sigfillset() function initializes a signal set to contain all signals. The sigaddset() function adds the specified signal signo to the signal set. The sigdelset() function deletes the specified signal signo from the signal set. The sigismember() function returns whether a specified signal signo is contained in the signal set. RETURN VALUES
The sigismember() function returns 1 if the signal is a member of the set, 0 otherwise. The other functions return 0 upon success. A -1 return value indicates an error occurred and the global variable errno is set to indicate the reason. ERRORS
These functions could fail if one of the following occurs: [EINVAL] signo has an invalid value. SEE ALSO
kill(2), sigaction(2), sigpending(2), sigprocmask(2), sigsuspend(2) STANDARDS
These functions are defined by IEEE Std 1003.1-1988 (``POSIX.1''). BSD
December 16, 2004 BSD
All times are GMT -4. The time now is 03:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy