3 * - complex test harness, recording routines
6 * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 static struct timeval begin
;
33 void Q_str(const char *str
) {
35 if (fprintf(Toutputfile
," %s\n",str
) == EOF
) Toutputerr();
36 if (fflush(Toutputfile
)) Toutputerr();
40 if (!adns__vbuf_append(&vb
,"",1)) Tnomem();
44 static void Rvb(void) {
48 static void Rf(const char *fmt
, ...) PRINTFFORMAT(1,2);
49 static void Rf(const char *fmt
, ...) {
58 static void Rerrno(const char *call
) {
68 int Hgettimeofday(struct timeval
*tv
, struct timezone
*tz
) {
72 assert(tv
); assert(!tz
);
76 r
= gettimeofday(tv
,0); if (r
) Tfailed("gettimeofday");
80 Tvbf("gettimeofday= %ld.%06ld",tv
->tv_sec
,tv
->tv_usec
);
84 diff
.tv_sec
= tv
->tv_sec
- begin
.tv_sec
;
85 diff
.tv_usec
= tv
->tv_usec
- begin
.tv_usec
;
86 if (diff
.tv_usec
< 0) {
88 diff
.tv_usec
+= 1000000;
90 assert(diff
.tv_sec
>= 0);
91 assert(diff
.tv_usec
>= 0);
92 Tvbf("gettimeofday= +%ld.%06ld",diff
.tv_sec
,diff
.tv_usec
);
99 int Hselect(int n
, fd_set
*rfds
, fd_set
*wfds
, fd_set
*efds
, struct timeval
*to
) {
102 Qselect(n
,rfds
,wfds
,efds
,to
);
104 r
= select(n
,rfds
,wfds
,efds
,to
);
110 Tvbf("select= %d",r
);
117 if (to
) memset(to
,0x5a,sizeof(*to
));
122 int Hsocket(int domain
, int type
, int protocol
) {
125 assert(domain
== AF_INET
);
128 r
= socket(domain
,type
,protocol
); if (r
==-1) Tfailed("socket");
134 int Hfcntl(int fd
, int cmd
, ...) {
139 if (cmd
== F_SETFL
) {
141 arg
= va_arg(al
,long);
143 Qfcntl_setfl(fd
,cmd
,arg
);
144 r
= fcntl(fd
, cmd
, arg
);
146 Qfcntl_other(fd
,cmd
);
150 if (r
==-1) Tfailed("fcntl");
155 int Hconnect(int fd
, struct sockaddr
*addr
, int addrlen
) {
158 Qconnect(fd
,addr
,addrlen
);
160 r
= connect(fd
, addr
, addrlen
);
175 int Hsendto(int fd
, const void *msg
, int msglen
, unsigned int flags
,
176 const struct sockaddr
*addr
, int addrlen
) {
180 Qsendto(fd
,msg
,msglen
,addr
,addrlen
);
182 r
= sendto(fd
,msg
,msglen
,flags
,addr
,addrlen
);
191 int Hrecvfrom(int fd
, void *buf
, int buflen
, unsigned int flags
,
192 struct sockaddr
*addr
, int *addrlen
) {
196 Qrecvfrom(fd
,buflen
,*addrlen
);
198 r
= recvfrom(fd
,buf
,buflen
,flags
,addr
,addrlen
);
203 Tvbf("recvfrom= %d",r
);
204 Tvbaddr(addr
,*addrlen
);
212 int Hread(int fd
, void *buf
, size_t len
) {
230 int Hwrite(int fd
, const void *buf
, size_t len
) {
235 r
= write(fd
,buf
,len
);