2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 2001 by Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <port_before.h>
23 #include <port_after.h>
25 static const char hex
[17] = "0123456789abcdef";
28 isc_gethexstring(unsigned char *buf
, size_t len
, int count
, FILE *fp
,
36 x
= 0; /*%< silence compiler */
42 (c
== '\n' && !*multiline
) ||
43 (c
== '(' && *multiline
) ||
44 (c
== ')' && !*multiline
))
50 } while (c
!= EOF
&& c
!= '\n');
51 if (c
== '\n' && *multiline
)
56 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r')
59 if ('(' == c
|| c
== ')') {
60 *multiline
= (c
== '(' /*)*/);
63 if ((s
= strchr(hex
, tolower(c
))) == NULL
)
65 x
= (x
<<4) | (s
- hex
);
85 isc_puthexstring(FILE *fp
, const unsigned char *buf
, size_t buflen
,
86 size_t len1
, size_t len2
, const char *sep
)
95 fputc(hex
[(buf
[0]>>4)&0xf], fp
);
96 fputc(hex
[buf
[0]&0xf], fp
);
100 if (i
>= len1
&& sep
!= NULL
) {
109 isc_tohex(const unsigned char *buf
, size_t buflen
, char *t
) {
110 while (buflen
> 0U) {
111 *t
++ = hex
[(buf
[0]>>4)&0xf];
112 *t
++ = hex
[buf
[0]&0xf];