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

Defined functions

init_socket defined in line 10; used 2 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1138
Valid CSS Valid XHTML 1.0 Strict