📄 ckcnet.c
字号:
debug(F111,"inet_addr ",name,(int)addr); return(addr);}char *inet_ntoa(in) struct in_addr in; { static char name[80]; sprintf(name, "%d.%d.%d.%d", in.s_net, in.s_host, in.s_lh, in.s_impno); return(name);}#else#ifdef DEC_TCPIP /* UCX */#ifndef __DECC /* VAXC or GCC */#define getservbyname my_getservbyname#ifdef CK_ANSICglobalref int (*C$$GA_UCX_GETSERVBYNAME)();extern void C$$TRANSLATE();extern void C$$SOCK_TRANSLATE();#elseglobalref int (*C$$GA_UCX_GETSERVBYNAME)();extern VOID C$$TRANSLATE();extern VOID C$$SOCK_TRANSLATE();#endif /* CK_ANSIC */struct servent *my_getservbyname (service, proto) char *service, *proto; { static struct servent sent; struct iosb { union { unsigned long status; unsigned short st[2]; } sb; unsigned long spare; } s; struct { struct iosb *s; char *serv; char *prot; } par; unsigned long e; char sbuf[30], pbuf[30]; char *p; debug(F111,"UCX getservbyname",service,(int)C$$GA_UCX_GETSERVBYNAME); p = sbuf; strcpy(p, service); while (*p = toupper(*p), *p++) {} p = pbuf; strcpy(p, proto); while (*p = toupper(*p), *p++) {} par.s = &s; par.serv = ""; par.prot = ""; /* reset file pointer or something like that!?!? */ e = (*C$$GA_UCX_GETSERVBYNAME)(&par, &sent, par.s); par.serv = sbuf; par.prot = pbuf; /* that is don't care */ e = (*C$$GA_UCX_GETSERVBYNAME)(&par, &sent, par.s); if ((long)e == -1L) return NULL; if ((e & 1) == 0L) { C$$TRANSLATE(e); return NULL; } if ((s.sb.st[0] & 1) == 0) { C$$SOCK_TRANSLATE(&s.sb.st[0]); return NULL; } /* sent.s_port is returned by UCX in network byte order. */ /* Calling htons here swaps the bytes, which ruins everything. */ /* Oh yeah? WHICH VERSION of UCX??? Let's try this... */#ifndef __alpha /* Maybe it should be __DECC, or some version thereof... *//* Hunter says: "In fact, the "#ifndef __alpha" isn't even needed, since my_getservbyname() isn't included if "__DECC" is defined, and that's always defined on Alpha." But if it doesn't hurt either, better not risk taking it out.*/#ifndef TCPWARE#define DO_HTONS#endif /* TCPWARE */#endif /* __alpha */#ifdef DO_HTONS sent.s_port = htons(sent.s_port); debug(F111,"UCX getservbyname","port",ntohs(sent.s_port));#else debug(F111,"UCX getservbyname","port",sent.s_port);#endif /* DO_HTONS */ return &sent;}#endif /* __DECC */#endif /* DEC_TCPIP */#endif /* EXCELAN */#endif /* TCPSOCKET */#ifndef NOTCPOPTS#ifndef datageneralintck_linger(onoff, timo) int onoff; int timo; {/* The following, from William Bader, turns off the socket linger parameter, which makes a close() block until all data is sent. "I don't think that disabling linger can ever cause kermit to lose data, but you telnet to a flaky server (or to our modem server when the modem is in use), disabling linger prevents kermit from hanging on the close if you try to exit." Modified by Jeff Altman to be generally useful.*/#ifdef SOL_SOCKET#ifdef SO_LINGER struct linger linger_opt; SOCKOPT_T x; if (ttyfd == -1 || nettype != NET_TCPA && nettype != NET_TCPB || ttmdm >= 0) { tcp_linger = onoff; tcp_linger_tmo = timo; return(1); } x = sizeof(linger_opt); if (getsockopt(ttyfd, SOL_SOCKET, SO_LINGER, (char *)&linger_opt, &x)) { perror("could not get SO_LINGER"); } else if (x != sizeof(linger_opt)) { debug(F101,"linger error: SO_LINGER len","",x); debug(F101,"linger SO_LINGER expected len","",sizeof(linger_opt)); } else if (linger_opt.l_onoff != onoff || linger_opt.l_linger != timo) { linger_opt.l_onoff = onoff; linger_opt.l_linger = timo; if (setsockopt(ttyfd, SOL_SOCKET, SO_LINGER, (char *)&linger_opt, sizeof(linger_opt))) { perror("error setting SO_LINGER"); } else { debug(F101,"linger new SO_LINGER","",linger_opt.l_onoff); tcp_linger = onoff; tcp_linger_tmo = timo; return 1; } } else { debug(F101,"setlinger SO_LINGER unchanged","",linger_opt.l_onoff); tcp_linger = onoff; tcp_linger_tmo = timo; return 1; }#else debug(F100,"SO_LINGER not defined","",0);#endif /* SO_LINGER */#else debug(F100,"SO_SOCKET not defined","",0);#endif /* SOL_SOCKET */ return(0);}int sendbuf(size) int size; {/* The following, from William Bader, allows changing of socket buffer sizes, in case that might affect performance. Modified by Jeff Altman to be generally useful.*/#ifdef SOL_SOCKET#ifdef SO_SNDBUF int i, rc = 0; SOCKOPT_T x; if (ttyfd == -1 || nettype != NET_TCPA && nettype != NET_TCPB || ttmdm >= 0) { tcp_sendbuf = size; return 1; } x = sizeof(i); if (getsockopt(ttyfd, SOL_SOCKET, SO_SNDBUF, (char *)&i, &x)) { perror("could not get SO_SNDBUF"); } else if (x != sizeof(i)) { debug(F101,"setsockbuf error: SO_SNDBUF len","",x); debug(F101,"setsockbuf SO_SNDBUF expected len","",sizeof(i)); } else if (size <= 0) { tcp_sendbuf = i; debug(F101,"setsockbuf SO_SNDBUF retrieved","",i); return 1; } else if (i != size) { x = size; if (setsockopt(ttyfd, SOL_SOCKET, SO_SNDBUF, (char *)&x, sizeof(x))) { perror("error setting SO_SNDBUF"); } else { debug(F101,"setsockbuf old SO_SNDBUF","",i); debug(F101,"setsockbuf new SO_SNDBUF","",x); tcp_sendbuf = size; return 1; } } else { debug(F101,"setsockbuf SO_SNDBUF unchanged","",i); tcp_sendbuf = size; return 1; }#else debug(F100,"SO_SNDBUF not defined","",0);#endif /* SO_SNDBUF */#else debug(F100,"SO_SOCKET not defined","",0);#endif /* SOL_SOCKET */ return(0);}int recvbuf(size) int size; {/* The following, from William Bader, allows changing of socket buffer sizes, in case that might affect performance. Modified by Jeff Altman to be generally useful.*/#ifdef SOL_SOCKET#ifdef SO_RCVBUF int i, rc = 0; SOCKOPT_T x; if (ttyfd == -1 || nettype != NET_TCPA && nettype != NET_TCPB || ttmdm >= 0) { tcp_recvbuf = size; return(1); } x = sizeof(i); if (getsockopt(ttyfd, SOL_SOCKET, SO_RCVBUF, (char *)&i, &x)) { perror("could not get SO_RCVBUF"); } else if (x != sizeof(i)) { debug(F101,"setsockbuf error: SO_RCVBUF len","",x); debug(F101,"setsockbuf SO_RCVBUF expected len","",sizeof(i)); } else if (size <= 0) { tcp_recvbuf = i; debug(F101,"setsockbuf SO_RCVBUF retrieved","",i); return 1; } else if (i != size) { x = size; if (setsockopt(ttyfd, SOL_SOCKET, SO_RCVBUF, (char *)&x, sizeof(x))) { perror("error setting SO_RCVBUF"); } else { debug(F101,"setsockbuf old SO_RCVBUF","",i); debug(F101,"setsockbuf new SO_RCVBUF","",x); tcp_recvbuf = size; return 1; } } else { debug(F101,"setsockbuf SO_RCVBUF unchanged","",i); tcp_recvbuf = size; return 1; }#else debug(F100,"SO_RCVBUF not defined","",0);#endif /* SO_RCVBUF */#else debug(F100,"SO_SOCKET not defined","",0);#endif /* SOL_SOCKET */ return 0;}intkeepalive(onoff) int onoff; {#ifdef SOL_SOCKET#ifdef SO_KEEPALIVE int keepalive_opt; SOCKOPT_T x; if (ttyfd == -1 || nettype != NET_TCPA && nettype != NET_TCPB || ttmdm >= 0) { tcp_keepalive = onoff; return 1; } x = sizeof(keepalive_opt); if (getsockopt(ttyfd, SOL_SOCKET, SO_KEEPALIVE, (char *)&keepalive_opt, &x)) { perror("could not get SO_KEEPALIVE"); } else if (x != sizeof(keepalive_opt)) { debug(F101,"setkeepalive error: SO_KEEPALIVE len","",x); debug(F101,"setkeepalive SO_KEEPALIVE expected len","", sizeof(keepalive_opt)); } else if (keepalive_opt != onoff) { keepalive_opt = onoff; if (setsockopt(ttyfd, SOL_SOCKET, SO_KEEPALIVE, (char *)&keepalive_opt, sizeof(keepalive_opt))) { perror("error clearing SO_KEEPALIVE"); } else { debug(F101,"setkeepalive new SO_KEEPALIVE","",keepalive_opt); tcp_keepalive = onoff; return 1; } } else { debug(F101,"setkeepalive SO_KEEPALIVE unchanged","",keepalive_opt); tcp_keepalive = onoff; return 1; }#else debug(F100,"SO_KEEPALIVE not defined","",0);#endif /* SO_KEEPALIVE */#else debug(F100,"SO_SOCKET not defined","",0);#endif /* SOL_SOCKET */ return(0);}intno_delay(onoff) int onoff; {#ifdef SOL_SOCKET#ifdef TCP_NODELAY int nodelay_opt; SOCKOPT_T x; if (ttyfd == -1 || nettype != NET_TCPA && nettype != NET_TCPB || ttmdm >= 0) { tcp_nodelay = onoff; return(1); } x = sizeof(nodelay_opt); if (getsockopt(ttyfd, SOL_SOCKET, TCP_NODELAY, (char *)&nodelay_opt, &x)) { perror("could not get TCP_NODELAY"); } else if (x != sizeof(nodelay_opt)) { debug(F101,"setnodelay error: TCP_NODELAY len","",x); debug(F101,"setnodelay TCP_NODELAY expected len","", sizeof(nodelay_opt)); } else if (nodelay_opt != onoff) { nodelay_opt = onoff; if (setsockopt(ttyfd, SOL_SOCKET, TCP_NODELAY, (char *)&nodelay_opt, sizeof(nodelay_opt))) { perror("error clearing TCP_NODELAY"); } else { debug(F101,"setnodelay new TCP_NODELAY","",nodelay_opt); tcp_nodelay = onoff; return 1; } } else { debug(F101,"setnodelay TCP_NODELAY unchanged","",nodelay_opt); tcp_nodelay = onoff; return(1); }#else debug(F100,"TCP_NODELAY not defined","",0);#endif /* TCP_NODELAY */#else debug(F100,"SO_SOCKET not defined","",0);#endif /* SOL_SOCKET */ return 0;}#endif /* datageneral */#endif /* NOTCPOPTS */#ifdef SUNX25#ifndef X25_WR_FACILITY/* For Solaris 2.3 / SunLink 8.x - see comments in ckcnet.h */voidbzero(s,n) char *s; int n; { memset(s,0,n);}#endif /* X25_WR_FACILITY */#endif /* SUNX25 */#ifdef TCPSOCKET#ifndef OS2#ifndef NOLISTEN#ifdef BSDSELECT#ifndef VMS#ifndef BELLV10#ifndef datageneral#ifdef hp9000s500 /* HP-9000/500 HP-U 5.21 */#include <time.h>#else#include <sys/time.h>#endif /* hp9000s500 */#endif /* datageneral */#endif /* BELLV10 */#endif /* VMS */#ifdef SELECT_H#include <sys/select.h>#endif /* SELECT_H */#endif /* BSDSELECT */#ifdef SELECT#ifdef CK_SCOV5#include <sys/select.h>#endif /* CK_SCOV5 */#endif /* SELECT */#ifdef TCPSOCKET#ifndef SO_OOBINLINE /* Hopefully only HP-UX 7.0 */#define SO_OOBINLINE 0x0100#endif /* SO_OOBINLINE */#endif /* TCPSOCKET */#ifdef NOTUSED/* T C P S O C K E T _ O P E N -- Open a preexisting socket number */inttcpsocket_open(name,lcl,nett,timo) char * name; int * lcl; int nett; int timo { int on = 1; static struct servent *service, servrec; static struct hostent *host; static struct sockaddr_in saddr; static int saddrlen;#ifdef BSDSELECT fd_set rfds; struct timeval tv;#else#ifdef BELLSELECT fd_set rfds;#endif /* BELLSELECT */#endif /* BSDSELECT */ debug(F101,"tcpsocket_open nett","",nett); *ipaddr = '\0'; if (nett != NET_TCPB) return(-1); /* BSD socket support */ netclos(); /* Close any previous connection. */ strncpy(namecopy, name, NAMECPYL); /* Copy the hostname. */ ttnproto = NP_NONE; /* No protocol selected yet. */ debug(F110,"tcpsocket_open namecopy",namecopy,0); /* Assign the socket number to ttyfd and then fill in tcp structures */ ttyfd = atoi(&name[1]); debug(F111,"tcpsocket_open","ttyfd",ttyfd);#ifndef NOTCPOPTS#ifdef SOL_SOCKET setsockopt(ttyfd, SOL_SOCKET, SO_OOBINLINE,(char *) &on, sizeof on);#ifndef datageneral#ifdef TCP_NODELAY no_delay(tcp_nodelay);#endif /* TCP_NODELAY */#ifdef SO_KEEPALIVE keepalive(tcp_keepalive);#endif /* SO_KEEPALIVE */#ifdef SO_LINGER ck_linger(tcp_linger, tcp_linger_tmo);#endif /* SO_LINGER */#ifdef SO_SNDBUF sendbuf(tcp_sendbuf);#endif /* SO_SNDBUF */#ifdef SO_RCVBUF recvbuf(tcp_recvbuf);#endif /* SO_RCVBUF */#endif /* datageneral */#endif /* SOL_SOCKET */#endif /* NOTCPOPTS */ /* Get the name of the host we are connected to */ saddrlen = sizeof(saddr); getpeername(ttyfd,(struct sockaddr *)&saddr,&saddrlen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -