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.
26 static struct timeval begin;
28 int Hgettimeofday(struct timeval *tv, struct timezone *tz) {
32 assert(tv); assert(!tz);
36 r= gettimeofday(tv,0); if (r) Tfailed("gettimeofday");
39 printf(" gettimeofday= %ld.%06ld",tv->tv_sec,tv->tv_usec);
43 diff.tv_sec= tv->tv_sec - begin.tv_sec;
44 diff.tv_usec= tv->tv_usec - begin.tv_usec;
45 if (diff.tv_usec < 0) {
47 diff.tv_usec += 1000000;
49 assert(diff.tv_sec >= 0);
50 assert(diff.tv_usec >= 0);
51 Tprintf(" gettimeofday= +%ld.%06ld\n",diff.tv_sec,diff.tv_usec);
56 int Hselect(int n, fd_set reads, fd_set writes, fd_set excepts, struct timeval *to) {
57 Qselect(n,reads,writes,excepts,to);
59 r= select(n,reads,writes,excepts,to);
64 Tprintf(" select= %d",r);
65 Tfdset(reads); Tfdset(writes); Tfdset(excepts);
69 if (to) memset(to,0x5a,sizeof(*to));
72 int Hsocket(int domain, int type, int protocol) {
73 assert(domain == AF_INET);
76 r= socket(domain,type,protocol); if (r) Tfailed("socket");
78 Tprintf(" socket= %d\n",r);
82 int Hfcntl(int fd, int cmd, long arg) {
85 r= fcntl(fd, cmd, arg); if (r==-1) Tfailed("fcntl");
87 Tprintf(" fcntl= %d\n",r);
91 int Hconnect(int fd, struct sockaddr *addr, int addrlen) {
92 Qconnect(fd,addr,addrlen);
94 r= connect(fd, addr, addrlen);
99 Tprintf(" connect= OK\n");
109 int Hsendto(int fd, const void *msg, int msglen, unsigned int flags,
110 const struct sockaddr *addr, int addrlen) {
112 Qsendto(fd,msg,msglen,addr,addrlen);
114 r= sendto(fd,msg,msglen,flags,addr,addrlen);
118 Tprintf(" sendto= %d\n",r);
123 int Hrecvfrom(int fd, void *buf, int buflen, unsigned int flags,
124 struct sockaddr *addr, int *addrlen) {
126 Qrecvfrom(fd,buflen,addr,*addrlen);
128 r= recvfrom(fd,buf,buflen,flags,addr,addrlen);
132 Tprintf(" recvfrom=",r);
141 int Hread(int fd, void *buf, size_t len) {
156 int Hwrite(int fd, const void *buf, size_t len) {
159 r= write(fd,buf,len);
163 Tprintf(" write= %d\n",r);