Annotation of 42BSD/ingres/source/support/initsocket.c, revision 1.1.1.1

1.1       root        1: # include      <stdio.h>
                      2: # include      <sys/types.h>
                      3: # include      <sys/socket.h>
                      4: # include      <sys/ioctl.h>
                      5: # include      <netinet/in.h>
                      6: # include      <netdb.h>
                      7: # include      <signal.h>
                      8: 
                      9: static char    Sccsid[] = "%W% (INGRES) %G%";
                     10: 
                     11: /*
                     12: ** init_socket
                     13: ** initilize the socket to the socket server
                     14: */
                     15: init_socket()
                     16: {
                     17:        register        int     from_socket;    /* file descriptor to attach to socket server */
                     18:        int     to_ioctl = 1;                   /* used in ioctl call */
                     19:        struct  sockaddr_in     addr;           /* address where socket server is */
                     20:        char    hostname[BUFSIZ];               /* hostname */
                     21:        struct  servent         *server;
                     22:        struct  hostent         *myhost;
                     23:        auto    int             len;
                     24:        extern  int             errno;
                     25: 
                     26:        if ( (len = fork()) != 0 )
                     27:        {
                     28: # ifdef        DEBUG
                     29:                printf("lock driver becomes %d\n",len);
                     30: # endif        DEBUG
                     31:                if ( len == -1 )
                     32:                {
                     33:                        perror("ingres lock driver, fork");
                     34:                        exit(errno);
                     35:                }
                     36:                exit(0);
                     37:        }
                     38:        if ( (from_socket = socket(AF_INET,SOCK_STREAM,0)) == -1 )
                     39:        {
                     40: # ifdef        DEBUG
                     41:                perror("INIT_S socket");
                     42: # endif        DEBUG
                     43:                exit(errno);
                     44:        }
                     45:        len = BUFSIZ;
                     46:        gethostname(hostname,&len);
                     47: 
                     48:        if ( (server = getservbyname("ingreslock",(char *)0)) == 0 )
                     49:                exit(errno);
                     50: 
                     51:        if ( (myhost = gethostbyname(hostname)) == 0 )
                     52:                exit(errno);
                     53:        bzero((char *) &addr,sizeof (addr));
                     54:        bcopy(myhost->h_addr,(char *)&addr.sin_addr,myhost->h_length);
                     55:        addr.sin_family = AF_INET;
                     56:        addr.sin_port = server->s_port;
                     57:        len = sizeof (addr);
                     58:        if ( bind(from_socket,&addr,len) == -1 )
                     59:        {
                     60: # ifdef        DEBUG
                     61:                perror("INIT_S bind, assuming driver already running");
                     62: # endif        DEBUG
                     63:                exit(0);
                     64:        }
                     65: 
                     66:        if ( listen(from_socket,10) == -1 )
                     67:        {
                     68:                perror("Ingres lock, can't listen on port");
                     69:                exit(errno);
                     70:        }
                     71:        ioctl(from_socket,FIONBIO,&to_ioctl);
                     72:        return ( from_socket );
                     73: }/* init_socket */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.