📄 ckcnet.c
字号:
char *cknetv = "Network support, 6.0.078, 6 Sep 1996";/* C K C N E T -- Network support *//* NOTE TO CONTRIBUTORS: This file, and all the other shared (ckc and cku) C-Kermit source files, must be compatible with C preprocessors that support only #ifdef, #else, #endif, #define, and #undef. Please do not use #if, logical operators, or other preprocessor features in any of the portable C-Kermit modules. You can, of course, use these constructions in system-specific modules when you know they are supported. Also, don't use any ANSI C constructs except with #ifdef CK_ANSIC..#endif.*//* Authors: Frank da Cruz (fdc@columbia.edu), Columbia University Academic Information Systems, New York City. netopen() routine for TCP/IP originally by Ken Yap, Rochester University (ken@cs.rochester.edu) (no longer at that address). Jeffrey E Altman (jaltman@columbia.edu) -- OS/2 & Windows, etc. Missing pieces for Excelan sockets library from William Bader. TELNET protocol by Frank da Cruz and Jeffrey Altman. TGV MultiNet code by Frank da Cruz. MultiNet code adapted to WIN/TCP by Ray Hunter of TWG. MultiNet code adapted to DEC TCP/IP by Lee Tibbert of DEC and Frank da Cruz. TCP/IP support adapted to IBM TCP/IP 1.2.1,2.0 for OS/2 by Kai Uwe Rommel. CMU-OpenVMS/IP modifications by Mike O'Malley, Digital (DEC). X.25 support by Marcello Frutig, Catholic University, Rio de Janeiro, Brazil (frutig@rnp.impa.br) with fixes from: Stefaan Eeckels, Eurokom, Luxembourg; David Lane, Status Computer. Other contributions as indicated below. Copyright (C) 1985, 1996, Trustees of Columbia University in the City of New York. The C-Kermit software may not be, in whole or in part, licensed or sold for profit as a software product itself, nor may it be included in or distributed with commercial products or otherwise distributed by commercial concerns to their clients or customers without written permission of the Office of Kermit Development and Distribution, Columbia University. This copyright notice must not be removed, altered, or obscured.*/#include "ckcsym.h"#include "ckcdeb.h"#include "ckcker.h"#ifdef I386IX /* Has to come before ckcnet.h in */#include <errno.h> /* this version, but after in others */#endif /* I386IX */#include "ckcnet.h"#ifdef NETCONN/* Don't need these if there is no network support. */#ifdef CK_SOCKS /* SOCKS Internet relay package */#define accept Raccept#define bind Rbind#define connect Rconnect#define getsockname Rgetsockname#define listen Rlisten#endif /* CK_SOCKS */#ifdef DEC_TCPIP#include <time.h>#include <inet.h>#endif /* DEC_TCPIP */#ifdef CMU_TCPIP#include <time.h>#endif /* CMU_TCPIP */#ifdef WINTCP#include <setjmp.h>#include <signal.h>#include <sys/time.h>/* The WIN/TCP code path is the same as that for MultiNet. Only the routine names have changed ...*/#define socket_read netread#define socket_ioctl ioctl#define socket_write netwrite#define socket_close netclose#ifdef OLD_TWG /* some routines have evolved */ extern int vmserrno, uerrno;#define socket_errno uerrno#define socket_perror perror /* which uses errno, not uerrno! */#else#define socket_errno errno#define socket_perror win$perror#endif /* OLD_TWG */#else /* Not WINTCP */#ifndef I386IX#include <errno.h> /* Already included above */#endif /* I386IX */#include <signal.h> /* Everybody needs this */#ifdef ZILOG /* Zilog has different name for this */#include <setret.h>#else /* !ZILOG */#include <setjmp.h>#ifdef CK_POSIX_SIG /* POSIX signal handling */#endif /* CK_POSIX_SIG */#endif /* ZILOG */#endif /* WINTCP */#ifdef datageneral /* Data General AOS/VS */#include <:usr:include:vs_tcp_errno.h>#include <:usr:include:sys:vs_tcp_types.h>#ifdef SELECT/* NOTE: This can be compiled and linked OK with SELECT defined but it doesn't work at all. Anybody who cares and knows how to fix it, feel free.*/#include <:usr:include:sys:vs_tcp_time.h>#endif /* SELECT */#include <:usr:include:sys:socket.h>#include <:usr:include:netinet:in.h>#include <:usr:include:netdb.h>#endif /* datageneral */extern#ifdef OS2SIGTYP (* volatile saval)(); /* For saving alarm handler */#else /* OS2 */SIGTYP (*saval)(); /* For saving alarm handler */#endif /* OS2 */_PROTOTYP( VOID bgchk, (void) );_PROTOTYP( static VOID tn_debug, (char *) );#ifdef RLOGCODE#ifdef TCPIPLIB_PROTOTYP( static VOID rlog_oob, (CHAR *, int) );#else /* TCPIPLIB */_PROTOTYP( static SIGTYP rlogoobh, ( int ) );#endif /* TCPIPLIB */_PROTOTYP( static int rlog_ini, (VOID) );int rlog_mode = RL_COOKED;int rlog_stopped = 0;#endif /* RLOGCODE *//* NAWS state - used in both TELNET and RLOGIN */int nawsflg = 0;extern int /* External variables */ duplex, debses, seslog, sessft, ttyfd, quiet, msgflg, what, nettype, ttmdm;#ifdef DEBUGextern int deblog;#else#define deblog 0#endif /* DEBUG */#ifdef OS2extern int tt_rows[], tt_cols[];extern int tt_status;#else /* OS2 */extern int tt_rows, tt_cols; /* Everybody has this */#endif /* OS2 */#ifdef CK_TTGWSIZ_PROTOTYP( int ttgwsiz, (void) );#endif /* CK_TTGWSIZ */#ifdef CK_NAWS /* Negotiate About Window Size */_PROTOTYP( int tn_snaws, (void) );#ifdef RLOGCODE#ifndef OS2_PROTOTYP(static int rlog_naws, (void) );#else_PROTOTYP( int rlog_naws, (void) );#endif /* OS2 */#endif /* RLOGCODE */#endif /* CK_NAWS */#ifdef OS2 /* For terminal type name string */#include "ckuusr.h"#ifndef NT#include <os2.h>#endif /* NT */#include "ckocon.h"extern int tt_type, max_tt;extern struct tt_info_rec tt_info[];extern char ttname[];extern int scrninitialized[];#endif /* OS2 */#include "ckcsig.h"#ifndef OS2 /* For timeout longjumps */static ckjmpbuf njbuf;#endif /* OS2 */#define NAMECPYL 100 /* Local copy of hostname */#ifndef OS2 static /* OS2 needs access in ckonet.c */#endif /* OS2 */char namecopy[NAMECPYL]; char ipaddr[20] = { '\0' }; /* Global copy of IP address */char myipaddr[20] = { '\0' }; /* Global copy of my IP address */#endif /* NETCONN */int ttnet = NET_NONE; /* Network type */int ttnproto = NP_NONE; /* Network virtual terminal protocol */int tn_init = 0; /* Telnet protocol initialized flag */int tn_exit = 0; /* Exit on disconnect */int tn_duplex = 1; /* Initial echo status */char *tn_term = NULL; /* Terminal type override */int tn_nlm = TNL_CRLF; /* Telnet CR -> CR LF mode */int tn_binary = TN_BM_AC; /* Binary negotiation accepted */int tn_b_nlm = TNL_CR; /* Telnet Binary CR RAW mode */int tn_b_meu = 0; /* Telnet Binary ME means U too */int tn_b_ume = 0; /* Telnet Binary U means ME too */#ifdef OS2int ttnum = -1; /* Last Telnet Terminal Type sent */int ttnumend = 0; /* Has end of list been found */#endif /* OS2 */#ifdef TNCODE#ifdef CK_ENVIRONMENTstatic char tn_msg[1024]; /* For debugging */static char hexbuf[1024];#else /* CK_ENVIRONMENT */static char tn_msg[128]; /* For debugging */static char hexbuf[6];#endif /* CK_ENVIRONMENT */#endif /* TNCODE */#ifdef NTextern int WSASafeToCancel;#endif /* NT */#ifndef NOTCPOPTS/* Skip all this if NOTCPOPTS specified. */#ifdef SOL_SOCKET#ifdef TCP_NODELAYint tcp_nodelay = 0; /* Nagle algorithm TCP_NODELAY */#endif /* TCP_NODELAY */#ifdef SO_LINGERint tcp_linger = 0; /* SO_LINGER */int tcp_linger_tmo = 0; /* SO_LINGER timeout */#endif /* SO_LINGER */#ifdef HPUX /* But the data structures */#ifndef HPUX8 /* needed for linger are not */#ifndef HPUX9 /* defined in HP-UX versions */#ifndef HPUX10 /* prior to 8.00. */#ifdef SO_LINGER#undef SO_LINGER#endif /* SO_LINGER */#endif /* HPUX10 */#endif /* HPUX9 */#endif /* HPUX8 */#endif /* HPUX */#ifdef SO_SNDBUF int tcp_sendbuf = -1;#endif /* SO_SNDBUF */#ifdef SO_RCVBUFint tcp_recvbuf = -1;#endif /* SO_RCVBUF */#ifdef SO_KEEPALIVE int tcp_keepalive = 1;#endif /* SO_KEEPALIVE */#endif /* SOL_SOCKET */#endif /* NOTCPOPTS */#ifndef NETCONN/* Network support not defined. Dummy functions here in case #ifdef's forgotten elsewhere.*/int /* Open network connection */netopen(name, lcl, nett) char *name; int *lcl, nett; { return(-1);}int /* Close network connection */netclos() { return(-1);}int /* Check network input buffer */nettchk() { return(-1);}int /* Flush network input buffer */netflui() { return(-1);}int /* Send network BREAK */netbreak() { return(-1);}int /* Input character from network */netinc(timo) int timo; { return(-1);}int /* Output character to network */#ifdef CK_ANSICnettoc(char c)#elsenettoc(c) char c;#endif /* CK_ANSIC *//* nettoc */ { return(-1);}intnettol(s,n) char *s; int n; { return(-1);}#else /* NETCONN is defined (rest of this module...) */#ifdef VMS/* In edit 190, we moved tn_ini() to be called from within netopen(). But tn_ini() calls ttol(), and ttol() checks to see if it's a net connection, but the flag for that isn't set until after netopen() is finished. Since, in this module, we are always doing network output anyway, we just call nettol() directly, instead of going thru ttol(). Only needed for VMS, since UNIX, AOS/VS, and VOS can handle net connections just like regular connections in ttol(), and OS/2 has a special routine for this.*/#define ttol nettol#endif /* VMS */extern int tn_binary; /* Binary mode enabled */int me_binary = 0; /* I'm not in TELNET binary mode */int u_binary = 0; /* You're not in TELNET binary mode */int tcpsrfd = -1;#ifdef TCPSOCKET#ifndef OS2#ifndef NOLISTEN /* For incoming connections */#ifndef INADDR_ANY#define INADDR_ANY 0 #endif /* INADDR_ANY */_PROTOTYP( int ttbufr, ( VOID ) );_PROTOTYP( int tcpsrv_open, (char *, int *, int, int ) );static unsigned short tcpsrv_port = 0;#endif /* NOLISTEN */#endif /* OS2 */#endif /* TCPSOCKET */#ifndef NOSIGWINCH#ifdef CK_NAWS /* Window size business */#ifdef SIGWINCH#ifdef UNIXstatic int sw_armed = 0; /* SIGWINCH armed flag */SIGTYPwinchh(foo) int foo; { int x; debug(F100,"SIGWINCH caught","",0); signal(SIGWINCH,winchh); /* Re-arm the signal */ if (ttyfd == -1) return; x = ttgwsiz(); /* Get new window size *//* This should be OK. It might seem that sending this from interrupt level could interfere with another TELNET IAC string that was in the process of being sent. But we always send TELNET strings with a single write(), which should prevent mixups.*/ if (x > 0 && tt_rows > 0 && tt_cols > 0) { tn_snaws();#ifdef RLOGCODE rlog_naws();#endif /* RLOGCODE */ } return;}#endif /* UNIX */#endif /* SIGWINCH */#endif /* CK_NAWS */#endif /* NOSIGWINCH *//* TCPIPLIB means use separate socket calls for i/o, while on UNIX the normal file system calls are used for TCP/IP sockets too. Means "DEC_TCPIP or MULTINET or WINTCP or OS2" (defined in ckcnet.h).*/#ifdef TCPIPLIB/* For buffered network reads... *//* If the buffering code is written right, it shouldn't matter how long this buffer is.*/#ifdef OS2#define TTIBUFL 32767#else /* OS2 */#define TTIBUFL 8191 /* Let's use 8K. */#endif /* OS2 */CHAR ttibuf[TTIBUFL+1];/* select() is used in preference to alarm()/signal(), but different systems use different forms of select()...*/#ifndef NOSELECT /* Option to override BSDSELECT */#ifdef BELLV10/* Note: Although BELLV10 does have TCP/IP support, and does use the unique form of select() that is evident in this module (and in ckutio.c), it does not have a sockets library and so we can't build Kermit TCP/IP support for it. For this, somebody would have to write TCP/IP streams code.*/#define BELLSELECT#ifndef FD_SETSIZE#define FD_SETSIZE 128#endif /* FD_SETSIZE */#else#ifdef WINTCP /* VMS with Wollongong WIN/TCP */#ifndef OLD_TWG /* TWG 3.2 has only select(read) */#define BSDSELECT#endif /* OLD_TWG */#else#ifdef CMU_TCPIP /* LIBCMU can do select */#define BSDSELECT#else#ifdef DEC_TCPIP#define BSDSELECT#else#ifdef OS2 /* OS/2 with TCP/IP */#ifdef NT#define BSDSELECT#else /* NT */#define IBMSELECT#endif /* NT */#endif /* OS2 */#endif /* DEC_TCPIP */#endif /* CMU_TCPIP */#endif /* WINTCP */#endif /* BELLV10 */#endif /* NOSELECT *//* Others (TGV, TCPware, ...) use alarm()/signal(). The BSDSELECT case does not compile at all; the IBMSELECT case compiles and links but crashes at runtime. NOTE: If any of these can be converted to select(), they should be for two reasons: (1) It's a lot faster; (2) certain sockets libraries do not like their socket_read() calls to be interrupted; subsequent socket_read()'s tend to fail with EBUSY. This happened in the UCX case before it was converted to use select().*/#ifndef VMSstatic /* These are used in CKVTIO.C */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -