1 /* $OpenBSD: convert.c,v 1.5 2004/02/07 11:35:59 henning Exp $ */ 2 /* $DragonFly: src/sbin/dhclient/convert.c,v 1.1 2008/08/30 16:07:58 hasso Exp $ */ 3 4 /* 5 * Safe copying of option values into and out of the option buffer, 6 * which can't be assumed to be aligned. 7 */ 8 9 /* 10 * Copyright (c) 1995, 1996 The Internet Software Consortium. 11 * All rights reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. Neither the name of The Internet Software Consortium nor the names 23 * of its contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND 27 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 28 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR 31 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 34 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * This software has been written for the Internet Software Consortium 41 * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie 42 * Enterprises. To learn more about the Internet Software Consortium, 43 * see ``http://www.vix.com/isc''. To learn more about Vixie 44 * Enterprises, see ``http://www.vix.com''. 45 */ 46 47 #include "dhcpd.h" 48 49 u_int32_t 50 getULong(unsigned char *buf) 51 { 52 u_int32_t ibuf; 53 54 memcpy(&ibuf, buf, sizeof(ibuf)); 55 return (ntohl(ibuf)); 56 } 57 58 int32_t 59 getLong(unsigned char *(buf)) 60 { 61 int32_t ibuf; 62 63 memcpy(&ibuf, buf, sizeof(ibuf)); 64 return (ntohl(ibuf)); 65 } 66 67 u_int16_t 68 getUShort(unsigned char *buf) 69 { 70 u_int16_t ibuf; 71 72 memcpy(&ibuf, buf, sizeof(ibuf)); 73 return (ntohs(ibuf)); 74 } 75 76 int16_t 77 getShort(unsigned char *buf) 78 { 79 int16_t ibuf; 80 81 memcpy(&ibuf, buf, sizeof(ibuf)); 82 return (ntohs(ibuf)); 83 } 84 85 void 86 putULong(unsigned char *obuf, u_int32_t val) 87 { 88 u_int32_t tmp = htonl(val); 89 90 memcpy(obuf, &tmp, sizeof(tmp)); 91 } 92 93 void 94 putLong(unsigned char *obuf, int32_t val) 95 { 96 int32_t tmp = htonl(val); 97 98 memcpy(obuf, &tmp, sizeof(tmp)); 99 } 100 101 void 102 putUShort(unsigned char *obuf, unsigned int val) 103 { 104 u_int16_t tmp = htons(val); 105 106 memcpy(obuf, &tmp, sizeof(tmp)); 107 } 108 109 void 110 putShort(unsigned char *obuf, int val) 111 { 112 int16_t tmp = htons(val); 113 114 memcpy(obuf, &tmp, sizeof(tmp)); 115 } 116