|
|
1.1 ! root 1: # include <stdio.h> ! 2: # include <sys/types.h> ! 3: # include <sys/socket.h> ! 4: # include <netinet/in.h> ! 5: # include <netdb.h> ! 6: # include <signal.h> ! 7: # include <setjmp.h> ! 8: # include <sccs.h> ! 9: ! 10: SCCSID(@(#)lock.c 8.1 12/31/84) ! 11: ! 12: /* ! 13: ** start_up_lock_driver ! 14: ** Attempt to start up a connection to the lock driver. ! 15: ** We connect to a know address (a socket server sits there). ! 16: ** If we get a connection on this location, than we are talking ! 17: ** to the lock driver. If we timeout, then we assume the driver ! 18: ** isn't there. ! 19: ** ! 20: ** Returns ! 21: ** File descriptor attached to the lock driver ! 22: ** -1 on any error. ! 23: ** ! 24: ** Trace Flags ! 25: ** 28 ! 26: */ ! 27: start_up_lock_driver() ! 28: { ! 29: struct sockaddr_in addr; /* address to attach to for server */ ! 30: register int to_driver; /* we can talk to the lock driver on this one */ ! 31: auto int hostlen; /* length of the hostname */ ! 32: register char *host; /* name of this host */ ! 33: char hname[BUFSIZ]; ! 34: struct servent *ing_ser; ! 35: struct hostent *myhost; ! 36: ! 37: ! 38: /* ! 39: ** Find out where the lock driver lives ! 40: */ ! 41: if ( (ing_ser = getservbyname("ingreslock",(char *)0)) == 0 ) ! 42: { ! 43: # ifdef xATR1 ! 44: if ( tTf(28,4) ) ! 45: perror("set_up_lock getservbyname"); ! 46: # endif ! 47: return ( -1 ); ! 48: } ! 49: ! 50: /* ! 51: ** Make our end of the socket ! 52: */ ! 53: if ( (to_driver = socket(AF_INET,SOCK_STREAM,0)) == -1 ) ! 54: { ! 55: # ifdef xATR1 ! 56: if ( tTf(28,4) ) ! 57: perror("set_up_lock socket"); ! 58: # endif ! 59: return ( -1 ); ! 60: } ! 61: ! 62: host = hname; ! 63: hostlen = BUFSIZ; ! 64: gethostname(hname,&hostlen); ! 65: if ( (myhost = gethostbyname(host)) == 0 ) ! 66: { ! 67: # ifdef xATR1 ! 68: if ( tTf(28,4) ) ! 69: perror("set_up_lock gethostbyname"); ! 70: # endif ! 71: close(to_driver); ! 72: return ( -1 ); ! 73: } ! 74: bzero((char *) &addr,sizeof (addr)); ! 75: bcopy(myhost->h_addr,(char *)&addr.sin_addr,myhost->h_length); ! 76: addr.sin_family = AF_INET; ! 77: addr.sin_port = ing_ser->s_port; ! 78: ! 79: ! 80: /* ! 81: ** Connect to the lock_driver ! 82: */ ! 83: if ( connect(to_driver,&addr,sizeof (addr)) == -1 ) ! 84: { ! 85: # ifdef xATR1 ! 86: if ( tTf(28,4) ) ! 87: perror("set_up_lock connect"); ! 88: # endif ! 89: close(to_driver); ! 90: return ( -1 ); ! 91: } ! 92: ! 93: ! 94: return ( to_driver ); ! 95: }/* start_up_lock_driver */ ! 96: ! 97: ! 98: struct servent * ! 99: getservbyname(name, proto) ! 100: char *name, *proto; ! 101: { ! 102: register struct servent *p; ! 103: register char **cp; ! 104: ! 105: setservent(0); ! 106: while (p = getservent()) { ! 107: if (strcmp(name, p->s_name) == 0) ! 108: goto gotname; ! 109: for (cp = p->s_aliases; *cp; cp++) ! 110: if (strcmp(name, *cp) == 0) ! 111: goto gotname; ! 112: continue; ! 113: gotname: ! 114: if (proto == 0 || strcmp(p->s_proto, proto) == 0) ! 115: break; ! 116: } ! 117: endservent(); ! 118: return (p); ! 119: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.