1 /* utils.c Shishi self tests utilities.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 #if defined HAVE_DECL_H_ERRNO && !HAVE_DECL_H_ERRNO
42 /* extern int h_errno; */
49 #ifdef HAVE_SYS_TYPES_H
50 #include <sys/types.h>
53 #ifdef HAVE_SYS_SELECT_H
54 #include <sys/select.h>
57 #ifdef HAVE_SYS_SOCKET_H
58 #include <sys/socket.h>
61 #ifdef HAVE_SYS_IOCTL_H
62 #include <sys/ioctl.h>
70 # include <inttypes.h>
77 #if TIME_WITH_SYS_TIME
78 # include <sys/time.h>
82 # include <sys/time.h>
89 # if !STDC_HEADERS && HAVE_MEMORY_H
102 #ifdef HAVE_NETINET_IN_H
103 #include <netinet/in.h>
105 #ifdef HAVE_NETINET_IN6_H
106 #include <netinet/in6.h>
109 const char *program_name
= PACKAGE
;
111 static int verbose
= 0;
112 static int debug
= 0;
113 static int error_count
= 0;
114 static int break_on_error
= 0;
117 fail (const char *format
, ...)
121 va_start (arg_ptr
, format
);
122 vfprintf (stderr
, format
, arg_ptr
);
130 success (const char *format
, ...)
134 va_start (arg_ptr
, format
);
136 vfprintf (stdout
, format
, arg_ptr
);
141 escapeprint (const unsigned char *str
, int len
)
149 for (i
= 0; i
< len
; i
++)
150 if ((str
[i
] >= 'A' && str
[i
] <= 'Z') ||
151 (str
[i
] >= 'a' && str
[i
] <= 'z') ||
152 (str
[i
] >= '0' && str
[i
] <= '9') || str
[i
] == '.')
153 printf ("%c", str
[i
]);
155 printf ("\\x%02x", str
[i
]);
156 printf ("' (length %d bytes)\n", len
);
160 hexprint (const unsigned char *str
, int len
)
168 for (i
= 0; i
< len
; i
++)
170 printf ("%02x ", str
[i
]);
171 if ((i
+ 1) % 8 == 0)
173 if ((i
+ 1) % 16 == 0 && i
+ 1 < len
)
179 binprint (const unsigned char *str
, int len
)
187 for (i
= 0; i
< len
; i
++)
189 printf ("%d%d%d%d%d%d%d%d ",
190 str
[i
] & 0x80 ? 1 : 0,
191 str
[i
] & 0x40 ? 1 : 0,
192 str
[i
] & 0x20 ? 1 : 0,
193 str
[i
] & 0x10 ? 1 : 0,
194 str
[i
] & 0x08 ? 1 : 0,
195 str
[i
] & 0x04 ? 1 : 0,
196 str
[i
] & 0x02 ? 1 : 0, str
[i
] & 0x01 ? 1 : 0);
197 if ((i
+ 1) % 3 == 0)
199 if ((i
+ 1) % 6 == 0 && i
+ 1 < len
)