3 Safe copying of option values into and out of the option buffer, which
4 can't be assumed to be aligned. */
7 * Copyright (c) 2004,2007,2009 by Internet Systems Consortium, Inc. ("ISC")
8 * Copyright (c) 1996-2003 by Internet Software Consortium
10 * Permission to use, copy, modify, and distribute this software for any
11 * purpose with or without fee is hereby granted, provided that the above
12 * copyright notice and this permission notice appear in all copies.
14 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
20 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 * Internet Systems Consortium, Inc.
24 * Redwood City, CA 94063
26 * https://www.isc.org/
28 * This software has been written for Internet Systems Consortium
29 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
30 * To learn more about Internet Systems Consortium, see
31 * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
32 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
33 * ``http://www.nominum.com''.
38 #include <omapip/omapip_p.h>
40 u_int32_t getULong (buf)
41 const unsigned char *buf;
45 memcpy (&ibuf, buf, sizeof (u_int32_t));
50 const unsigned char *buf;
54 memcpy (&ibuf, buf, sizeof (int32_t));
58 u_int32_t getUShort (buf)
59 const unsigned char *buf;
63 memcpy (&ibuf, buf, sizeof (u_int16_t));
67 int32_t getShort (buf)
68 const unsigned char *buf;
72 memcpy (&ibuf, buf, sizeof (int16_t));
76 void putULong (obuf, val)
80 u_int32_t tmp = htonl (val);
81 memcpy (obuf, &tmp, sizeof tmp);
84 void putLong (obuf, val)
88 int32_t tmp = htonl (val);
89 memcpy (obuf, &tmp, sizeof tmp);
92 void putUShort (obuf, val)
96 u_int16_t tmp = htons (val);
97 memcpy (obuf, &tmp, sizeof tmp);
100 void putShort (obuf, val)
104 int16_t tmp = htons (val);
105 memcpy (obuf, &tmp, sizeof tmp);
108 void putUChar (obuf, val)
115 u_int32_t getUChar (obuf)
116 const unsigned char *obuf;
121 int converted_length (buf, base, width)
122 const unsigned char *buf;
129 u_int32_t newcolumn = base;
135 number = getUChar (buf);
137 number = getUShort (buf);
139 number = getULong (buf);
149 newcolumn = column * base;
150 /* If we wrap around, it must be the next power of two up. */
151 } while (newcolumn > column);
156 int binary_to_ascii (outbuf, inbuf, base, width)
157 unsigned char *outbuf;
158 const unsigned char *inbuf;
163 static char h2a [] = "0123456789abcdef";
164 int power = converted_length (inbuf, base, width);
171 number = getUChar (inbuf);
173 number = getUShort (inbuf);
175 number = getULong (inbuf);
179 for (i = power - 1 ; i >= 0; i--) {
180 outbuf [i] = h2a [number % base];