summaryrefslogtreecommitdiff
path: root/regress/hplayback.c
blob: 279934c63e05c9319bb9bef64b8fff39946b04e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include "harness.h"
static FILE *Tinputfile, *Treportfile;
static vbuf vb2;
extern void Tshutdown(void) {
  adns__vbuf_free(&vb2);
}
static void Tensurereportfile(void) {
  const char *fdstr;
  int fd;
  if (Treportfile) return;
  Treportfile= stderr;
  fdstr= getenv("ADNS_TEST_REPORT_FD"); if (!fdstr) return;
  fd= atoi(fdstr);
  Treportfile= fdopen(fd,"a"); if (!Treportfile) Tfailed("fdopen ADNS_TEST_REPORT_FD");
}
static void Psyntax(const char *where) {
  fprintf(stderr,"adns test harness: syntax error in test log input file: %s\n",where);
  exit(-1);
}
static void Pcheckinput(void) {
  if (ferror(Tinputfile)) Tfailed("read test log input file");
  if (feof(Tinputfile)) Psyntax("eof at syscall reply");
}
void Tensurerecordfile(void) {
  const char *fdstr;
  int fd;
  int chars;
  unsigned long sec, usec;
  if (Tinputfile) return;
  Tinputfile= stdin;
  fdstr= getenv("ADNS_TEST_IN_FD");
  if (fdstr) {
    fd= atoi(fdstr);
    Tinputfile= fdopen(fd,"r"); if (!Tinputfile) Tfailed("fdopen ADNS_TEST_IN_FD");
  }
  setvbuf(Tinputfile,0,_IONBF,0);
  if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
  fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
  chars= -1;
  sscanf(vb2.buf," start %lu.%lu%n",&sec,&usec,&chars);
  if (chars==-1) Psyntax("start time invalid");
  currenttime.tv_sec= sec;
  currenttime.tv_usec= usec;
  if (vb2.buf[chars] != '\n') Psyntax("not newline after start time");
}
static void Parg(const char *argname) {
  int l;
  if (vb2.buf[vb2.used++] != ' ') Psyntax("not a space before argument");
  l= strlen(argname);
  if (memcmp(vb2.buf+vb2.used,argname,l)) Psyntax("argument name wrong");
  vb2.used+= l;
  if (vb2.buf[vb2.used++] != '=') Psyntax("not = after argument name");
}
static int Pstring_maybe(const char *string) {
  int l;
  l= strlen(string);
  if (memcmp(vb2.buf+vb2.used,string,l)) return 0;
  vb2.used+= l;
  return 1;
}
static void Pstring(const char *string, const char *emsg) {
  if (Pstring_maybe(string)) return;
  Psyntax(emsg);
}
static int Perrno(const char *stuff) {
  const struct Terrno *te;
  int r;
  char *ep;
  for (te= Terrnos; te->n && strcmp(te->n,stuff); te++);
  if (te->n) return te->v;
  r= strtoul(stuff+2,&ep,10);
  if (*ep) Psyntax("errno value not recognised, not numeric");
  return r;
}
static void P_updatetime(void) {
  int chars;
  unsigned long sec, usec;
  if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
  fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
  chars= -1;
  sscanf(vb2.buf," +%lu.%lu%n",&sec,&usec,&chars);
  if (chars==-1) Psyntax("update time invalid");
  currenttime.tv_sec+= sec;
  currenttime.tv_usec+= usec;
  if (currenttime.tv_usec > 1000000) {
    currenttime.tv_sec++;
    currenttime.tv_usec -= 1000000;
  }
  if (vb2.buf[chars] != '\n') Psyntax("not newline after update time");
}
static void Pfdset(fd_set *set, int max) {
  int r, c;
  char *ep;
  if (vb2.buf[vb2.used++] != '[') Psyntax("fd set start not [");
  FD_ZERO(set);
  if (vb2.buf[vb2.used] == ']') { vb2.used++; return; }
  for (;;) {
    r= strtoul(vb2.buf+vb2.used,&ep,10);
    if (r>=max) Psyntax("fd set member > max");
    if (ep == (char*)vb2.buf+vb2.used) Psyntax("empty entry in fd set");
    FD_SET(r,set);
    vb2.used= ep - (char*)vb2.buf;
    c= vb2.buf[vb2.used++];
    if (c == ']') break;
    if (c != ',') Psyntax("fd set separator not ,");
  }
}
#ifdef HAVE_POLL
static int Ppollfdevents(void) {
  int events;
  if (Pstring_maybe("0")) return 0;
  events= 0;
  if (Pstring_maybe("POLLIN")) {
    events |= POLLIN;
    if (!Pstring_maybe("|")) return events;
  }
  if (Pstring_maybe("POLLOUT")) {
    events |= POLLOUT;
    if (!Pstring_maybe("|")) return events;
  }
  Pstring("POLLPRI","pollfdevents PRI?");
  return events;
}
static void Ppollfds(struct pollfd *fds, int nfds) {
  int i;
  char *ep;
  const char *comma= "";
  if (vb2.buf[vb2.used++] != '[') Psyntax("pollfds start not [");
  for (i=0; i<nfds; i++) {
    Pstring("{fd=","{fd= in pollfds");
    fds->fd= strtoul(vb2.buf+vb2.used,&ep,10);
    vb2.used= ep - (char*)vb2.buf;    
    Pstring(", events=",", events= in pollfds");
    fds->events= Ppollfdevents();
    Pstring(", revents=",", revents= in pollfds");
    fds->revents= Ppollfdevents();
    Pstring("}","} in pollfds");
    Pstring(comma,"separator in pollfds");
    comma= ", ";
  }
  if (vb2.buf[vb2.used++] != ']') Psyntax("pollfds end not ]");
}
#endif
static void Paddr(struct sockaddr *addr, int *lenr) {
  adns_rr_addr a;
  char *p, *q, *ep;
  int err;
  unsigned long ul;
  p= vb2.buf+vb2.used;
  if (*p!='[') {
    q= strchr(p,':');
    if (!q) Psyntax("missing :");
    *q++= 0;
  } else {
    p++;
    q= strchr(p,']');
    if (!q) Psyntax("missing ]");
    *q++= 0;
    if (*q!=':') Psyntax("expected : after ]");
    q++;
  }
  ul= strtoul(q,&ep,10);
  if (*ep && *ep != ' ') Psyntax("invalid port (bad syntax)");
  if (ul >= 65536) Psyntax("port too large");
  a.len= sizeof(a.addr);
  err= adns_text2addr(p, (int)ul, 0, &a.addr.sa,&a.len);
  if (err) Psyntax("invalid address");
  assert(*lenr >= a.len);
  memcpy(addr, &a.addr, a.len);
  *lenr= a.len;
  vb2.used= ep - (char*)vb2.buf;
}
static int Pbytes(byte *buf, int maxlen) {
  static const char hexdigits[]= "0123456789abcdef";
  int c, v, done;
  const char *pf;
  done= 0;
  for (;;) {
    c= getc(Tinputfile); Pcheckinput();
    if (c=='\n' || c==' ' || c=='\t') continue;
    if (c=='.') break;
    pf= strchr(hexdigits,c); if (!pf) Psyntax("invalid first hex digit");
    v= (pf-hexdigits)<<4;
    c= getc(Tinputfile); Pcheckinput();
    pf= strchr(hexdigits,c); if (!pf) Psyntax("invalid second hex digit");
    v |= (pf-hexdigits);
    if (maxlen<=0) Psyntax("buffer overflow in bytes");
    *buf++= v;
    maxlen--; done++;
  }
  for (;;) {
    c= getc(Tinputfile); Pcheckinput();
    if (c=='\n') return done;
  }
}
void Q_vb(void) {
  const char *nl;
  Tensurerecordfile();
  if (!adns__vbuf_ensure(&vb2,vb.used+2)) Tnomem();
  fread(vb2.buf,1,vb.used+2,Tinputfile);
  if (feof(Tinputfile)) {
    fprintf(stderr,"adns test harness: input ends prematurely; program did:\n %.*s\n",
           vb.used,vb.buf);
    exit(-1);
  }
  Pcheckinput();
  if (vb2.buf[0] != ' ') Psyntax("not space before call");
  if (memcmp(vb.buf,vb2.buf+1,vb.used) ||
      vb2.buf[vb.used+1] != '\n') {
    fprintf(stderr,
            "adns test harness: program did unexpected:\n %.*s\n"
            "was expecting:\n %.*s\n",
            vb.used,vb.buf, vb.used,vb2.buf+1);
    exit(1);
  }
  Tensurereportfile();
  nl= memchr(vb.buf,'\n',vb.used);
  fprintf(Treportfile," %.*s\n", (int)(nl ? nl - (const char*)vb.buf : vb.used), vb.buf);
}
int Hselect(	int max , fd_set *rfds , fd_set *wfds , fd_set *efds , struct timeval *to 	) {
 int r, amtread;
 char *ep;
 Qselect(	max , rfds , wfds , efds , to 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," select=",8)) Psyntax("syscall reply mismatch");
 if (vb2.buf[8] == 'E') {
  int e;
  e= Perrno(vb2.buf+8);
  P_updatetime();
  errno= e;
  return -1;
 }
  r= strtoul(vb2.buf+8,&ep,10);
  if (*ep && *ep!=' ') Psyntax("return value not E* or positive number");
  vb2.used= ep - (char*)vb2.buf;
	Parg("rfds"); Pfdset(rfds,max); 
	Parg("wfds"); Pfdset(wfds,max); 
	Parg("efds"); Pfdset(efds,max); 
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}
#ifdef HAVE_POLL
int Hpoll(	struct pollfd *fds , int nfds , int timeout 	) {
 int r, amtread;
 char *ep;
 Qpoll(	fds , nfds , timeout 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," poll=",6)) Psyntax("syscall reply mismatch");
 if (vb2.buf[6] == 'E') {
  int e;
  e= Perrno(vb2.buf+6);
  P_updatetime();
  errno= e;
  return -1;
 }
  r= strtoul(vb2.buf+6,&ep,10);
  if (*ep && *ep!=' ') Psyntax("return value not E* or positive number");
  vb2.used= ep - (char*)vb2.buf;
        Parg("fds"); Ppollfds(fds,nfds); 
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}
#endif
int Hsocket(	int domain , int type , int protocol 	) {
 int r, amtread;
 char *ep;
  Tmust("socket","domain",domain==AF_INET || domain==AF_INET6); 
  Tmust("socket","type",type==SOCK_STREAM || type==SOCK_DGRAM); 
 Qsocket(	domain , type 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," socket=",8)) Psyntax("syscall reply mismatch");
 if (vb2.buf[8] == 'E') {
  int e;
  e= Perrno(vb2.buf+8);
  P_updatetime();
  errno= e;
  return -1;
 }
  r= strtoul(vb2.buf+8,&ep,10);
  if (*ep && *ep!=' ') Psyntax("return value not E* or positive number");
  vb2.used= ep - (char*)vb2.buf;
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}
int Hfcntl(	int fd , int cmd , ... 	) {
 int r, amtread;
	va_list al; long arg; 
  Tmust("fcntl","cmd",cmd==F_SETFL || cmd==F_GETFL);
  if (cmd == F_SETFL) {
    va_start(al,cmd); arg= va_arg(al,long); va_end(al);
  } else {
    arg= 0;
  } 
 Qfcntl(	fd , cmd , arg 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," fcntl=",7)) Psyntax("syscall reply mismatch");
 if (vb2.buf[7] == 'E') {
  int e;
  e= Perrno(vb2.buf+7);
  P_updatetime();
  errno= e;
  return -1;
 }
  r= 0;
  if (cmd == F_GETFL) {
    if (!memcmp(vb2.buf+7,"O_NONBLOCK|...",14)) {
      r= O_NONBLOCK;
      vb2.used= 7+14;
    } else if (!memcmp(vb2.buf+7,"~O_NONBLOCK&...",15)) {
      vb2.used= 7+15;
    } else {
      Psyntax("fcntl flags not O_NONBLOCK|... or ~O_NONBLOCK&...");
    }
  } else if (cmd == F_SETFL) {
  if (memcmp(vb2.buf+7,"OK",2)) Psyntax("success/fail not E* or OK");
  vb2.used= 7+2;
  r= 0;
  } else {
    Psyntax("fcntl not F_GETFL or F_SETFL");
  }
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}
int Hconnect(	int fd , const struct sockaddr *addr , int addrlen 	) {
 int r, amtread;
 Qconnect(	fd , addr , addrlen 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," connect=",9)) Psyntax("syscall reply mismatch");
 if (vb2.buf[9] == 'E') {
  int e;
  e= Perrno(vb2.buf+9);
  P_updatetime();
  errno= e;
  return -1;
 }
  if (memcmp(vb2.buf+9,"OK",2)) Psyntax("success/fail not E* or OK");
  vb2.used= 9+2;
  r= 0;
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}
int Hbind(	int fd , const struct sockaddr *addr , int addrlen 	) {
 int r, amtread;
 Qbind(	fd , addr , addrlen 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," bind=",6)) Psyntax("syscall reply mismatch");
 if (vb2.buf[6] == 'E') {
  int e;
  e= Perrno(vb2.buf+6);
  P_updatetime();
  errno= e;
  return -1;
 }
  if (memcmp(vb2.buf+6,"OK",2)) Psyntax("success/fail not E* or OK");
  vb2.used= 6+2;
  r= 0;
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}
int Hlisten(	int fd , int backlog 	) {
 int r, amtread;
 Qlisten(	fd , backlog 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," listen=",8)) Psyntax("syscall reply mismatch");
 if (vb2.buf[8] == 'E') {
  int e;
  e= Perrno(vb2.buf+8);
  P_updatetime();
  errno= e;
  return -1;
 }
  if (memcmp(vb2.buf+8,"OK",2)) Psyntax("success/fail not E* or OK");
  vb2.used= 8+2;
  r= 0;
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}
int Hclose(	int fd 	) {
 int r, amtread;
 Qclose(	fd 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," close=",7)) Psyntax("syscall reply mismatch");
 if (vb2.buf[7] == 'E') {
  int e;
  e= Perrno(vb2.buf+7);
  P_updatetime();
  errno= e;
  return -1;
 }
  if (memcmp(vb2.buf+7,"OK",2)) Psyntax("success/fail not E* or OK");
  vb2.used= 7+2;
  r= 0;
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}
int Hsendto(	int fd , const void *msg , int msglen , unsigned int flags , const struct sockaddr *addr , int addrlen 	) {
 int r, amtread;
 char *ep;
	Tmust("sendto","flags",flags==0); 
 Qsendto(	fd , msg , msglen , addr , addrlen 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," sendto=",8)) Psyntax("syscall reply mismatch");
 if (vb2.buf[8] == 'E') {
  int e;
  e= Perrno(vb2.buf+8);
  P_updatetime();
  errno= e;
  return -1;
 }
  r= strtoul(vb2.buf+8,&ep,10);
  if (*ep && *ep!=' ') Psyntax("return value not E* or positive number");
  vb2.used= ep - (char*)vb2.buf;
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}
int Hrecvfrom(	int fd , void *buf , int buflen , unsigned int flags , struct sockaddr *addr , int *addrlen 	) {
 int r, amtread;
	Tmust("recvfrom","flags",flags==0); 
	Tmust("recvfrom","*addrlen",*addrlen>=sizeof(struct sockaddr_in)); 
 Qrecvfrom(	fd , buflen , *addrlen 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," recvfrom=",10)) Psyntax("syscall reply mismatch");
 if (vb2.buf[10] == 'E') {
  int e;
  e= Perrno(vb2.buf+10);
  P_updatetime();
  errno= e;
  return -1;
 }
  if (memcmp(vb2.buf+10,"OK",2)) Psyntax("success/fail not E* or OK");
  vb2.used= 10+2;
  r= 0;
	Parg("addr"); Paddr(addr,addrlen); 
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
	r= Pbytes(buf,buflen); 
 P_updatetime();
 return r;
}
int Hread(	int fd , void *buf , size_t buflen 	) {
 int r, amtread;
 Qread(	fd , buflen 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," read=",6)) Psyntax("syscall reply mismatch");
 if (vb2.buf[6] == 'E') {
  int e;
  e= Perrno(vb2.buf+6);
  P_updatetime();
  errno= e;
  return -1;
 }
  if (memcmp(vb2.buf+6,"OK",2)) Psyntax("success/fail not E* or OK");
  vb2.used= 6+2;
  r= 0;
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
	r= Pbytes(buf,buflen); 
 P_updatetime();
 return r;
}
int Hwrite(	int fd , const void *buf , size_t len 	) {
 int r, amtread;
 char *ep;
 Qwrite(	fd , buf , len 	);
 if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
 fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 Tensurereportfile();
 fprintf(Treportfile,"%s",vb2.buf);
 amtread= strlen(vb2.buf);
 if (amtread<=0 || vb2.buf[--amtread]!='\n')
  Psyntax("badly formed line");
 vb2.buf[amtread]= 0;
 if (memcmp(vb2.buf," write=",7)) Psyntax("syscall reply mismatch");
 if (vb2.buf[7] == 'E') {
  int e;
  e= Perrno(vb2.buf+7);
  P_updatetime();
  errno= e;
  return -1;
 }
  r= strtoul(vb2.buf+7,&ep,10);
  if (*ep && *ep!=' ') Psyntax("return value not E* or positive number");
  vb2.used= ep - (char*)vb2.buf;
 assert(vb2.used <= amtread);
 if (vb2.used != amtread) Psyntax("junk at end of line");
 P_updatetime();
 return r;
}