|
|
1.1 root 1: /* str2spkt.c - read/write a SPDU thru a string */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/ssap/RCS/str2spkt.c,v 7.0 89/11/23 22:25:53 mrose Rel $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/ssap/RCS/str2spkt.c,v 7.0 89/11/23 22:25:53 mrose Rel $
9: *
10: *
11: * $Log: str2spkt.c,v $
12: * Revision 7.0 89/11/23 22:25:53 mrose
13: * Release 6.0
14: *
15: */
16:
17: /*
18: * NOTICE
19: *
20: * Acquisition, use, and distribution of this module and related
21: * materials are subject to the restrictions of a license agreement.
22: * Consult the Preface in the User's Manual for the full terms of
23: * this agreement.
24: *
25: */
26:
27:
28: /* LINTLIBRARY */
29:
30: #include <stdio.h>
31: #include "spkt.h"
32: #include "tailor.h"
33:
34: /* */
35:
36: char *spkt2str (s)
37: struct ssapkt *s;
38: {
39: int i,
40: len;
41: char *base,
42: *dp;
43: static char buffer[(CONNECT_MAX + BUFSIZ) * 2 + 1];
44:
45: if (spkt2tsdu (s, &base, &len) == NOTOK)
46: return NULLCP;
47: if (s -> s_udata)
48: switch (s -> s_code) {
49: case SPDU_DT:
50: if (s -> s_mask & SMASK_SPDU_GT)
51: break; /* else fall */
52: case SPDU_EX:
53: case SPDU_TD:
54: if ((dp = realloc (base, (unsigned) (i = len + s -> s_ulen)))
55: == NULL) {
56: free (base);
57: return NULLCP;
58: }
59: bcopy (s -> s_udata, (base = dp) + len, s -> s_ulen);
60: len = i;
61: break;
62:
63: default:
64: break;
65: }
66:
67: buffer[explode (buffer, (u_char *) base, len)] = NULL;
68: if (len > 0)
69: free (base);
70:
71: #ifdef DEBUG
72: if (ssap_log -> ll_events & LLOG_PDUS) {
73: LLOG (ssap_log, LLOG_PDUS,
74: ("write %d bytes, \"%s\"", strlen (buffer), buffer));
75: spkt2text (ssap_log, s, 0);
76: }
77: #endif
78:
79: return buffer;
80: }
81:
82: /* */
83:
84: struct ssapkt *str2spkt (buffer)
85: char *buffer;
86: {
87: int cc;
88: char packet[CONNECT_MAX + BUFSIZ];
89: register struct ssapkt *s;
90: struct qbuf qbs;
91: register struct qbuf *qb = &qbs,
92: *qp;
93:
94: bzero ((char *) qb, sizeof *qb);
95: qb -> qb_forw = qb -> qb_back = qb;
96:
97: cc = implode ((u_char *) packet, buffer, strlen (buffer));
98: if ((qp = (struct qbuf *) malloc (sizeof *qp + (unsigned) cc)) == NULL)
99: s = NULLSPKT;
100: else {
101: bcopy (packet, qp -> qb_data = qp -> qb_base, qp -> qb_len = cc);
102: insque (qp, qb -> qb_back);
103: s = tsdu2spkt (qb, cc, NULLIP);
104: QBFREE (qb);
105: }
106:
107: #ifdef DEBUG
108: if (ssap_log -> ll_events & LLOG_PDUS) {
109: LLOG (ssap_log, LLOG_PDUS,
110: ("read %d bytes, \"%s\"", strlen (buffer), buffer));
111: spkt2text (ssap_log, s, 1);
112: }
113: #endif
114:
115: return s;
116: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.