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 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
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 * ``http://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''.
37 static char copyright
[] =
38 "$Id$ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
41 #include <omapip/omapip_p.h>
43 u_int32_t
getULong (buf
)
44 const unsigned char *buf
;
48 memcpy (&ibuf
, buf
, sizeof (u_int32_t
));
53 const unsigned char *buf
;
57 memcpy (&ibuf
, buf
, sizeof (int32_t));
61 u_int32_t
getUShort (buf
)
62 const unsigned char *buf
;
66 memcpy (&ibuf
, buf
, sizeof (u_int16_t
));
70 int32_t getShort (buf
)
71 const unsigned char *buf
;
75 memcpy (&ibuf
, buf
, sizeof (int16_t));
79 void putULong (obuf
, val
)
83 u_int32_t tmp
= htonl (val
);
84 memcpy (obuf
, &tmp
, sizeof tmp
);
87 void putLong (obuf
, val
)
91 int32_t tmp
= htonl (val
);
92 memcpy (obuf
, &tmp
, sizeof tmp
);
95 void putUShort (obuf
, val
)
99 u_int16_t tmp
= htons (val
);
100 memcpy (obuf
, &tmp
, sizeof tmp
);
103 void putShort (obuf
, val
)
107 int16_t tmp
= htons (val
);
108 memcpy (obuf
, &tmp
, sizeof tmp
);
111 void putUChar (obuf
, val
)
118 u_int32_t
getUChar (obuf
)
119 const unsigned char *obuf
;
124 int converted_length (buf
, base
, width
)
125 const unsigned char *buf
;
132 u_int32_t newcolumn
= base
;
138 number
= getUChar (buf
);
140 number
= getUShort (buf
);
142 number
= getULong (buf
);
152 newcolumn
= column
* base
;
153 /* If we wrap around, it must be the next power of two up. */
154 } while (newcolumn
> column
);
159 int binary_to_ascii (outbuf
, inbuf
, base
, width
)
160 unsigned char *outbuf
;
161 const unsigned char *inbuf
;
166 static char h2a
[] = "0123456789abcdef";
167 int power
= converted_length (inbuf
, base
, width
);
175 number
= getUChar (inbuf
);
177 number
= getUShort (inbuf
);
179 number
= getULong (inbuf
);
183 for (i
= power
- 1 ; i
>= 0; i
--) {
184 outbuf
[i
] = h2a
[number
% base
];