1 /* packet packing and unpacking */
8 pmem(Pkt *p, void *v, int len)
21 ppath(Pkt *p, char *str)
30 if(p->s->flags2 & FL2_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->flags2 & FL2_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->flags2 & FL2_UNICODE){
242 if(((p->pos - p->buf) % 2) != 0)
243 g8(p); /* strip padding to even offset */
246 while(*p->pos && n && p->pos < p->eop){
248 i += runetochar(str +i, &r);
253 while(*p->pos && p->pos < p->eop)
256 * some versions of windows terminate a rune string
257 * with a single nul so we do a dangerous hack...
264 while(*p->pos && n-- && p->pos < p->eop)
267 while(*p->pos++ && p->pos < p->eop)
273 gascii(Pkt *p, char *str, int n)
278 while(*p->pos && n-- && p->pos < p->eop)
281 while(*p->pos++ && p->pos < p->eop)
291 if(p->pos + 8 > p->eop)
294 n = (uvlong)*p->pos++;
295 n |= (uvlong)*p->pos++ << 8;
296 n |= (uvlong)*p->pos++ << 16;
297 n |= (uvlong)*p->pos++ << 24;
298 n |= (uvlong)*p->pos++ << 32;
299 n |= (uvlong)*p->pos++ << 40;
300 n |= (uvlong)*p->pos++ << 48;
301 n |= (uvlong)*p->pos++ << 56;
310 if(p->pos + 6 > p->eop)
313 n = (uvlong)*p->pos++ << 40;
314 n |= (uvlong)*p->pos++ << 24;
315 n |= (uvlong)*p->pos++ << 32;
316 n |= (uvlong)*p->pos++ << 16;
317 n |= (uvlong)*p->pos++ << 8;
318 n |= (uvlong)*p->pos++;
327 if(p->pos + 4 > p->eop)
330 n = (uint)*p->pos++ << 24;
331 n |= (uint)*p->pos++ << 16;
332 n |= (uint)*p->pos++ << 8;
333 n |= (uint)*p->pos++;
342 if(p->pos + 4 > p->eop)
346 n |= (uint)*p->pos++ << 8;
347 n |= (uint)*p->pos++ << 16;
348 n |= (uint)*p->pos++ << 24;
357 if(p->pos + 2 > p->eop)
359 n = (uint)*p->pos++ << 8;
360 n |= (uint)*p->pos++;
369 if(p->pos + 2 > p->eop)
372 n |= (uint)*p->pos++ << 8;
379 if(p->pos + 1 > p->eop)
381 return (uint)*p->pos++;
390 if(p->pos + 4 > p->eop)
394 * bug in word swapping in Win95 requires this
396 if(p->s->caps & CAP_NT_SMBS){
404 memset(&tm, 0, sizeof(tm));
405 tm.year = 80 + (d >> 9);
406 tm.mon = ((d >> 5) & 017) - 1;
410 tm.min = (t >> 5) & 63;
411 tm.sec = (t & 31) << 1;
412 strcpy(tm.zone, "GMT");
414 return tm2sec(&tm) + p->s->tz;
422 if(p->pos + 8 > p->eop)
425 vl = (uvlong)gl32(p);
426 vl |= (uvlong)gl32(p) << 32;
434 gconv(Pkt *p, int conv, char *str, int n)
439 off = gl32(p) & 0xffff;
440 if(off == 0 || p->tdata - conv + off > p->eop){
446 p->pos = p->tdata - conv + off;
452 goff(Pkt *p, uchar *base, char *str, int n)
458 if(off == 0 || base + off > p->eop){