Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!hao!ames!ucbcad!ucbvax!decvax!decwrl!pyramid!uccba!hal!ncoast!allbery From: allbery@ncoast.UUCP Newsgroups: comp.unix.wizards Subject: Re: Absolutly hanging up a modem Message-ID: <4947@ncoast.UUCP> Date: Tue, 27-Oct-87 21:10:51 EST Article-I.D.: ncoast.4947 Posted: Tue Oct 27 21:10:51 1987 Date-Received: Sat, 31-Oct-87 17:58:50 EST References: <1548@bloom-beacon.MIT.EDU> <142700004@tiger.UUCP> <292@minya.UUCP> Reply-To: allbery@ncoast.UUCP (Brandon Allbery) Followup-To: comp.unix.wizards Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 85 As quoted from <292@minya.UUCP> by jc@minya.UUCP (John Chambers): +--------------- | Good suggestion. Much better than the "Drop DTR" suggestion. True, | this is what the modem expects (if it isn't in command mode) But | does anyone know the Unix call (for Sys/V and BSD and Xenix and ...) | that does this? Presumably the guy wasn't talking about how to hack | the kernel to make it twiddle the DTR line; he was asking how his | user-mode program does it. +--------------- On every Unix and Unix-like system I've used (except Minix, which as yet does not have a tty driver) you can drop DTR absolutely by setting the baud rate to 0. This is nonportable in its lowest-level incarnation, but a portable version follows: int hupfd(fd) int fd; { int status; switch (fork()) { case -1: return -1; case 0: close(0); dup(fd); close(1); dup(fd); close(fd); execlp("stty", "stty", "0", (char *) 0); _exit(-1); default: wait(&status); return status; } } Pass it a file descriptor of a modem, and it will drop DTR on the modem, forcing a hangup. Less portable versions follow: V7/BSD/Xenix 2.x: #include hupfd(fd) { struct sgttyb b; if (ioctl(fd, TIOCGETP, &b) == -1) return -1; b.sg_ispeed = b.sg_ospeed = B0; return ioctl(fd, TIOCSETP, &b); } System III/System V/Xenix 3/Xenix V: #include #include hupfd(fd) { struct termio b; if (ioctl(fd, TCGETA, &b) == -1) return -1; b.c_cflag = (b.c_cflag & ~CBAUD) | B0; return ioctl(fd, TCSETAF, &b); } V6 (does anyone still use this?!): #include hupfd(fd) { struct sgttyb b; if (gtty(fd, &b) == -1) return -1; b.sg_ispeed = b.sg_ospeed = B0; return stty(fd, &b); } Note that, thanks to "compatibility" routines in both BSD and AT&T Unixes, the V6 version should work on almost any Unix or lookalike thereof. -- Brandon S. Allbery necntc!ncoast!allbery@harvard.harvard.edu {{harvard,mit-eddie}!necntc,well!hoptoad,sun!mandrill!hal}!ncoast!allbery "Uncle _who_?" -- Lt. Worf