1 /* utils.c Shishi self tests utilities.
2 * Copyright (C) 2002, 2003, 2004, 2006 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
31 #include <sys/types.h>
32 #include <sys/select.h>
33 #include <sys/socket.h>
41 #if defined HAVE_DECL_H_ERRNO && !HAVE_DECL_H_ERRNO
42 /* extern int h_errno; */
49 #ifdef HAVE_SYS_IOCTL_H
50 #include <sys/ioctl.h>
57 #if TIME_WITH_SYS_TIME
58 # include <sys/time.h>
62 # include <sys/time.h>
72 #ifdef HAVE_NETINET_IN_H
73 #include <netinet/in.h>
75 #ifdef HAVE_NETINET_IN6_H
76 #include <netinet/in6.h>
83 const char *program_name
= PACKAGE
;
85 static int verbose
= 0;
87 static int error_count
= 0;
88 static int break_on_error
= 0;
91 fail (const char *format
, ...)
95 va_start (arg_ptr
, format
);
96 vfprintf (stderr
, format
, arg_ptr
);
104 success (const char *format
, ...)
108 va_start (arg_ptr
, format
);
110 vfprintf (stdout
, format
, arg_ptr
);
115 escapeprint (const char *str
, int len
)
123 for (i
= 0; i
< len
; i
++)
124 if ((str
[i
] >= 'A' && str
[i
] <= 'Z') ||
125 (str
[i
] >= 'a' && str
[i
] <= 'z') ||
126 (str
[i
] >= '0' && str
[i
] <= '9') || str
[i
] == '.')
127 printf ("%c", str
[i
]);
129 printf ("\\x%02x", str
[i
]);
130 printf ("' (length %d bytes)\n", len
);
134 hexprint (const char *str
, int len
)
142 for (i
= 0; i
< len
; i
++)
144 printf ("%02x ", str
[i
]);
145 if ((i
+ 1) % 8 == 0)
147 if ((i
+ 1) % 16 == 0 && i
+ 1 < len
)
154 binprint (const char *str
, int len
)
162 for (i
= 0; i
< len
; i
++)
164 printf ("%d%d%d%d%d%d%d%d ",
165 str
[i
] & 0x80 ? 1 : 0,
166 str
[i
] & 0x40 ? 1 : 0,
167 str
[i
] & 0x20 ? 1 : 0,
168 str
[i
] & 0x10 ? 1 : 0,
169 str
[i
] & 0x08 ? 1 : 0,
170 str
[i
] & 0x04 ? 1 : 0,
171 str
[i
] & 0x02 ? 1 : 0, str
[i
] & 0x01 ? 1 : 0);
172 if ((i
+ 1) % 3 == 0)
174 if ((i
+ 1) % 6 == 0 && i
+ 1 < len
)
180 void test (Shishi
* handle
);
183 main (int argc
, char *argv
[])
188 if (strcmp (argv
[argc
- 1], "-v") == 0 ||
189 strcmp (argv
[argc
- 1], "--verbose") == 0)
191 else if (strcmp (argv
[argc
- 1], "-d") == 0 ||
192 strcmp (argv
[argc
- 1], "--debug") == 0)
194 else if (strcmp (argv
[argc
- 1], "-b") == 0 ||
195 strcmp (argv
[argc
- 1], "--break-on-error") == 0)
197 else if (strcmp (argv
[argc
- 1], "-h") == 0 ||
198 strcmp (argv
[argc
- 1], "-?") == 0 ||
199 strcmp (argv
[argc
- 1], "--help") == 0)
201 printf ("Usage: %s [-vdbh?] [--verbose] [--debug] "
202 "[--break-on-error] [--help]\n", argv
[0]);
210 fail ("Could not initialize shishi\n");
216 shishi_cfg (handle
, strdup ("verbose"));
217 shishi_cfg (handle
, strdup ("verbose-noise"));
218 shishi_cfg (handle
, strdup ("verbose-asn1"));
219 shishi_cfg (handle
, strdup ("verbose-crypto"));
220 shishi_cfg (handle
, strdup ("verbose-crypto-noise"));
225 shishi_done (handle
);
228 printf ("Self test `%s' done with %d errors\n", argv
[0], error_count
);
230 return error_count
? 1 : 0;