1 /* packet packing and unpacking */
8 pmem(Pkt *p, void *v, int len)
21 ppath(Pkt *p, char *str)
30 if(p->s->caps & CAP_UNICODE){
31 if(((p->pos - p->buf) % 2) != 0) /* pad to even offset */
34 str += chartorune(&r, str);
41 while((c = *str++) != 0){
52 pstr(Pkt *p, char *str)
60 if(p->s->caps & CAP_UNICODE){
61 if(((p->pos - p->buf) % 2) != 0)
62 p8(p, 0); /* pad to even offset */
64 str += chartorune(&r, str);
77 pascii(Pkt *p, char *str)
89 pl64(Pkt *p, uvlong n)
158 * Encode a Netbios name
161 pname(Pkt *p, char *name, char pad)
168 for(i = 0; i < 16; i++) {
170 if(!done && name[i] == '\0')
173 c = islower(name[i])? toupper(name[i]): name[i];
174 *p->pos++ = ((uchar)c >> 4) + 'A';
175 *p->pos++ = (c & 0xf) + 'A';
182 pvtime(Pkt *p, uvlong n)
195 pdatetime(Pkt *p, long utc)
198 Tm *tm = localtime(utc);
199 int t = tm->hour << 11 | tm->min << 5 | (tm->sec / 2);
200 int d = (tm->year - 80) << 9 | (tm->mon + 1) << 5 | tm->mday;
203 * bug in word swapping in Win95 requires this
205 if(p->s->caps & CAP_NT_SMBS){
217 gmem(Pkt *p, void *v, int n)
223 while(n-- && p->pos < p->eop)
228 * note len is the length of the source string in
229 * in runes or bytes, in ASCII mode this is also the size
230 * of the output buffer but this is not so in Unicode mode!
233 gstr(Pkt *p, char *str, int n)
241 if(p->s->caps & CAP_UNICODE){
243 while(*p->pos && n && p->pos < p->eop){
245 i += runetochar(str +i, &r);
250 while(*p->pos && p->pos < p->eop)
253 * some versions of windows terminate a rune string
254 * with a single nul so we do a dangerous hack...
261 while(*p->pos && n-- && p->pos < p->eop)
264 while(*p->pos++ && p->pos < p->eop)
270 gascii(Pkt *p, char *str, int n)
275 while(*p->pos && n-- && p->pos < p->eop)
278 while(*p->pos++ && p->pos < p->eop)
288 if(p->pos + 8 > p->eop)
291 n = (uvlong)*p->pos++;
292 n |= (uvlong)*p->pos++ << 8;
293 n |= (uvlong)*p->pos++ << 16;
294 n |= (uvlong)*p->pos++ << 24;
295 n |= (uvlong)*p->pos++ << 32;
296 n |= (uvlong)*p->pos++ << 40;
297 n |= (uvlong)*p->pos++ << 48;
298 n |= (uvlong)*p->pos++ << 56;
307 if(p->pos + 6 > p->eop)
310 n = (uvlong)*p->pos++ << 40;
311 n |= (uvlong)*p->pos++ << 24;
312 n |= (uvlong)*p->pos++ << 32;
313 n |= (uvlong)*p->pos++ << 16;
314 n |= (uvlong)*p->pos++ << 8;
315 n |= (uvlong)*p->pos++;
324 if(p->pos + 4 > p->eop)
327 n = (uint)*p->pos++ << 24;
328 n |= (uint)*p->pos++ << 16;
329 n |= (uint)*p->pos++ << 8;
330 n |= (uint)*p->pos++;
339 if(p->pos + 4 > p->eop)
343 n |= (uint)*p->pos++ << 8;
344 n |= (uint)*p->pos++ << 16;
345 n |= (uint)*p->pos++ << 24;
354 if(p->pos + 2 > p->eop)
356 n = (uint)*p->pos++ << 8;
357 n |= (uint)*p->pos++;
366 if(p->pos + 2 > p->eop)
369 n |= (uint)*p->pos++ << 8;
376 if(p->pos + 1 > p->eop)
378 return (uint)*p->pos++;
387 if(p->pos + 4 > p->eop)
391 * bug in word swapping in Win95 requires this
393 if(p->s->caps & CAP_NT_SMBS){
401 tm.year = 80 + (d >> 9);
402 tm.mon = ((d >> 5) & 017) - 1;
408 tm.min = (t >> 5) & 63;
409 tm.sec = (t & 31) << 1;
419 if(p->pos + 8 > p->eop)
422 vl = (uvlong)gl32(p);
423 vl |= (uvlong)gl32(p) << 32;
431 gconv(Pkt *p, int conv, char *str, int n)
436 off = gl32(p) & 0xffff;
437 if(off == 0 || p->tdata - conv + off > p->eop){
443 p->pos = p->tdata - conv + off;
449 goff(Pkt *p, uchar *base, char *str, int n)
455 if(off == 0 || base + off > p->eop){