/* $OpenBSD: convert.c,v 1.5 2004/02/07 11:35:59 henning Exp $ */12/*3* Safe copying of option values into and out of the option buffer,4* which can't be assumed to be aligned.5*/67/*-8* SPDX-License-Identifier: BSD-3-Clause9*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 without14* modification, are permitted provided that the following conditions15* are met:16*17* 1. Redistributions of source code must retain the above copyright18* notice, this list of conditions and the following disclaimer.19* 2. Redistributions in binary form must reproduce the above copyright20* notice, this list of conditions and the following disclaimer in the21* documentation and/or other materials provided with the distribution.22* 3. Neither the name of The Internet Software Consortium nor the names23* of its contributors may be used to endorse or promote products derived24* from this software without specific prior written permission.25*26* THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND27* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,28* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF29* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE30* DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR31* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,32* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT33* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF34* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND35* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,36* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT37* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF38* SUCH DAMAGE.39*40* This software has been written for the Internet Software Consortium41* by Ted Lemon <[email protected]> in cooperation with Vixie42* Enterprises. To learn more about the Internet Software Consortium,43* see ``http://www.vix.com/isc''. To learn more about Vixie44* Enterprises, see ``http://www.vix.com''.45*/4647#include <sys/cdefs.h>48#include "dhcpd.h"4950u_int32_t51getULong(unsigned char *buf)52{53u_int32_t ibuf;5455memcpy(&ibuf, buf, sizeof(ibuf));56return (ntohl(ibuf));57}5859int32_t60getLong(unsigned char *(buf))61{62int32_t ibuf;6364memcpy(&ibuf, buf, sizeof(ibuf));65return (ntohl(ibuf));66}6768u_int16_t69getUShort(unsigned char *buf)70{71u_int16_t ibuf;7273memcpy(&ibuf, buf, sizeof(ibuf));74return (ntohs(ibuf));75}7677int16_t78getShort(unsigned char *buf)79{80int16_t ibuf;8182memcpy(&ibuf, buf, sizeof(ibuf));83return (ntohs(ibuf));84}8586void87putULong(unsigned char *obuf, u_int32_t val)88{89u_int32_t tmp = htonl(val);9091memcpy(obuf, &tmp, sizeof(tmp));92}9394void95putLong(unsigned char *obuf, int32_t val)96{97int32_t tmp = htonl(val);9899memcpy(obuf, &tmp, sizeof(tmp));100}101102void103putUShort(unsigned char *obuf, unsigned int val)104{105u_int16_t tmp = htons(val);106107memcpy(obuf, &tmp, sizeof(tmp));108}109110void111putShort(unsigned char *obuf, int val)112{113int16_t tmp = htons(val);114115memcpy(obuf, &tmp, sizeof(tmp));116}117118119