]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - omapip/convert.c
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-2022 Internet Systems Consortium, Inc. ("ISC")
8 * Copyright (c) 1996-2003 by Internet Software Consortium
10 * This Source Code Form is subject to the terms of the Mozilla Public
11 * License, v. 2.0. If a copy of the MPL was not distributed with this
12 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
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 * Newmarket, NH 03857 USA
26 * https://www.isc.org/
32 #include <omapip/omapip_p.h>
34 u_int32_t
getULong (buf
)
35 const unsigned char *buf
;
39 memcpy (&ibuf
, buf
, sizeof (u_int32_t
));
44 const unsigned char *buf
;
48 memcpy (&ibuf
, buf
, sizeof (int32_t));
52 u_int32_t
getUShort (buf
)
53 const unsigned char *buf
;
57 memcpy (&ibuf
, buf
, sizeof (u_int16_t
));
61 int32_t getShort (buf
)
62 const unsigned char *buf
;
66 memcpy (&ibuf
, buf
, sizeof (int16_t));
70 void putULong (obuf
, val
)
74 u_int32_t tmp
= htonl (val
);
75 memcpy (obuf
, &tmp
, sizeof tmp
);
78 void putLong (obuf
, val
)
82 int32_t tmp
= htonl (val
);
83 memcpy (obuf
, &tmp
, sizeof tmp
);
86 void putUShort (obuf
, val
)
90 u_int16_t tmp
= htons (val
);
91 memcpy (obuf
, &tmp
, sizeof tmp
);
94 void putShort (obuf
, val
)
98 int16_t tmp
= htons (val
);
99 memcpy (obuf
, &tmp
, sizeof tmp
);
102 void putUChar (obuf
, val
)
109 u_int32_t
getUChar (obuf
)
110 const unsigned char *obuf
;
115 int converted_length (buf
, base
, width
)
116 const unsigned char *buf
;
123 u_int32_t newcolumn
= base
;
129 number
= getUChar (buf
);
131 number
= getUShort (buf
);
133 number
= getULong (buf
);
143 newcolumn
= column
* base
;
144 /* If we wrap around, it must be the next power of two up. */
145 } while (newcolumn
> column
);
150 int binary_to_ascii (outbuf
, inbuf
, base
, width
)
151 unsigned char *outbuf
;
152 const unsigned char *inbuf
;
157 static char h2a
[] = "0123456789abcdef";
158 int power
= converted_length (inbuf
, base
, width
);
165 number
= getUChar (inbuf
);
167 number
= getUShort (inbuf
);
169 number
= getULong (inbuf
);
173 for (i
= power
- 1 ; i
>= 0; i
--) {
174 outbuf
[i
] = h2a
[number
% base
];