1: #if defined(DOSCCS) && !defined(lint)
   2: static char sccsid[] = "@(#)bsdtcp.c	4.3.2 (2.11BSD GTE) 1996/3/22";
   3: #endif
   4: 
   5: #include "../condevs.h"
   6: #ifdef BSDTCP
   7: #include <netdb.h>
   8: #include <sys/socket.h>
   9: #include <netinet/in.h>
  10: 
  11: /*
  12:  *	bsdtcpopn -- make a tcp connection
  13:  *
  14:  *	return codes:
  15:  *		>0 - file number - ok
  16:  *		FAIL - failed
  17:  */
  18: 
  19: bsdtcpopn(flds)
  20: register char *flds[];
  21: {
  22:     struct servent *sp;
  23:     struct hostent *hp;
  24:     struct  sockaddr_in hisctladdr;
  25:     int s = -1, port;
  26:     extern int errno;
  27: 
  28:     sp = getservbyname(flds[F_CLASS], "tcp");
  29:     if (sp == NULL) {
  30:         port = htons(atoi(flds[F_CLASS]));
  31:         if (port == 0) {
  32:             logent(_FAILED, "UNKNOWN PORT NUMBER");
  33:             return CF_SYSTEM;
  34:         }
  35:     } else
  36:         port = sp->s_port;
  37:     DEBUG(4, "bsdtcpopn host %s, ", flds[F_PHONE]);
  38:     DEBUG(4, "port %d\n", ntohs(port));
  39:     if (setjmp(Sjbuf)) {
  40:         bsdtcpcls(s);
  41:         logent("tcpopen", "TIMEOUT");
  42:         return CF_DIAL;
  43:     }
  44: 
  45:     bzero((char *)&hisctladdr, sizeof (hisctladdr));
  46:     hp = gethostbyname(flds[F_PHONE]);
  47:     if (hp == NULL) {
  48:         logent("tcpopen","UNKNOWN HOST");
  49:         return CF_DIAL;
  50:     }
  51:     signal(SIGALRM, alarmtr);
  52:     alarm(30);
  53:     hisctladdr.sin_family = hp->h_addrtype;
  54: #ifdef BSD2_9
  55:     s = socket(SOCK_STREAM, 0, &hisctladdr, 0);
  56: #else BSD4_2
  57:     s = socket(hp->h_addrtype, SOCK_STREAM, 0);
  58: #endif BSD4_2
  59:     if (s < 0)
  60:         goto bad;
  61: #ifndef BSD2_9
  62:     if (bind(s, (char *)&hisctladdr, sizeof (hisctladdr), 0) < 0)
  63:         goto bad;
  64: #endif BSD2_9
  65:     bcopy(hp->h_addr, (char *)&hisctladdr.sin_addr, hp->h_length);
  66:     hisctladdr.sin_port = port;
  67: #ifdef BSD2_9
  68:     if (connect(s, (char *)&hisctladdr) < 0)
  69: #else BSD4_2
  70:     if (connect(s, (char *)&hisctladdr, sizeof (hisctladdr), 0) < 0)
  71: #endif BSD4_2
  72:         goto bad;
  73:     alarm(0);
  74:     CU_end = bsdtcpcls;
  75:     return s;
  76: bad:
  77:     alarm(0);
  78:     bsdtcpcls(s);
  79:     DEBUG(5, "tcpopen failed: errno %d\n", errno);
  80:     logent(strerror(errno), _FAILED);
  81:     return CF_DIAL;
  82: }
  83: 
  84: /*
  85:  * bsdtcpcls -- close tcp connection
  86:  */
  87: bsdtcpcls(fd)
  88: register int fd;
  89: {
  90:     DEBUG(4, "TCP CLOSE called\n", 0);
  91:     if (fd > 0) {
  92:         close(fd);
  93:         DEBUG(4, "closed fd %d\n", fd);
  94:     }
  95: }
  96: #endif BSDTCP

Defined functions

bsdtcpcls defined in line 87; used 3 times
bsdtcpopn defined in line 19; never used

Defined variables

sccsid defined in line 2; never used
Last modified: 1996-03-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1438
Valid CSS Valid XHTML 1.0 Strict