aboutsummaryrefslogtreecommitdiff
path: root/src/common/pack.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/pack.c')
-rw-r--r--src/common/pack.c212
1 files changed, 0 insertions, 212 deletions
diff --git a/src/common/pack.c b/src/common/pack.c
index 82ac7fe..94fa3d2 100644
--- a/src/common/pack.c
+++ b/src/common/pack.c
@@ -35,218 +35,6 @@ typedef signed short shalf;
35typedef signed int sword; 35typedef signed int sword;
36 36
37 37
38/*
39 "bhwAcslxPBHWCSLX"
40
41 Small letters: do not convert (not implemented for arrays and P)
42 Captial letters: convert from network byte order to host byte order
43
44 b - byte
45 h - half-word
46 w - word
47 a - array (32-byte unsigned long + that many bytes)
48 c - signed 8 bit value
49 s - signed 16 bit value
50 l - signed 32 bit value
51 x - signed 64 bit value
52 p - (unpack only) value is a pointer to a pointer. Generate the buffer
53 to hold the data.
54
55 prefixing with a number K means that the argument will be an array of K
56 of the arguments specified by the letter
57 */
58
59int
60EXTRACTOR_common_cat_pack (void *buf, const char *fmt, ...)
61{
62 va_list ap;
63 word blen, val;
64 int npacked;
65 unsigned int nreps, i;
66 byte *bp, *bytep;
67 half *halfp;
68 word *wordp;
69 void *arr;
70 struct cat_bvec *cbvp;
71 char *cp;
72
73 va_start (ap, fmt);
74
75 npacked = 0;
76 bp = (byte *) buf;
77
78 while (*fmt)
79 {
80 nreps = 0;
81
82 if (isdigit ( (unsigned char) *fmt))
83 {
84 /* We use cp instead of fmt to keep the 'const' qualifier of fmt */
85 nreps = strtoul (fmt, &cp, 0);
86 fmt = cp;
87 }
88
89 switch (*fmt)
90 {
91 case 'B':
92 case 'b':
93 case 'C':
94 case 'c':
95 if (!nreps)
96 {
97 *bp++ = va_arg (ap, int);
98 npacked += 1;
99 }
100 else
101 {
102 bytep = va_arg (ap, byte *);
103 for (i = 0; i < nreps; ++i)
104 {
105 *bp++ = bytep[i];
106 npacked += 1;
107 }
108 }
109 break;
110
111 case 'h':
112 case 's':
113 if (!nreps)
114 {
115 val = va_arg (ap, int);
116 *bp++ = val & 0xFF;
117 *bp++ = val >> 8;
118 npacked += 2;
119 }
120 else
121 {
122 halfp = va_arg (ap, half *);
123 for (i = 0; i < nreps; ++i)
124 {
125 val = halfp[i];
126 *bp++ = val & 0xFF;
127 *bp++ = val >> 8;
128 npacked += 2;
129 }
130 }
131 break;
132
133 case 'H':
134 case 'S':
135 if (!nreps)
136 {
137 val = va_arg (ap, int);
138 *bp++ = val >> 8;
139 *bp++ = val & 0xFF;
140 npacked += 2;
141 }
142 else
143 {
144 halfp = va_arg (ap, half *);
145 for (i = 0; i < nreps; ++i)
146 {
147 val = halfp[i];
148 *bp++ = val >> 8;
149 *bp++ = val & 0xFF;
150 npacked += 2;
151 }
152 }
153 break;
154
155 case 'l':
156 case 'w':
157 if (!nreps)
158 {
159 val = va_arg (ap, word);
160 *bp++ = val & 0xFF;
161 *bp++ = val >> 8;
162 *bp++ = val >> 16;
163 *bp++ = val >> 24;
164 npacked += 4;
165 }
166 else
167 {
168 wordp = va_arg (ap, word *);
169 for (i = 0; i < nreps; ++i)
170 {
171 val = wordp[i];
172 *bp++ = val & 0xFF;
173 *bp++ = val >> 8;
174 *bp++ = val >> 16;
175 *bp++ = val >> 24;
176 npacked += 4;
177 }
178 }
179 break;
180
181 case 'L':
182 case 'W':
183 if (!nreps)
184 {
185 val = va_arg (ap, word);
186 *bp++ = val >> 24;
187 *bp++ = val >> 16;
188 *bp++ = val >> 8;
189 *bp++ = val & 0xFF;
190 npacked += 4;
191 }
192 else
193 {
194 wordp = va_arg (ap, word *);
195 for (i = 0; i < nreps; ++i)
196 {
197 val = wordp[i];
198 *bp++ = val >> 24;
199 *bp++ = val >> 16;
200 *bp++ = val >> 8;
201 *bp++ = val & 0xFF;
202 npacked += 4;
203 }
204 }
205 break;
206
207 case 'A':
208 if (!nreps)
209 {
210 blen = va_arg (ap, word);
211 arr = va_arg (ap, void *);
212 *bp++ = blen >> 24;
213 *bp++ = blen >> 16;
214 *bp++ = blen >> 8;
215 *bp++ = blen & 0xFF;
216 memmove (bp, arr, blen);
217 bp += blen;
218 npacked += blen + 4; /* +4 for the 32 bits of length field */
219 }
220 else
221 {
222 cbvp = va_arg (ap, struct cat_bvec *);
223 for (i = 0; i < nreps; ++i)
224 {
225 blen = cbvp[i].len;
226 arr = cbvp[i].data;
227 *bp++ = blen >> 24;
228 *bp++ = blen >> 16;
229 *bp++ = blen >> 8;
230 *bp++ = blen & 0xFF;
231 memmove (bp, arr, blen);
232 bp += blen;
233 npacked += blen + 4; /* see above */
234 }
235 }
236 break;
237
238 default:
239 va_end (ap);
240 return -1;
241 }
242 ++fmt;
243 }
244
245 va_end (ap);
246 return npacked;
247}
248
249
250 38
251int 39int
252EXTRACTOR_common_cat_unpack (const void *buf, const char *fmt, ...) 40EXTRACTOR_common_cat_unpack (const void *buf, const char *fmt, ...)