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);
36 sysfatal("ppath: %C/%x utf too wide for windows\n", r, r);
43 while((c = *str++) != 0){
54 pstr(Pkt *p, char *str)
62 if(p->s->flags2 & FL2_UNICODE){
63 if(((p->pos - p->buf) % 2) != 0)
64 p8(p, 0); /* pad to even offset */
66 str += chartorune(&r, str);
68 sysfatal("pstr: %C/%x utf too wide for windows\n", r, r);
81 pascii(Pkt *p, char *str)
93 pl64(Pkt *p, uvlong n)
162 * Encode a Netbios name
165 pname(Pkt *p, char *name, char pad)
172 for(i = 0; i < 16; i++) {
174 if(!done && name[i] == '\0')
177 c = islower(name[i])? toupper(name[i]): name[i];
178 *p->pos++ = ((uchar)c >> 4) + 'A';
179 *p->pos++ = (c & 0xf) + 'A';
186 pvtime(Pkt *p, uvlong n)
199 pdatetime(Pkt *p, long utc)
202 Tm *tm = localtime(utc);
203 int t = tm->hour << 11 | tm->min << 5 | (tm->sec / 2);
204 int d = (tm->year - 80) << 9 | (tm->mon + 1) << 5 | tm->mday;
207 * bug in word swapping in Win95 requires this
209 if(p->s->caps & CAP_NT_SMBS){
221 gmem(Pkt *p, void *v, int n)
227 while(n-- && p->pos < p->eop)
232 * note len is the length of the source string in
233 * in runes or bytes, in ASCII mode this is also the size
234 * of the output buffer but this is not so in Unicode mode!
237 _gstr(Pkt *p, char *str, int n, int align)
245 if(p->flags2 & FL2_UNICODE){
246 if(((p->pos - p->buf) % 2) != 0){
251 while(*p->pos && n && p->pos < p->eop){
253 i += runetochar(str +i, &r);
257 while(*p->pos && p->pos < p->eop)
260 * some versions of windows terminate a rune string
261 * with a single nul so we do a dangerous hack...
268 while(*p->pos && n-- && p->pos < p->eop)
271 while(*p->pos++ && p->pos < p->eop)
277 gstr(Pkt *p, char *str, int n)
283 gstr_noalign(Pkt *p, char *str, int n)
289 * Because DFS uses a string heap rather than strings embedded in the
290 * data packet, experience (rather than any spec) tells, us we must
291 * turn off the 16bit alignment for unicode strings.
294 goff(Pkt *p, uchar *base, char *str, int n)
300 if(off == 0 || base + off > p->eop){
306 gstr_noalign(p, str, n);
311 gascii(Pkt *p, char *str, int n)
316 while(*p->pos && n-- && p->pos < p->eop)
319 while(*p->pos++ && p->pos < p->eop)
329 if(p->pos + 8 > p->eop)
332 n = (uvlong)*p->pos++;
333 n |= (uvlong)*p->pos++ << 8;
334 n |= (uvlong)*p->pos++ << 16;
335 n |= (uvlong)*p->pos++ << 24;
336 n |= (uvlong)*p->pos++ << 32;
337 n |= (uvlong)*p->pos++ << 40;
338 n |= (uvlong)*p->pos++ << 48;
339 n |= (uvlong)*p->pos++ << 56;
348 if(p->pos + 6 > p->eop)
351 n = (uvlong)*p->pos++ << 40;
352 n |= (uvlong)*p->pos++ << 24;
353 n |= (uvlong)*p->pos++ << 32;
354 n |= (uvlong)*p->pos++ << 16;
355 n |= (uvlong)*p->pos++ << 8;
356 n |= (uvlong)*p->pos++;
365 if(p->pos + 4 > p->eop)
368 n = (uint)*p->pos++ << 24;
369 n |= (uint)*p->pos++ << 16;
370 n |= (uint)*p->pos++ << 8;
371 n |= (uint)*p->pos++;
380 if(p->pos + 4 > p->eop)
384 n |= (uint)*p->pos++ << 8;
385 n |= (uint)*p->pos++ << 16;
386 n |= (uint)*p->pos++ << 24;
395 if(p->pos + 2 > p->eop)
397 n = (uint)*p->pos++ << 8;
398 n |= (uint)*p->pos++;
407 if(p->pos + 2 > p->eop)
410 n |= (uint)*p->pos++ << 8;
417 if(p->pos + 1 > p->eop)
419 return (uint)*p->pos++;
428 if(p->pos + 4 > p->eop)
432 * bug in word swapping in Win95 requires this
434 if(p->s->caps & CAP_NT_SMBS){
442 tm.year = 80 + (d >> 9);
443 tm.mon = ((d >> 5) & 017) - 1;
449 tm.min = (t >> 5) & 63;
450 tm.sec = (t & 31) << 1;
460 if(p->pos + 8 > p->eop)
463 vl = (uvlong)gl32(p);
464 vl |= (uvlong)gl32(p) << 32;
472 gconv(Pkt *p, int conv, char *str, int n)
477 off = gl32(p) & 0xffff;
478 if(off == 0 || p->tdata - conv + off > p->eop){
484 p->pos = p->tdata - conv + off;