4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 2001 by Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <port_before.h>
25 #include <port_after.h>
27 static const char hex
[17] = "0123456789abcdef";
30 isc_gethexstring(unsigned char *buf
, size_t len
, int count
, FILE *fp
,
38 x
= 0; /*%< silence compiler */
44 (c
== '\n' && !*multiline
) ||
45 (c
== '(' && *multiline
) ||
46 (c
== ')' && !*multiline
))
52 } while (c
!= EOF
&& c
!= '\n');
53 if (c
== '\n' && *multiline
)
58 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r')
61 if ('(' == c
|| c
== ')') {
62 *multiline
= (c
== '(' /*)*/);
65 if ((s
= strchr(hex
, tolower(c
))) == NULL
)
67 x
= (x
<<4) | (s
- hex
);
87 isc_puthexstring(FILE *fp
, const unsigned char *buf
, size_t buflen
,
88 size_t len1
, size_t len2
, const char *sep
)
97 fputc(hex
[(buf
[0]>>4)&0xf], fp
);
98 fputc(hex
[buf
[0]&0xf], fp
);
102 if (i
>= len1
&& sep
!= NULL
) {
111 isc_tohex(const unsigned char *buf
, size_t buflen
, char *t
) {
112 while (buflen
> 0U) {
113 *t
++ = hex
[(buf
[0]>>4)&0xf];
114 *t
++ = hex
[buf
[0]&0xf];