|
|
1.1 root 1: /* str2tpkt.c - read/write a TPDU thru a string */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/tsap/RCS/str2tpkt.c,v 7.1 89/12/07 01:07:28 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/tsap/RCS/str2tpkt.c,v 7.1 89/12/07 01:07:28 mrose Exp $
9: *
10: *
11: * $Log: str2tpkt.c,v $
12: * Revision 7.1 89/12/07 01:07:28 mrose
13: * queued writes
14: *
15: * Revision 7.0 89/11/23 22:30:30 mrose
16: * Release 6.0
17: *
18: */
19:
20: /*
21: * NOTICE
22: *
23: * Acquisition, use, and distribution of this module and related
24: * materials are subject to the restrictions of a license agreement.
25: * Consult the Preface in the User's Manual for the full terms of
26: * this agreement.
27: *
28: */
29:
30:
31: /* LINTLIBRARY */
32:
33: #include <stdio.h>
34: #include "tpkt.h"
35: #include "tailor.h"
36:
37:
38: int readfnx (), getfnx (), writefnx (), putfnx ();
39:
40: /* */
41:
42: char *tpkt2str (t)
43: struct tsapkt *t;
44: {
45: int cc;
46: char packet[BUFSIZ];
47: static char buffer[2 * sizeof packet + 1];
48:
49: (void) writefnx ((struct tsapblk *) NOTOK, packet, 0);
50: if (tpkt2fd ((struct tsapblk *) 0, t, putfnx) == NOTOK)
51: return NULLCP;
52:
53: cc = writefnx ((struct tsapblk *) NOTOK, NULLCP, 0);
54: if (t -> t_qbuf) {
55: bcopy (t -> t_qbuf -> qb_data, packet + cc, t -> t_qbuf -> qb_len);
56: cc += t -> t_qbuf -> qb_len;
57: }
58: buffer[explode (buffer, (u_char *) packet, cc)] = NULL;
59:
60: DLOG (tsap_log, LLOG_PDUS,
61: ("write %d bytes, \"%s\"", strlen (buffer), buffer));
62:
63: return buffer;
64: }
65:
66: /* */
67:
68: struct tsapkt *str2tpkt (buffer)
69: char *buffer;
70: {
71: char packet[BUFSIZ];
72: register struct tsapkt *t;
73:
74: DLOG (tsap_log, LLOG_PDUS,
75: ("read %d bytes, \"%s\"", strlen (buffer), buffer));
76:
77: (void) getfnx (NOTOK, NULLPKT, packet,
78: implode ((u_char *) packet, buffer, strlen (buffer)));
79: t = fd2tpkt (0, getfnx, readfnx);
80:
81: return t;
82: }
83:
84: /* */
85:
86: static int getfnx (fd, t, buffer, n)
87: int fd;
88: register struct tsapkt *t;
89: char *buffer;
90: int n;
91: {
92: static int cc;
93:
94: if (fd == NOTOK) {
95: (void) readfnx (NOTOK, buffer, cc = n);
96: return OK;
97: }
98:
99: t -> t_length = cc + sizeof t -> t_pkthdr;
100: t -> t_vrsn = TPKT_VRSN;
101:
102: if (readfnx (fd, (char *) &t -> t_li, sizeof t -> t_li)
103: != sizeof t -> t_li)
104: return DR_LENGTH;
105:
106: if (readfnx (fd, (char *) &t -> t_code, sizeof t -> t_code)
107: != sizeof t -> t_code)
108: return DR_LENGTH;
109:
110: return OK;
111: }
112:
113:
114: static int readfnx (fd, buffer, n)
115: int fd,
116: n;
117: char *buffer;
118: {
119: register int i;
120: static int cc;
121: static char *bp;
122:
123: if (fd == NOTOK) {
124: bp = buffer, cc = n;
125:
126: return OK;
127: }
128:
129: if ((i = min (cc, n)) > 0) {
130: bcopy (bp, buffer, n);
131: bp += i, cc -= i;
132: }
133:
134: return i;
135: }
136:
137: /* */
138:
139: static int putfnx (tb, t, cp, n)
140: struct tsapblk *tb;
141: register struct tsapkt *t;
142: char *cp;
143: int n;
144: {
145: register int cc;
146: register struct udvec *uv;
147:
148: cc = sizeof t -> t_li;
149: if (writefnx (tb, (char *) &t -> t_li, cc) != cc)
150: return NOTOK;
151:
152: if (writefnx (tb, (char *) &t -> t_code, sizeof t -> t_code)
153: != sizeof t -> t_code)
154: return NOTOK;
155: cc += sizeof t -> t_code;
156:
157: if (writefnx (tb, cp, n) != n)
158: return NOTOK;
159: cc += n;
160:
161: if (t -> t_vdata
162: && writefnx (tb, t -> t_vdata, t -> t_vlen) != t -> t_vlen)
163: return NOTOK;
164: cc += t -> t_vlen;
165:
166: for (uv = t -> t_udvec; uv -> uv_base; uv++) {
167: if (writefnx (tb, uv -> uv_base, uv -> uv_len) != uv -> uv_len)
168: return NOTOK;
169: cc += uv -> uv_len;
170: }
171:
172: return cc;
173: }
174:
175: /* */
176:
177: static int writefnx (tb, buffer, n)
178: struct tsapblk *tb;
179: int n;
180: char *buffer;
181: {
182: static int cc;
183: static char *bp;
184:
185: if (tb) {
186: if (buffer == NULLCP)
187: return cc;
188: bp = buffer, cc = 0;
189:
190: return OK;
191: }
192:
193: bcopy (buffer, bp, n);
194: bp += n, cc += n;
195:
196: return n;
197: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.