]>
git.saurik.com Git - apple/network_cmds.git/blob - telnet.tproj/sys_bsd.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1988, 1990, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 static char sccsid
[] = "@(#)sys_bsd.c 8.4 (Berkeley) 5/30/95";
62 * The following routines try to encapsulate what is system dependent
63 * (at least between 4.x and dos) which is used in telnet.c.
68 #include <sys/types.h>
70 #include <sys/socket.h>
73 #include <arpa/telnet.h>
83 #if defined(CRAY) || (defined(USE_TERMIO) && !defined(SYSV_TERMIO))
84 #define SIG_FUNC_RET void
86 #define SIG_FUNC_RET int
90 extern SIG_FUNC_RET
ayt_status();
94 tout
, /* Output file descriptor */
95 tin
, /* Input file descriptor */
99 struct tchars otc
= { 0 }, ntc
= { 0 };
100 struct ltchars oltc
= { 0 }, nltc
= { 0 };
101 struct sgttyb ottyb
= { 0 }, nttyb
= { 0 };
103 # define cfgetispeed(ptr) (ptr)->sg_ispeed
104 # define cfgetospeed(ptr) (ptr)->sg_ospeed
105 # define old_tc ottyb
107 #else /* USE_TERMIO */
108 struct termio old_tc
= { 0 };
109 extern struct termio new_tc
;
113 # define TCSANOW TCSETS
114 # define TCSADRAIN TCSETSW
115 # define tcgetattr(f, t) ioctl(f, TCGETS, (char *)t)
118 # define TCSANOW TCSETA
119 # define TCSADRAIN TCSETAW
120 # define tcgetattr(f, t) ioctl(f, TCGETA, (char *)t)
122 # define TCSANOW TIOCSETA
123 # define TCSADRAIN TIOCSETAW
124 # define tcgetattr(f, t) ioctl(f, TIOCGETA, (char *)t)
127 # define tcsetattr(f, a, t) ioctl(f, a, (char *)t)
128 # define cfgetospeed(ptr) ((ptr)->c_cflag&CBAUD)
130 # define cfgetispeed(ptr) (((ptr)->c_cflag&CIBAUD) >> IBSHIFT)
132 # define cfgetispeed(ptr) cfgetospeed(ptr)
134 # endif /* TCSANOW */
136 # define TIOCFLUSH TC_PX_DRAIN
138 #endif /* USE_TERMIO */
140 static fd_set ibits
, obits
, xbits
;
146 tout
= fileno(stdout
);
157 TerminalWrite(buf
, n
)
161 return write(tout
, buf
, n
);
169 return read(tin
, buf
, n
);
182 ioctl(0, TIOCLGET
, (char *)&flush
);
183 return !(flush
&LNOFLSH
); /* if LNOFLSH, no autoflush */
189 #ifdef KLUDGELINEMODE
190 extern int kludgelinemode
;
193 * TerminalSpecialChars()
195 * Look at an input character to see if it is a special character
196 * and decide what to do.
200 * 0 Don't add this character.
201 * 1 Do add this character
204 extern void xmitAO(), xmitEL(), xmitEC(), intp(), sendbrk();
207 TerminalSpecialChars(c
)
210 if (c
== termIntChar
) {
213 } else if (c
== termQuitChar
) {
214 #ifdef KLUDGELINEMODE
221 } else if (c
== termEofChar
) {
222 if (my_want_state_is_will(TELOPT_LINEMODE
)) {
227 } else if (c
== termSuspChar
) {
230 } else if (c
== termFlushChar
) {
231 xmitAO(); /* Transmit Abort Output */
233 } else if (!MODE_LOCAL_CHARS(globalmode
)) {
234 if (c
== termKillChar
) {
237 } else if (c
== termEraseChar
) {
238 xmitEC(); /* Transmit Erase Character */
247 * Flush output to the terminal
251 TerminalFlushOutput()
254 (void) ioctl(fileno(stdout
), TIOCFLUSH
, (char *) 0);
256 (void) ioctl(fileno(stdout
), TCFLSH
, (char *) 0);
264 ioctl(0, TIOCGETP
, (char *)&ottyb
);
265 ioctl(0, TIOCGETC
, (char *)&otc
);
266 ioctl(0, TIOCGLTC
, (char *)&oltc
);
267 ioctl(0, TIOCLGET
, (char *)&olmode
);
273 #else /* USE_TERMIO */
274 tcgetattr(0, &old_tc
);
279 termFlushChar
= CONTROL('O');
282 termWerasChar
= CONTROL('W');
285 termRprntChar
= CONTROL('R');
288 termLiteralNextChar
= CONTROL('V');
291 termStartChar
= CONTROL('Q');
294 termStopChar
= CONTROL('S');
297 termAytChar
= CONTROL('T');
299 #endif /* USE_TERMIO */
307 case SLC_IP
: return(&termIntChar
);
308 case SLC_ABORT
: return(&termQuitChar
);
309 case SLC_EOF
: return(&termEofChar
);
310 case SLC_EC
: return(&termEraseChar
);
311 case SLC_EL
: return(&termKillChar
);
312 case SLC_XON
: return(&termStartChar
);
313 case SLC_XOFF
: return(&termStopChar
);
314 case SLC_FORW1
: return(&termForw1Char
);
316 case SLC_FORW2
: return(&termForw2Char
);
318 case SLC_AO
: return(&termFlushChar
);
321 case SLC_SUSP
: return(&termSuspChar
);
324 case SLC_EW
: return(&termWerasChar
);
327 case SLC_RP
: return(&termRprntChar
);
330 case SLC_LNEXT
: return(&termLiteralNextChar
);
333 case SLC_AYT
: return(&termAytChar
);
346 TerminalDefaultChars()
351 nttyb
.sg_kill
= ottyb
.sg_kill
;
352 nttyb
.sg_erase
= ottyb
.sg_erase
;
353 #else /* USE_TERMIO */
354 memmove(new_tc
.c_cc
, old_tc
.c_cc
, sizeof(old_tc
.c_cc
));
356 termFlushChar
= CONTROL('O');
359 termWerasChar
= CONTROL('W');
362 termRprntChar
= CONTROL('R');
365 termLiteralNextChar
= CONTROL('V');
368 termStartChar
= CONTROL('Q');
371 termStopChar
= CONTROL('S');
374 termAytChar
= CONTROL('T');
376 #endif /* USE_TERMIO */
381 TerminalRestoreState()
387 * TerminalNewMode - set up terminal to a specific mode.
388 * MODE_ECHO: do local terminal echo
389 * MODE_FLOW: do local flow control
390 * MODE_TRAPSIG: do local mapping to TELNET IAC sequences
391 * MODE_EDIT: do local line editing
394 * MODE_ECHO|MODE_EDIT|MODE_FLOW|MODE_TRAPSIG
398 * local signal mapping
402 * Both Linemode and Single Character mode:
405 * local/no signal mapping
413 static int prevmode
= 0;
419 #else /* USE_TERMIO */
420 struct termio tmp_tc
;
421 #endif /* USE_TERMIO */
426 globalmode
= f
&~MODE_FORCE
;
431 * Write any outstanding data before switching modes
432 * ttyflush() returns 0 only when there is no more data
433 * left to write out, it returns -1 if it couldn't do
434 * anything at all, otherwise it returns 1 + the number
435 * of characters left to write.
437 * We would really like ask the kernel to wait for the output
438 * to drain, like we can do with the TCSADRAIN, but we don't have
439 * that option. The only ioctl that waits for the output to
440 * drain, TIOCSETP, also flushes the input queue, which is NOT
441 * what we want (TIOCSETP is like TCSADFLUSH).
444 old
= ttyflush(SYNCHing
|flushout
);
445 if (old
< 0 || old
> 1) {
447 tcgetattr(tin
, &tmp_tc
);
448 #endif /* USE_TERMIO */
451 * Wait for data to drain, then flush again.
454 tcsetattr(tin
, TCSADRAIN
, &tmp_tc
);
455 #endif /* USE_TERMIO */
456 old
= ttyflush(SYNCHing
|flushout
);
457 } while (old
< 0 || old
> 1);
461 prevmode
= f
&~MODE_FORCE
;
475 tmp_tc
.c_lflag
|= ECHO
;
476 tmp_tc
.c_oflag
|= ONLCR
;
478 tmp_tc
.c_iflag
|= ICRNL
;
482 sb
.sg_flags
&= ~ECHO
;
484 tmp_tc
.c_lflag
&= ~ECHO
;
485 tmp_tc
.c_oflag
&= ~ONLCR
;
488 tmp_tc
.c_iflag
&= ~ICRNL
;
493 if ((f
&MODE_FLOW
) == 0) {
495 tc
.t_startc
= _POSIX_VDISABLE
;
496 tc
.t_stopc
= _POSIX_VDISABLE
;
498 tmp_tc
.c_iflag
&= ~(IXOFF
|IXON
); /* Leave the IXANY bit alone */
500 if (restartany
< 0) {
501 tmp_tc
.c_iflag
|= IXOFF
|IXON
; /* Leave the IXANY bit alone */
502 } else if (restartany
> 0) {
503 tmp_tc
.c_iflag
|= IXOFF
|IXON
|IXANY
;
505 tmp_tc
.c_iflag
|= IXOFF
|IXON
;
506 tmp_tc
.c_iflag
&= ~IXANY
;
511 if ((f
&MODE_TRAPSIG
) == 0) {
513 tc
.t_intrc
= _POSIX_VDISABLE
;
514 tc
.t_quitc
= _POSIX_VDISABLE
;
515 tc
.t_eofc
= _POSIX_VDISABLE
;
516 ltc
.t_suspc
= _POSIX_VDISABLE
;
517 ltc
.t_dsuspc
= _POSIX_VDISABLE
;
519 tmp_tc
.c_lflag
&= ~ISIG
;
524 tmp_tc
.c_lflag
|= ISIG
;
531 sb
.sg_flags
&= ~CBREAK
;
532 sb
.sg_flags
|= CRMOD
;
534 tmp_tc
.c_lflag
|= ICANON
;
538 sb
.sg_flags
|= CBREAK
;
540 sb
.sg_flags
|= CRMOD
;
542 sb
.sg_flags
&= ~CRMOD
;
544 tmp_tc
.c_lflag
&= ~ICANON
;
545 tmp_tc
.c_iflag
&= ~ICRNL
;
546 tmp_tc
.c_cc
[VMIN
] = 1;
547 tmp_tc
.c_cc
[VTIME
] = 0;
551 if ((f
&(MODE_EDIT
|MODE_TRAPSIG
)) == 0) {
553 ltc
.t_lnextc
= _POSIX_VDISABLE
;
556 tmp_tc
.c_cc
[VLNEXT
] = (cc_t
)(_POSIX_VDISABLE
);
561 if (f
&MODE_SOFT_TAB
) {
563 sb
.sg_flags
|= XTABS
;
566 tmp_tc
.c_oflag
|= OXTABS
;
569 tmp_tc
.c_oflag
&= ~TABDLY
;
570 tmp_tc
.c_oflag
|= TAB3
;
575 sb
.sg_flags
&= ~XTABS
;
578 tmp_tc
.c_oflag
&= ~OXTABS
;
581 tmp_tc
.c_oflag
&= ~TABDLY
;
586 if (f
&MODE_LIT_ECHO
) {
591 tmp_tc
.c_lflag
&= ~ECHOCTL
;
599 tmp_tc
.c_lflag
|= ECHOCTL
;
619 tmp_tc
.c_iflag
&= ~ISTRIP
;
621 tmp_tc
.c_iflag
|= ISTRIP
;
622 if (f
& MODE_OUTBIN
) {
623 tmp_tc
.c_cflag
&= ~(CSIZE
|PARENB
);
624 tmp_tc
.c_cflag
|= CS8
;
625 tmp_tc
.c_oflag
&= ~OPOST
;
627 tmp_tc
.c_cflag
&= ~(CSIZE
|PARENB
);
628 tmp_tc
.c_cflag
|= old_tc
.c_cflag
& (CSIZE
|PARENB
);
629 tmp_tc
.c_oflag
|= OPOST
;
644 (void) signal(SIGTSTP
, susp
);
647 (void) signal(SIGINFO
, ayt
);
649 #if defined(USE_TERMIO) && defined(NOKERNINFO)
650 tmp_tc
.c_lflag
|= NOKERNINFO
;
653 * We don't want to process ^Y here. It's just another
654 * character that we'll pass on to the back end. It has
655 * to process it because it will be processed when the
656 * user attempts to read it, not when we send it.
659 ltc
.t_dsuspc
= _POSIX_VDISABLE
;
662 tmp_tc
.c_cc
[VDSUSP
] = (cc_t
)(_POSIX_VDISABLE
);
667 * If the VEOL character is already set, then use VEOL2,
668 * otherwise use VEOL.
670 esc
= (rlogin
!= _POSIX_VDISABLE
) ? rlogin
: escape
;
671 if ((tmp_tc
.c_cc
[VEOL
] != esc
)
673 && (tmp_tc
.c_cc
[VEOL2
] != esc
)
676 if (tmp_tc
.c_cc
[VEOL
] == (cc_t
)(_POSIX_VDISABLE
))
677 tmp_tc
.c_cc
[VEOL
] = esc
;
679 else if (tmp_tc
.c_cc
[VEOL2
] == (cc_t
)(_POSIX_VDISABLE
))
680 tmp_tc
.c_cc
[VEOL2
] = esc
;
684 if (tc
.t_brkc
== (cc_t
)(_POSIX_VDISABLE
))
689 SIG_FUNC_RET
ayt_status();
691 (void) signal(SIGINFO
, ayt_status
);
694 (void) signal(SIGTSTP
, SIG_DFL
);
696 (void) sigsetmask(sigblock(0) & ~(1<<(SIGTSTP
-1)));
698 (void) sigrelse(SIGTSTP
);
711 ioctl(tin
, TIOCLSET
, (char *)&lmode
);
712 ioctl(tin
, TIOCSLTC
, (char *)<c
);
713 ioctl(tin
, TIOCSETC
, (char *)&tc
);
714 ioctl(tin
, TIOCSETN
, (char *)&sb
);
716 if (tcsetattr(tin
, TCSADRAIN
, &tmp_tc
) < 0)
717 tcsetattr(tin
, TCSANOW
, &tmp_tc
);
720 #if (!defined(TN3270)) || ((!defined(NOT43)) || defined(PUTCHAR))
721 # if !defined(sysV88)
722 ioctl(tin
, FIONBIO
, (char *)&onoff
);
723 ioctl(tout
, FIONBIO
, (char *)&onoff
);
725 #endif /* (!defined(TN3270)) || ((!defined(NOT43)) || defined(PUTCHAR)) */
727 if (noasynchtty
== 0) {
728 ioctl(tin
, FIOASYNC
, (char *)&onoff
);
730 #endif /* defined(TN3270) */
735 * Try to guess whether speeds are "encoded" (4.2BSD) or just numeric (4.4BSD).
751 # define B19200 B14400
755 #define B28800 B19200
759 # define B38400 B28800
763 #define B57600 B38400
767 #define B76800 B57600
771 #define B115200 B76800
775 #define B230400 B115200
780 * This code assumes that the values B0, B50, B75...
781 * are in ascending order. They do not have to be
788 { 0, B0
}, { 50, B50
}, { 75, B75
},
789 { 110, B110
}, { 134, B134
}, { 150, B150
},
790 { 200, B200
}, { 300, B300
}, { 600, B600
},
791 { 1200, B1200
}, { 1800, B1800
}, { 2400, B2400
},
792 { 4800, B4800
}, { 7200, B7200
}, { 9600, B9600
},
793 { 14400, B14400
}, { 19200, B19200
}, { 28800, B28800
},
794 { 38400, B38400
}, { 57600, B57600
}, { 115200, B115200
},
795 { 230400, B230400
}, { -1, B230400
}
797 #endif /* DECODE_BAUD */
800 TerminalSpeeds(ispeed
, ospeed
)
805 register struct termspeeds
*tp
;
806 #endif /* DECODE_BAUD */
807 register long in
, out
;
809 out
= cfgetospeed(&old_tc
);
810 in
= cfgetispeed(&old_tc
);
816 while ((tp
->speed
!= -1) && (tp
->value
< in
))
821 while ((tp
->speed
!= -1) && (tp
->value
< out
))
824 #else /* DECODE_BAUD */
827 #endif /* DECODE_BAUD */
831 TerminalWindowSize(rows
, cols
)
837 if (ioctl(fileno(stdin
), TIOCGWINSZ
, (char *)&ws
) >= 0) {
842 #endif /* TIOCGWINSZ */
855 NetNonblockingIO(fd
, onoff
)
859 ioctl(fd
, FIONBIO
, (char *)&onoff
);
868 ioctl(fd
, FIOASYNC
, (char *)&onoff
); /* hear about input */
878 fcntl(fd
, F_SETOWN
, myPid
);
880 #endif /*defined(TN3270)*/
883 * Various signal handling routines.
892 longjmp(peerdied
, -1);
905 longjmp(toplevel
, -1);
914 #ifdef KLUDGELINEMODE
930 if ((rlogin
!= _POSIX_VDISABLE
) && rlogin_susp())
966 (void) signal(SIGINT
, intr
);
967 (void) signal(SIGQUIT
, intr2
);
968 (void) signal(SIGPIPE
, deadpeer
);
970 (void) signal(SIGWINCH
, sendwin
);
973 (void) signal(SIGTSTP
, susp
);
976 (void) signal(SIGINFO
, ayt
);
981 NetNonblockingIO(net
, 1);
984 if (noasynchnet
== 0) { /* DBX can't handle! */
988 #endif /* defined(TN3270) */
990 #if defined(SO_OOBINLINE)
991 if (SetSockOpt(net
, SOL_SOCKET
, SO_OOBINLINE
, 1) == -1) {
992 perror("SetSockOpt");
994 #endif /* defined(SO_OOBINLINE) */
1000 * This routine tries to fill up/empty our various rings.
1002 * The parameter specifies whether this is a poll operation,
1003 * or a block-until-something-happens operation.
1005 * The return value is 1 if something happened, 0 if not.
1009 process_rings(netin
, netout
, netex
, ttyin
, ttyout
, poll
)
1010 int poll
; /* If 0, then block until something to do */
1013 /* One wants to be a bit careful about setting returnValue
1014 * to one, since a one implies we did some useful work,
1015 * and therefore probably won't be called to block next
1016 * time (TN3270 mode only).
1018 int returnValue
= 0;
1019 static struct timeval TimeValue
= { 0 };
1022 FD_SET(net
, &obits
);
1025 FD_SET(tout
, &obits
);
1029 FD_SET(tin
, &ibits
);
1031 #else /* defined(TN3270) */
1033 FD_SET(tin
, &ibits
);
1035 #endif /* defined(TN3270) */
1038 FD_SET(net
, &ibits
);
1040 # else /* !defined(TN3270) */
1042 FD_SET(net
, &ibits
);
1044 # endif /* !defined(TN3270) */
1046 FD_SET(net
, &xbits
);
1048 if ((c
= select(16, &ibits
, &obits
, &xbits
,
1049 (poll
== 0)? (struct timeval
*)0 : &TimeValue
)) < 0) {
1052 * we can get EINTR if we are in line mode,
1053 * and the user does an escape (TSTP), or
1054 * some other signal generator.
1056 if (errno
== EINTR
) {
1059 # if defined(TN3270)
1061 * we can get EBADF if we were in transparent
1062 * mode, and the transcom process died.
1064 if (errno
== EBADF
) {
1066 * zero the bits (even though kernel does it)
1067 * to make sure we are selecting on the right
1075 # endif /* defined(TN3270) */
1076 /* I don't like this, does it ever happen? */
1077 printf("sleep(5) from telnet, after select\r\n");
1086 if (FD_ISSET(net
, &xbits
)) {
1087 FD_CLR(net
, &xbits
);
1089 (void) ttyflush(1); /* flush already enqueued data */
1093 * Something to read from the network...
1095 if (FD_ISSET(net
, &ibits
)) {
1098 FD_CLR(net
, &ibits
);
1099 canread
= ring_empty_consecutive(&netiring
);
1100 #if !defined(SO_OOBINLINE)
1102 * In 4.2 (and some early 4.3) systems, the
1103 * OOB indication and data handling in the kernel
1104 * is such that if two separate TCP Urgent requests
1105 * come in, one byte of TCP data will be overlaid.
1106 * This is fatal for Telnet, but we try to live
1109 * In addition, in 4.2 (and...), a special protocol
1110 * is needed to pick up the TCP Urgent data in
1111 * the correct sequence.
1113 * What we do is: if we think we are in urgent
1114 * mode, we look to see if we are "at the mark".
1115 * If we are, we do an OOB receive. If we run
1116 * this twice, we will do the OOB receive twice,
1117 * but the second will fail, since the second
1118 * time we were "at the mark", but there wasn't
1119 * any data there (the kernel doesn't reset
1120 * "at the mark" until we do a normal read).
1121 * Once we've read the OOB data, we go ahead
1122 * and do normal reads.
1124 * There is also another problem, which is that
1125 * since the OOB byte we read doesn't put us
1126 * out of OOB state, and since that byte is most
1127 * likely the TELNET DM (data mark), we would
1128 * stay in the TELNET SYNCH (SYNCHing) state.
1129 * So, clocks to the rescue. If we've "just"
1130 * received a DM, then we test for the
1131 * presence of OOB data when the receive OOB
1132 * fails (and AFTER we did the normal mode read
1133 * to clear "at the mark").
1137 static int bogus_oob
= 0, first
= 1;
1139 ioctl(net
, SIOCATMARK
, (char *)&atmark
);
1141 c
= recv(net
, netiring
.supply
, canread
, MSG_OOB
);
1142 if ((c
== -1) && (errno
== EINVAL
)) {
1143 c
= recv(net
, netiring
.supply
, canread
, 0);
1144 if (clocks
.didnetreceive
< clocks
.gotDM
) {
1145 SYNCHing
= stilloob(net
);
1147 } else if (first
&& c
> 0) {
1149 * Bogosity check. Systems based on 4.2BSD
1150 * do not return an error if you do a second
1151 * recv(MSG_OOB). So, we do one. If it
1152 * succeeds and returns exactly the same
1153 * data, then assume that we are running
1154 * on a broken system and set the bogus_oob
1155 * flag. (If the data was different, then
1156 * we probably got some valid new data, so
1157 * increment the count...)
1160 i
= recv(net
, netiring
.supply
+ c
, canread
- c
, MSG_OOB
);
1162 memcmp(netiring
.supply
, netiring
.supply
+ c
, i
) == 0) {
1171 if (bogus_oob
&& c
> 0) {
1174 * Bogosity. We have to do the read
1175 * to clear the atmark to get out of
1178 i
= read(net
, netiring
.supply
+ c
, canread
- c
);
1183 c
= recv(net
, netiring
.supply
, canread
, 0);
1186 c
= recv(net
, netiring
.supply
, canread
, 0);
1188 settimer(didnetreceive
);
1189 #else /* !defined(SO_OOBINLINE) */
1190 c
= recv(net
, (char *)netiring
.supply
, canread
, 0);
1191 #endif /* !defined(SO_OOBINLINE) */
1192 if (c
< 0 && errno
== EWOULDBLOCK
) {
1194 } else if (c
<= 0) {
1198 Dump('<', netiring
.supply
, c
);
1201 ring_supplied(&netiring
, c
);
1206 * Something to read from the tty...
1208 if (FD_ISSET(tin
, &ibits
)) {
1209 FD_CLR(tin
, &ibits
);
1210 c
= TerminalRead(ttyiring
.supply
, ring_empty_consecutive(&ttyiring
));
1211 if (c
< 0 && errno
== EIO
)
1213 if (c
< 0 && errno
== EWOULDBLOCK
) {
1216 /* EOF detection for line mode!!!! */
1217 if ((c
== 0) && MODE_LOCAL_CHARS(globalmode
) && isatty(tin
)) {
1218 /* must be an EOF... */
1219 *ttyiring
.supply
= termEofChar
;
1226 Dump('<', ttyiring
.supply
, c
);
1228 ring_supplied(&ttyiring
, c
);
1230 returnValue
= 1; /* did something useful */
1233 if (FD_ISSET(net
, &obits
)) {
1234 FD_CLR(net
, &obits
);
1235 returnValue
|= netflush();
1237 if (FD_ISSET(tout
, &obits
)) {
1238 FD_CLR(tout
, &obits
);
1239 returnValue
|= (ttyflush(SYNCHing
|flushout
) > 0);