Annotation of 43BSDReno/contrib/isode-beta/compat/camtec.c, revision 1.1.1.1

1.1       root        1: /* camtec.c - X.25, CONS abstractions for CAMTEC CCL  */
                      2: 
                      3: #ifndef lint
                      4: static char *rcsid = "$Header: /f/osi/compat/RCS/camtec.c,v 7.1 90/07/09 14:31:37 mrose Exp $";
                      5: #endif
                      6: 
                      7: /*
                      8:  * $Header: /f/osi/compat/RCS/camtec.c,v 7.1 90/07/09 14:31:37 mrose Exp $
                      9:  *
                     10:  * Contributed by Keith Ruttle, CAMTEC Electronics Ltd
                     11:  *
                     12:  *
                     13:  * $Log:       camtec.c,v $
                     14:  * Revision 7.1  90/07/09  14:31:37  mrose
                     15:  * sync
                     16:  * 
                     17:  * Revision 7.0  89/11/23  21:22:56  mrose
                     18:  * Release 6.0
                     19:  * 
                     20:  */
                     21: 
                     22: /*
                     23:  *                                NOTICE
                     24:  *
                     25:  *    Acquisition, use, and distribution of this module and related
                     26:  *    materials are subject to the restrictions of a license agreement.
                     27:  *    Consult the Preface in the User's Manual for the full terms of
                     28:  *    this agreement.
                     29:  *
                     30:  */
                     31: 
                     32: 
                     33: /* LINTLIBRARY */
                     34: 
                     35: #include <errno.h>
                     36: #include <stdio.h>
                     37: #include "general.h"
                     38: #include "manifest.h"
                     39: 
                     40: #ifdef  X25
                     41: 
                     42: #include "x25.h"
                     43: #include "isoaddrs.h"
                     44: 
                     45: 
                     46: #ifdef  CAMTEC_CCL
                     47: 
                     48: #include "tailor.h"
                     49: #include "tpkt.h"
                     50: 
                     51: /*    4.[23] UNIX: CCL X25 */
                     52: 
                     53: 
                     54: static char calling_dte[NSAP_DTELEN + 1];
                     55: 
                     56: /*  */
                     57: 
                     58: int     start_x25_client (local)
                     59: struct NSAPaddr *local;
                     60: {
                     61:     int     sd, pgrp;
                     62:     CONN_DB l_iov;
                     63: 
                     64:     if (local != NULLNA)
                     65:        local -> na_stack = NA_X25, local -> na_community = ts_comm_x25_default;
                     66:     if ((sd = socket (AF_CCL, SOCK_STREAM, CCLPROTO_X25)) == NOTOK) {
                     67:        SLOG (compat_log, LLOG_EXCEPTIONS, "failed", ("socket"));
                     68:        return NOTOK; /* Error can be found in errno */
                     69:     }
                     70: 
                     71:     pgrp = getpid();
                     72:     if (ioctl(sd, SIOCSPGRP, &pgrp)) {
                     73:        SLOG (compat_log, LLOG_EXCEPTIONS, "failed", ("SIOCSPGRP"));
                     74:        return NOTOK; /* Error can be found in errno */
                     75:     }
                     76: 
                     77:     l_iov.ccl_iovec[0].iov_base = calling_dte;
                     78:     gen2if(local, &l_iov, ADDR_LOCAL);
                     79: 
                     80:     return sd;
                     81: }
                     82: 
                     83: /*  */
                     84: 
                     85: int     start_x25_server (local, backlog, opt1, opt2)
                     86: struct NSAPaddr *local;
                     87: int     backlog,
                     88:        opt1,
                     89:        opt2;
                     90: {
                     91:     int     sd, pgrp;
                     92:     CONN_DB b_iov;
                     93:     char param1[128];
                     94: 
                     95:     b_iov.ccl_iovec[0].iov_base = param1;
                     96: 
                     97:     if ((sd = socket (AF_CCL, SOCK_STREAM, CCLPROTO_X25)) == NOTOK) {
                     98:        SLOG (compat_log, LLOG_EXCEPTIONS, "failed", ("socket"));
                     99:        return NOTOK; /* Can't get an X.25 socket */
                    100:     }
                    101: 
                    102:     pgrp = getpid();
                    103:     if (ioctl(sd, SIOCSPGRP, &pgrp)) {
                    104:        SLOG (compat_log, LLOG_EXCEPTIONS, "failed", ("SIOCSPGRP"));
                    105:        return NOTOK; /* Error can be found in errno */
                    106:     }
                    107: 
                    108:     if (local != NULLNA) {
                    109:        local -> na_stack = NA_X25, local -> na_community = ts_comm_x25_default;
                    110:        if (local -> na_dtelen == 0) {
                    111:            (void) strcpy (local -> na_dte, x25_local_dte);
                    112:            local -> na_dtelen = strlen(x25_local_dte);
                    113:            if (local -> na_pidlen == 0 && *x25_local_pid)
                    114:                local -> na_pidlen =
                    115:                    str2sel (x25_local_pid, -1, local -> na_pid, NPSIZE);
                    116:        }
                    117:     }
                    118: 
                    119:     (void) gen2if (local, &b_iov, ADDR_LISTEN);
                    120:     if (bind (sd, &b_iov, sizeof(b_iov)) != NOTOK) {
                    121:        if (ioctl(sd, CCL_AUTO_ACCEPT, 1) < 0) {
                    122:                SLOG (compat_log, LLOG_EXCEPTIONS, "failed",
                    123:                      ("CCL_AUTO_ACCEPT"));
                    124:                close (sd);
                    125:                return NOTOK;
                    126:        }
                    127:        (void) listen (sd, backlog);
                    128:        return sd;
                    129:     }
                    130: 
                    131:     (void) close (sd);
                    132:     return NOTOK;
                    133: }
                    134: 
                    135: /*  */
                    136: 
                    137: int     join_x25_client (fd, remote)
                    138: int     fd;
                    139: struct NSAPaddr *remote;
                    140: {
                    141:     CONN_DB     sck;
                    142:     struct iovec *iov;
                    143:     int         i, len = 0;
                    144:     int         nfd;
                    145:     char        param1[128];
                    146:     char        param2[128];
                    147:     char        param3[128];
                    148:     char        param4[256];
                    149: 
                    150:     iov = &(sck.ccl_iovec[0]);
                    151:     if((nfd = accept (fd, (char *) 0, &len)) == NOTOK)
                    152:        return NOTOK;
                    153:     iov[0].iov_base = param1;
                    154:     iov[1].iov_base = param2;
                    155:     iov[2].iov_base = param3;
                    156:     iov[3].iov_base = param4;
                    157:     iov[0].iov_len = iov[1].iov_len = iov[2].iov_len = 128;
                    158:     iov[3].iov_len = 256;
                    159:     iov[4].iov_len = iov[5].iov_len = iov[6].iov_len = 0;
                    160:     if (ioctl(nfd, CCL_FETCH_CONNECT, &iov[0]) < 0)
                    161:        return NOTOK;
                    162:     (void) if2gen (remote, &sck, ADDR_REMOTE);
                    163:     ioctl (nfd, CCL_SEND_TYPE, 0);
                    164:     return nfd;
                    165: }
                    166: 
                    167: int     join_x25_server (fd, remote)
                    168: int     fd;
                    169: struct NSAPaddr *remote;
                    170: {
                    171:     CONN_DB zsck;
                    172:     CONN_DB *sck = &zsck;
                    173:     int r;
                    174:     struct iovec *iov = &( zsck.ccl_iovec[0] );
                    175:     char        param1[128];
                    176:     char        param3[128];
                    177:     char        param4[256];
                    178: 
                    179:     if (remote == NULLNA || remote -> na_stack != NA_X25)
                    180:     {
                    181:        SLOG (compat_log, LLOG_EXCEPTIONS, NULLCP,
                    182:              ("Invalid type na%d", remote->na_stack));
                    183:        return NOTOK;
                    184:     }
                    185: 
                    186:     iov[0].iov_base = param1;
                    187:     iov[1].iov_base = calling_dte;
                    188:     iov[1].iov_len = strlen(calling_dte);
                    189:     iov[2].iov_base = param3;
                    190:     iov[3].iov_base = param4;
                    191:     iov[4].iov_len = iov[5].iov_len = iov[6].iov_len = 0;
                    192: 
                    193:     (void) gen2if (remote, sck, ADDR_REMOTE);
                    194:     if ((r = connect (fd, sck, sizeof (CONN_DB))) >= 0)
                    195:            ioctl (fd, CCL_SEND_TYPE, 0);
                    196:     bzero(calling_dte, sizeof calling_dte );
                    197:     return (r);
                    198: }
                    199: 
                    200: int     read_x25_socket (fd, buffer, len)
                    201: int     fd, len;
                    202: char    *buffer;
                    203: {
                    204:     static u_char mode;
                    205:     int cc, count = 0, total = len;
                    206:     char *p = buffer;
                    207: 
                    208:     do {
                    209:            cc = recv (fd, p, total, 0);
                    210:            switch (cc) {
                    211:                case NOTOK:
                    212:                        if (errno == ECONNRESET) {
                    213:                                struct iovec iov[7];
                    214:                                char parm[34];
                    215:                                int i;
                    216:                                iov[0].iov_base = parm;
                    217:                                iov[0].iov_len = 1;
                    218:                                iov[1].iov_base = parm + 1;
                    219:                                iov[1].iov_len = 32;
                    220:                                for (i = 2; i < 7; i++) {
                    221:                                        iov[i].iov_base = (char *)0;
                    222:                                        iov[i].iov_len = 0;
                    223:                                }
                    224:                                ioctl(fd, CCL_FETCH_RESET, iov);
                    225:                        elucidate_x25_err( 1 << RECV_DIAG, iov[0].iov_base);
                    226:                        }
                    227:                case 0:
                    228:                        return cc;
                    229: 
                    230:                default:
                    231:                        ioctl (fd, CCL_RECV_TYPE, &mode);
                    232:                        count += cc;
                    233:                        p += cc;
                    234:                        total -= cc;
                    235:                        break;
                    236:            }
                    237:     } while (total > 0 && (mode & MORE_DATA));
                    238: 
                    239:     DLOG (compat_log, LLOG_DEBUG,
                    240:          ("X25 read, total %d", count ));
                    241:     return count;
                    242: }
                    243: 
                    244: int     write_x25_socket (fd, buffer, len)
                    245: int     fd, len;
                    246: char    *buffer;
                    247: {
                    248:     int         count;
                    249:     int         cc;
                    250: 
                    251:     count = send(fd, buffer, len, 0);
                    252:     DLOG (compat_log, LLOG_DEBUG,
                    253:          ("X25 write, total %d/%d", count, len));
                    254:     return count;
                    255: }
                    256: #endif
                    257: #endif 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.