xref: /original-bsd/usr.bin/uucp/libacu/unet.c (revision 93ab02a6)
1 /*-
2  * Copyright (c) 1985 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)unet.c	4.4 (Berkeley) 04/24/91";
10 #endif /* not lint */
11 
12 #include "condevs.h"
13 #ifdef UNETTCP
14 
15 /*
16  *	unetopn -- make UNET (tcp-ip) connection
17  *
18  *	return codes:
19  *		>0 - file number - ok
20  *		FAIL - failed
21  */
22 
23 /* Default port of uucico server */
24 #define	DFLTPORT	33
25 
26 unetopn(flds)
27 register char *flds[];
28 {
29 	register int ret, port;
30 	int unetcls();
31 
32 	port = atoi(flds[F_PHONE]);
33 	if (port <= 0 || port > 255)
34 		port = DFLTPORT;
35 	DEBUG(4, "unetopn host %s, ", flds[F_NAME]);
36 	DEBUG(4, "port %d\n", port);
37 	if (setjmp(Sjbuf)) {
38 		logent("tcpopen", "TIMEOUT");
39 		endhnent();	/* see below */
40 		return CF_DIAL;
41 	}
42 	signal(SIGALRM, alarmtr);
43 	alarm(30);
44 	ret = tcpopen(flds[F_NAME], port, 0, TO_ACTIVE, "rw");
45 	alarm(0);
46 	endhnent();	/* wave magic wand at 3com and incant "eat it, bruce" */
47 	if (ret < 0) {
48 		DEBUG(5, "tcpopen failed: errno %d\n", errno);
49 		logent("tcpopen", _FAILED);
50 		return CF_DIAL;
51 	}
52 	CU_end = unetcls;
53 	return ret;
54 }
55 
56 /*
57  * unetcls -- close UNET connection.
58  */
59 unetcls(fd)
60 register int fd;
61 {
62 	DEBUG(4, "UNET CLOSE called\n", 0);
63 	if (fd > 0) {
64 #ifdef notdef
65 		/* disable this until a timeout is put in */
66 		if (ioctl(fd, UIOCCLOSE, STBNULL))
67 			logent("UNET CLOSE", _FAILED);
68 #endif notdef
69 		close(fd);
70 		DEBUG(4, "closed fd %d\n", fd);
71 	}
72 }
73 #endif UNETTCP
74