xref: /csrg-svn/usr.bin/uucp/libacu/unet.c (revision 62384)
148651Sbostic /*-
2*62384Sbostic  * Copyright (c) 1985, 1993
3*62384Sbostic  *	The Regents of the University of California.  All rights reserved.
448651Sbostic  *
548651Sbostic  * %sccs.include.proprietary.c%
648651Sbostic  */
748651Sbostic 
817781Sralph #ifndef lint
9*62384Sbostic static char sccsid[] = "@(#)unet.c	8.1 (Berkeley) 06/06/93";
1048651Sbostic #endif /* not lint */
1117781Sralph 
1246875Sbostic #include "condevs.h"
1317781Sralph #ifdef UNETTCP
1417781Sralph 
1517781Sralph /*
1617781Sralph  *	unetopn -- make UNET (tcp-ip) connection
1717781Sralph  *
1817781Sralph  *	return codes:
1917781Sralph  *		>0 - file number - ok
2017781Sralph  *		FAIL - failed
2117781Sralph  */
2217781Sralph 
2317781Sralph /* Default port of uucico server */
2417781Sralph #define	DFLTPORT	33
2517781Sralph 
unetopn(flds)2617781Sralph unetopn(flds)
2717781Sralph register char *flds[];
2817781Sralph {
2917781Sralph 	register int ret, port;
3017781Sralph 	int unetcls();
3117781Sralph 
3217781Sralph 	port = atoi(flds[F_PHONE]);
3317781Sralph 	if (port <= 0 || port > 255)
3417781Sralph 		port = DFLTPORT;
3517781Sralph 	DEBUG(4, "unetopn host %s, ", flds[F_NAME]);
3617781Sralph 	DEBUG(4, "port %d\n", port);
3717781Sralph 	if (setjmp(Sjbuf)) {
3817781Sralph 		logent("tcpopen", "TIMEOUT");
3917781Sralph 		endhnent();	/* see below */
4017781Sralph 		return CF_DIAL;
4117781Sralph 	}
4217781Sralph 	signal(SIGALRM, alarmtr);
4317781Sralph 	alarm(30);
4417781Sralph 	ret = tcpopen(flds[F_NAME], port, 0, TO_ACTIVE, "rw");
4517781Sralph 	alarm(0);
4617781Sralph 	endhnent();	/* wave magic wand at 3com and incant "eat it, bruce" */
4717781Sralph 	if (ret < 0) {
4817781Sralph 		DEBUG(5, "tcpopen failed: errno %d\n", errno);
4917781Sralph 		logent("tcpopen", _FAILED);
5017781Sralph 		return CF_DIAL;
5117781Sralph 	}
5217781Sralph 	CU_end = unetcls;
5317781Sralph 	return ret;
5417781Sralph }
5517781Sralph 
5617781Sralph /*
5717781Sralph  * unetcls -- close UNET connection.
5817781Sralph  */
unetcls(fd)5917781Sralph unetcls(fd)
6017781Sralph register int fd;
6117781Sralph {
6217781Sralph 	DEBUG(4, "UNET CLOSE called\n", 0);
6317781Sralph 	if (fd > 0) {
6417781Sralph #ifdef notdef
6517781Sralph 		/* disable this until a timeout is put in */
6617781Sralph 		if (ioctl(fd, UIOCCLOSE, STBNULL))
6717781Sralph 			logent("UNET CLOSE", _FAILED);
6817781Sralph #endif notdef
6917781Sralph 		close(fd);
7017781Sralph 		DEBUG(4, "closed fd %d\n", fd);
7117781Sralph 	}
7217781Sralph }
7317781Sralph #endif UNETTCP
74