|
|
1.1 ! root 1: /* ts2bridge.c - TPM: X.25 interface via bridge */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/tsap/RCS/ts2bridge.c,v 7.3 90/07/09 14:51:11 mrose Exp $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/tsap/RCS/ts2bridge.c,v 7.3 90/07/09 14:51:11 mrose Exp $ ! 9: * ! 10: * Contributed by Julian Onions, Nottingham University in the UK ! 11: * ! 12: * ! 13: * $Log: ts2bridge.c,v $ ! 14: * Revision 7.3 90/07/09 14:51:11 mrose ! 15: * sync ! 16: * ! 17: * Revision 7.2 90/03/23 17:31:14 mrose ! 18: * 8 ! 19: * ! 20: * Revision 7.1 89/12/07 01:07:34 mrose ! 21: * queued writes ! 22: * ! 23: * Revision 7.0 89/11/23 22:30:35 mrose ! 24: * Release 6.0 ! 25: * ! 26: */ ! 27: ! 28: /* ! 29: * NOTICE ! 30: * ! 31: * Acquisition, use, and distribution of this module and related ! 32: * materials are subject to the restrictions of a license agreement. ! 33: * Consult the Preface in the User's Manual for the full terms of ! 34: * this agreement. ! 35: * ! 36: */ ! 37: ! 38: ! 39: /* LINTLIBRARY */ ! 40: ! 41: #include <stdio.h> ! 42: #include "tpkt.h" ! 43: #ifdef BRIDGE_X25 ! 44: #include <sys/uio.h> ! 45: #include <sys/ioctl.h> ! 46: #include "tailor.h" ! 47: ! 48: /* ! 49: * This could be anything up to the size TCP encapsualtion howver, to ! 50: * interwork with the X.25 it should be the same as X.25's MAXNSDU. ! 51: * This define is clearly a hack - but including x25.h messes things up more! ! 52: */ ! 53: #define MAXNSDU (1024) ! 54: ! 55: extern int errno; ! 56: ! 57: /* N-CONNECT.REQUEST */ ! 58: /* ARGSUSED */ ! 59: int bridgeopen (tb, local, remote, td, async) ! 60: register struct tsapblk *tb; ! 61: struct NSAPaddr *local, ! 62: *remote; ! 63: struct TSAPdisconnect *td; ! 64: { ! 65: register int fd; ! 66: ! 67: if ((fd = start_bridge_client (local)) == NOTOK) ! 68: return tsaplose (td, DR_CONGEST, "socket", "unable to start"); ! 69: ! 70: tb -> tb_fd = fd; ! 71: (void) BTService (tb); ! 72: ! 73: if (join_bridge_server (fd, remote) == NOTOK) { ! 74: (void) tsaplose (td, DR_REFUSED, "connection", "unable to establish"); ! 75: (void) close_bridge_socket (fd); ! 76: return (tb -> tb_fd = NOTOK); ! 77: } ! 78: return DONE; ! 79: } ! 80: ! 81: /* */ ! 82: ! 83: /* ARGSUSED */ ! 84: ! 85: static int bridgeretry (tb, td) ! 86: struct tsapblk *tb; ! 87: struct TSAPdisconnect *td; ! 88: { ! 89: int fd = tb -> tb_fd; ! 90: fd_set mask; ! 91: ! 92: FD_ZERO (&mask); ! 93: FD_SET (fd, &mask); ! 94: ! 95: if (xselect (fd + 1, NULLFD, &mask, NULLFD, 0) < 1) ! 96: return OK; ! 97: ! 98: return DONE; ! 99: } ! 100: ! 101: /* init for read from network/write to network */ ! 102: ! 103: #define bridgeinit tcpinit ! 104: #define bridgeread read ! 105: int close_bridge_socket (); ! 106: #define select_bridge_socket selsocket ! 107: ! 108: int tcpinit (); ! 109: int tcpwrite (); ! 110: int selsocket (); ! 111: int read (); ! 112: ! 113: /* */ ! 114: ! 115: /* ARGSUSED */ ! 116: ! 117: char *bridgesave (fd, dte1, l1, dte2, l2, td) ! 118: int fd; ! 119: char *dte1; ! 120: int l1; ! 121: char *dte2; ! 122: int l2; ! 123: struct TSAPdisconnect *td; ! 124: { ! 125: static char buffer[BUFSIZ]; ! 126: ! 127: (void) sprintf (buffer, "%c%d %*s %*s", ! 128: NT_BRG, fd, l1, dte1, l2, dte2); ! 129: return buffer; ! 130: } ! 131: ! 132: ! 133: int bridgerestore (tb, buffer, td) ! 134: register struct tsapblk *tb; ! 135: char *buffer; ! 136: struct TSAPdisconnect *td; ! 137: { ! 138: int fd; ! 139: char dte1[NSAP_DTELEN + 1], ! 140: dte2[NSAP_DTELEN + 1]; ! 141: register struct NSAPaddr *na; ! 142: register struct tsapADDR *ta; ! 143: ! 144: if (sscanf (buffer, "%d %s %s", &fd, dte1, dte2) != 3 || fd < 0) ! 145: return tsaplose (td, DR_PARAMETER, NULLCP, ! 146: "bad initialization vector \"%s\"", buffer); ! 147: ! 148: ta = &tb -> tb_initiating; ! 149: ta -> ta_present = 1; ! 150: na = &ta -> ta_addr; ! 151: na -> na_stack = NA_BRG; ! 152: na -> na_community = ts_comm_x25_default; ! 153: bcopy(dte1, na -> na_dte, strlen(dte1)); ! 154: na -> na_dtelen = strlen (na -> na_dte); ! 155: ! 156: tb -> tb_fd = fd; ! 157: (void) BTService (tb); ! 158: ! 159: ta = &tb -> tb_responding; ! 160: ta -> ta_present = 1; ! 161: na = &ta -> ta_addr; ! 162: na -> na_stack = NA_BRG; ! 163: na -> na_community = ts_comm_x25_default; ! 164: bcopy(dte1, na -> na_dte, strlen(dte2)); ! 165: na -> na_dtelen = strlen (na -> na_dte); ! 166: ! 167: return OK; ! 168: } ! 169: ! 170: /* */ ! 171: ! 172: int BTService (tb) ! 173: register struct tsapblk *tb; ! 174: { ! 175: tb -> tb_flags |= TB_BRG; ! 176: ! 177: tb -> tb_tsdusize = MAXNSDU - (tb -> tb_tpduslop = DT_MAGIC); ! 178: ! 179: tb -> tb_retryfnx = bridgeretry; ! 180: ! 181: tb -> tb_initfnx = bridgeinit; ! 182: tb -> tb_readfnx = bridgeread; ! 183: tb -> tb_writefnx = tp0write; ! 184: tb -> tb_closefnx = close_bridge_socket; ! 185: tb -> tb_selectfnx = select_bridge_socket; ! 186: ! 187: tp0init (tb); ! 188: } ! 189: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.