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