⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckcnet.c

📁 KERMIT工具 这在办公室下载不了,很多人都没有载不到.
💻 C
📖 第 1 页 / 共 5 页
字号:
              return(-2);#endif /* OS2ONLY */          } else {                      /* we got out-of-band data */              hexdump("ttbufr out-of-band chars",&ttibuf[ttibp+ttibn],count);#ifdef BETADEBUG              bleep(BP_NOTE);#endif /* BETADEBUG */#ifdef RLOGCODE                         /* blah */              if (ttnproto == NP_RLOGIN  ||                  ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN ||                  ((ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN) &&                   !rlog_inband)                   )              {                  /*                    When urgent data is read with MSG_OOB and not OOBINLINE                    then urgent data and normal data are not mixed.  So                    treat the entire buffer as urgent data.                  */                  rlog_oob(&ttibuf[ttibp+ttibn], count);#ifdef OS2                  ReleaseTCPIPMutex();#endif /* OS2 */                  return ttbufr();              } else#endif /* RLOGCODE */ /* blah */#ifdef COMMENT            /*               I haven't written this yet, nor do I know what it should do             */                if (ttnproto == NP_TELNET) {                    tn_oob();#ifdef OS2                    ReleaseTCPIPMutex();#endif /* OS2 */                    return 0;              } else#endif /* COMMENT */              {                  /* For any protocols we don't have a special out-of-band  */                  /* handler for, just put the bytes in the normal buffer   */                  /* and return                                             */                  ttibp += 0;       /* Reset buffer pointer. */                  ttibn += count;#ifdef DEBUG                  /* Got some bytes. */                  debug(F101,"ttbufr count 2","",count);                  if (count > 0)                      ttibuf[ttibp+ttibn] = '\0';                  debug(F111,"ttbufr ttibuf",ttibuf,ttibp);#endif /* DEBUG */#ifdef OS2                  ReleaseTCPIPMutex();#endif /* OS2 */                  return(ttibn);    /* Return buffer count. */              }          }      }    }#endif /* SO_OOBINLINE */#endif /* VMS */    count = socket_read(ttyfd,&ttibuf[ttibp+ttibn],count);    if (count <= 0) {        int s_errno = socket_errno;        debug(F101,"ttbufr socket_read","",count);        debug(F101,"ttbufr socket_errno","",s_errno);#ifdef OS2        if (count == 0 || os2socketerror(s_errno) < 0) {            netclos();            ReleaseTCPIPMutex();            return(-2);        }        ReleaseTCPIPMutex();        return(-1);#else /* OS2 */        netclos();                      /* *** *** */        return(-2);#endif /* OS2 */    }#endif /* COMMENT */ /* (blocking vs nonblock reads...) */    else {        ttibp = 0;                      /* Reset buffer pointer. */        ttibn += count;#ifdef DEBUG        debug(F101,"ttbufr count 2","",count); /* Got some bytes. */        if (count > 0)          ttibuf[ttibp+ttibn] = '\0';        debug(F111,"ttbufr ttibuf",&ttibuf[ttibp],ttibn);#endif /* DEBUG */#ifdef OS2        ReleaseTCPIPMutex();#endif /* OS2 */        return(ttibn);                  /* Return buffer count. */    }}#endif /* TCPIPLIB */#ifndef IBMSELECT#ifndef BELLSELECT#ifndef BSDSELECT               /* Non-TCPIPLIB case */#ifdef SELECT#define BSDSELECT#endif /* SELECT */#endif /* BSDSELECT */#endif /* BELLSELECT */#endif /* IBMSELECT */#define TELNET_PORT 23          /* Should do lookup, but it won't change */#define RLOGIN_PORT 513#define KERMIT_PORT 1649#define KLOGIN_PORT 543#define EKLOGIN_PORT 2105#ifndef NONET/*  C-Kermit network open/close functions for BSD-sockets.  Much of this code shared by SunLink X.25, which also uses the socket library.*//*  N E T O P N  --  Open a network connection.  *//*  Call with:    name of host (or host:service),    lcl - local-mode flag to be set if this function succeeds,    network type - value defined in ckunet.h.*/#ifdef TCPSOCKETstruct hostent *#ifdef CK_ANSICck_copyhostent(struct hostent * h)#else /* CK_ANSIC */ck_copyhostent(h) struct hostent * h;#endif /* CK_ANSIC */{    /*     *  The hostent structure is dynamic in nature.     *  struct  hostent {     *  char    * h_name;     *  char    * * h_aliases;     *  short   h_addrtype;     *  short   h_length;     *  char    * * h_addr_list;     *  #define h_addr  h_addr_list[0]     */#define HOSTENTCNT 5    static struct hostent hosts[HOSTENTCNT] = {{NULL,NULL,0,0,NULL},                                               {NULL,NULL,0,0,NULL},                                               {NULL,NULL,0,0,NULL},                                               {NULL,NULL,0,0,NULL},                                               {NULL,NULL,0,0,NULL}};    static int    next = 0;    int    i,cnt;    char ** pp;    if ( h == NULL )        return(NULL);    if (next == HOSTENTCNT)        next = 0;    if ( hosts[next].h_name ) {        free(hosts[next].h_name);        hosts[next].h_name = NULL;    }    if ( hosts[next].h_aliases ) {        pp = hosts[next].h_aliases;        while ( *pp ) {            free(*pp);            pp++;        }        free(hosts[next].h_aliases);    }#ifdef HADDRLIST    if ( hosts[next].h_addr_list ) {        pp = hosts[next].h_addr_list;        while ( *pp ) {            free(*pp);            pp++;        }        free(hosts[next].h_addr_list);    }#endif /* HADDRLIST */    makestr(&hosts[next].h_name,h->h_name);    if (h->h_aliases) {        for ( cnt=0,pp=h->h_aliases; pp && *pp; pp++,cnt++) ;        /* The following can give warnings in non-ANSI builds */        hosts[next].h_aliases = (char **) malloc(sizeof(char *) * (cnt+1));        for ( i=0; i<cnt; i++) {            hosts[next].h_aliases[i] = NULL;            makestr(&hosts[next].h_aliases[i],h->h_aliases[i]);        }        hosts[next].h_aliases[i] = NULL;    } else        hosts[next].h_aliases = NULL;    hosts[next].h_addrtype = h->h_addrtype;    hosts[next].h_length = h->h_length;#ifdef HADDRLIST#ifdef h_addr    if (h->h_addr_list) {        for ( cnt=0,pp=h->h_addr_list; pp && *pp; pp++,cnt++) ;        /* The following can give warnings non-ANSI builds */        hosts[next].h_addr_list = (char **) malloc(sizeof(char *) * (cnt+1));        for ( i=0; i<cnt; i++) {            hosts[next].h_addr_list[i] = malloc(h->h_length);            bcopy(h->h_addr_list[i],hosts[next].h_addr_list[i],h->h_length);        }        hosts[next].h_addr_list[i] = NULL;    } else        hosts[next].h_addr_list = NULL;#else    bcopy(h->h_addr, &hosts[next].h_addr, h->h_length);#endif /* h_addr */#else /* HADDRLIST */    bcopy(h->h_addr, &hosts[next].h_addr, h->h_length);#endif /* HADDRLIST */    return(&hosts[next++]);}#ifdef EXCELAN/*  Most other BSD sockets implementations define these in header files  and libraries.*/struct servent {    unsigned short s_port;};struct hostent {    short h_addrtype;    struct in_addr h_addr;    int h_length;};struct servent *getservbyname(service, connection) char *service,*connection; {    static struct servent servrec;    int port;    port = 0;    if (strcmp(service, "telnet") == 0) port = 23;    else if (strcmp(service, "smtp") == 0) port = 25;    else port = atoi(service);    debug(F101,"getservbyname return port ","",port);    if (port > 0) {        servrec.s_port = htons(port);        return(&servrec);    }    return((struct servent *) NULL);}struct hostent *gethostbyname(hostname) char *hostname; {    return((struct hostent *) NULL);}unsigned longinet_addr(name) char *name; {    unsigned long addr;    addr = rhost(&name);    debug(F111,"inet_addr ",name,(int)addr);    return(addr);}char *inet_ntoa(in) struct in_addr in; {    static char name[80];    ckmakxmsg(name, ckuitoa(in.s_net),".",ckuitoa(in.s_host),".",               ckuitoa(in.s_lh),".", ckuitoa(in.s_impno));    return(name);}#else#ifdef DEC_TCPIP                        /* UCX */int ucx_port_bug = 0;                   /* Explained below */#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;    ckstrncpy(p, service, 29);    while (*p = toupper(*p), *p++) {}    p = pbuf;    ckstrncpy(p, proto, 29);    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 supposed to be returned by UCX in network byte order.  However, UCX 2.0 through 2.0C did not do this; 2.0D and later do it.  But there is no way of knowing which UCX version, so we have a user-settable  runtime variable.  Note: UCX 2.0 was only for the VAX.*/    debug(F101,"UCX getservbyname port","",sent.s_port);    debug(F101,"UCX getservbyname ntohs(port)","",ntohs(sent.s_port));    if (ucx_port_bug) {        sent.s_port = htons(sent.s_port);        debug(F100,"UCX-PORT-BUG ON: swapping bytes","",0);        debug(F101,"UCX swapped port","",sent.s_port);        debug(F101,"UCX swapped ntohs(port)","",ntohs(sent.s_port));    }    return &sent;}#endif /* __DECC */#endif /* DEC_TCPIP */#endif /* EXCELAN */#endif /* TCPSOCKET */#ifndef NOTCPOPTS#ifndef datageneralintck_linger(sock, onoff, timo) int sock; 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 set_linger_opt;    struct linger get_linger_opt;    SOCKOPT_T x;#ifdef IKSD    if (!inserver)#endif /* IKSD */      if (sock == -1 ||        nettype != NET_TCPA && nettype != NET_TCPB &&        nettype != NET_SSH || ttmdm >= 0) {        tcp_linger = onoff;        tcp_linger_tmo = timo;        return(1);    }    x = sizeof(get_linger_opt);    if (getsockopt(sock, SOL_SOCKET, SO_LINGER,                    (char *)&get_linger_opt, &x)) {        debug(F111,"TCP ck_linger can't get SO_LINGER",ck_errstr(),errno);    } else if (x != sizeof(get_linger_opt)) {#ifdef OS2        struct _linger16 {            short s_linger;            short s_onoff;        } get_linger_opt16, set_linger_opt16;        if ( x == sizeof(get_linger_opt16) ) {            debug(F111,"TCP setlinger warning: SO_LINGER","len is 16-bit",x);            if (getsockopt(sock,                           SOL_SOCKET, SO_LINGER,                           (char *)&get_linger_opt16, &x)                ) {                debug(F111,                      "TCP ck_linger can't get SO_LINGER",ck_errstr(),errno);            } else if (get_linger_opt16.s_onoff != onoff ||                       get_linger_opt16.s_linger != timo)            {                set_linger_opt16.s_onoff  = onoff;                set_linger_opt16.s_linger = timo;                if (setsockopt(sock,                               SOL_SOCKET,                               SO_LINGER,                               (char *)&set_linger_opt16,                               sizeof(set_linger_opt16))                    ) {                    debug(F111,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -