Annotation of embedaddon/dhcp/common/ethernet.c, revision 1.1
1.1 ! misho 1: /* ethernet.c
! 2:
! 3: Packet assembly code, originally contributed by Archie Cobbs. */
! 4:
! 5: /*
! 6: * Copyright (c) 2004,2007,2009 by Internet Systems Consortium, Inc. ("ISC")
! 7: * Copyright (c) 1996-2003 by Internet Software Consortium
! 8: *
! 9: * Permission to use, copy, modify, and distribute this software for any
! 10: * purpose with or without fee is hereby granted, provided that the above
! 11: * copyright notice and this permission notice appear in all copies.
! 12: *
! 13: * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
! 14: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
! 15: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
! 16: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
! 17: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
! 18: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
! 19: * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
! 20: *
! 21: * Internet Systems Consortium, Inc.
! 22: * 950 Charter Street
! 23: * Redwood City, CA 94063
! 24: * <info@isc.org>
! 25: * https://www.isc.org/
! 26: *
! 27: * This software has been written for Internet Systems Consortium
! 28: * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
! 29: * To learn more about Internet Systems Consortium, see
! 30: * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
! 31: * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
! 32: * ``http://www.nominum.com''.
! 33: */
! 34:
! 35: #include "dhcpd.h"
! 36:
! 37: #if defined (PACKET_ASSEMBLY) || defined (PACKET_DECODING)
! 38: #include "includes/netinet/if_ether.h"
! 39: #endif /* PACKET_ASSEMBLY || PACKET_DECODING */
! 40:
! 41: #if defined (PACKET_ASSEMBLY)
! 42: /* Assemble an hardware header... */
! 43:
! 44: void assemble_ethernet_header (interface, buf, bufix, to)
! 45: struct interface_info *interface;
! 46: unsigned char *buf;
! 47: unsigned *bufix;
! 48: struct hardware *to;
! 49: {
! 50: struct isc_ether_header eh;
! 51:
! 52: if (to && to -> hlen == 7) /* XXX */
! 53: memcpy (eh.ether_dhost, &to -> hbuf [1],
! 54: sizeof eh.ether_dhost);
! 55: else
! 56: memset (eh.ether_dhost, 0xff, sizeof (eh.ether_dhost));
! 57: if (interface -> hw_address.hlen - 1 == sizeof (eh.ether_shost))
! 58: memcpy (eh.ether_shost, &interface -> hw_address.hbuf [1],
! 59: sizeof (eh.ether_shost));
! 60: else
! 61: memset (eh.ether_shost, 0x00, sizeof (eh.ether_shost));
! 62:
! 63: eh.ether_type = htons (ETHERTYPE_IP);
! 64:
! 65: memcpy (&buf [*bufix], &eh, ETHER_HEADER_SIZE);
! 66: *bufix += ETHER_HEADER_SIZE;
! 67: }
! 68: #endif /* PACKET_ASSEMBLY */
! 69:
! 70: #ifdef PACKET_DECODING
! 71: /* Decode a hardware header... */
! 72:
! 73: ssize_t decode_ethernet_header (interface, buf, bufix, from)
! 74: struct interface_info *interface;
! 75: unsigned char *buf;
! 76: unsigned bufix;
! 77: struct hardware *from;
! 78: {
! 79: struct isc_ether_header eh;
! 80:
! 81: memcpy (&eh, buf + bufix, ETHER_HEADER_SIZE);
! 82:
! 83: #ifdef USERLAND_FILTER
! 84: if (ntohs (eh.ether_type) != ETHERTYPE_IP)
! 85: return -1;
! 86: #endif
! 87: memcpy (&from -> hbuf [1], eh.ether_shost, sizeof (eh.ether_shost));
! 88: from -> hbuf [0] = ARPHRD_ETHER;
! 89: from -> hlen = (sizeof eh.ether_shost) + 1;
! 90:
! 91: return ETHER_HEADER_SIZE;
! 92: }
! 93: #endif /* PACKET_DECODING */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>