2000-03-24 00:22:20 +00:00
|
|
|
/* ethernet.c
|
1999-05-27 17:34:54 +00:00
|
|
|
|
|
|
|
Packet assembly code, originally contributed by Archie Cobbs. */
|
|
|
|
|
|
|
|
/*
|
2017-07-12 09:23:23 -04:00
|
|
|
* Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
|
2005-03-17 20:15:29 +00:00
|
|
|
* Copyright (c) 1996-2003 by Internet Software Consortium
|
1999-05-27 17:34:54 +00:00
|
|
|
*
|
2017-07-12 09:23:23 -04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
1999-05-27 17:34:54 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
|
|
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-05-27 17:34:54 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* Internet Systems Consortium, Inc.
|
|
|
|
* 950 Charter Street
|
|
|
|
* Redwood City, CA 94063
|
|
|
|
* <info@isc.org>
|
2009-07-23 18:52:21 +00:00
|
|
|
* https://www.isc.org/
|
2000-03-17 04:00:32 +00:00
|
|
|
*
|
1999-05-27 17:34:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dhcpd.h"
|
|
|
|
|
|
|
|
#if defined (PACKET_ASSEMBLY) || defined (PACKET_DECODING)
|
|
|
|
#include "includes/netinet/if_ether.h"
|
|
|
|
#endif /* PACKET_ASSEMBLY || PACKET_DECODING */
|
|
|
|
|
|
|
|
#if defined (PACKET_ASSEMBLY)
|
|
|
|
/* Assemble an hardware header... */
|
|
|
|
|
|
|
|
void assemble_ethernet_header (interface, buf, bufix, to)
|
|
|
|
struct interface_info *interface;
|
|
|
|
unsigned char *buf;
|
1999-10-07 06:36:35 +00:00
|
|
|
unsigned *bufix;
|
1999-05-27 17:34:54 +00:00
|
|
|
struct hardware *to;
|
|
|
|
{
|
2001-06-27 00:31:20 +00:00
|
|
|
struct isc_ether_header eh;
|
1999-05-27 17:34:54 +00:00
|
|
|
|
2000-01-05 18:01:15 +00:00
|
|
|
if (to && to -> hlen == 7) /* XXX */
|
|
|
|
memcpy (eh.ether_dhost, &to -> hbuf [1],
|
|
|
|
sizeof eh.ether_dhost);
|
1999-05-27 17:34:54 +00:00
|
|
|
else
|
|
|
|
memset (eh.ether_dhost, 0xff, sizeof (eh.ether_dhost));
|
2000-01-05 18:01:15 +00:00
|
|
|
if (interface -> hw_address.hlen - 1 == sizeof (eh.ether_shost))
|
|
|
|
memcpy (eh.ether_shost, &interface -> hw_address.hbuf [1],
|
1999-05-27 17:34:54 +00:00
|
|
|
sizeof (eh.ether_shost));
|
|
|
|
else
|
|
|
|
memset (eh.ether_shost, 0x00, sizeof (eh.ether_shost));
|
|
|
|
|
|
|
|
eh.ether_type = htons (ETHERTYPE_IP);
|
|
|
|
|
1999-11-11 16:10:59 +00:00
|
|
|
memcpy (&buf [*bufix], &eh, ETHER_HEADER_SIZE);
|
|
|
|
*bufix += ETHER_HEADER_SIZE;
|
1999-05-27 17:34:54 +00:00
|
|
|
}
|
|
|
|
#endif /* PACKET_ASSEMBLY */
|
|
|
|
|
|
|
|
#ifdef PACKET_DECODING
|
|
|
|
/* Decode a hardware header... */
|
|
|
|
|
|
|
|
ssize_t decode_ethernet_header (interface, buf, bufix, from)
|
|
|
|
struct interface_info *interface;
|
|
|
|
unsigned char *buf;
|
1999-10-07 06:36:35 +00:00
|
|
|
unsigned bufix;
|
1999-05-27 17:34:54 +00:00
|
|
|
struct hardware *from;
|
|
|
|
{
|
2001-06-27 00:31:20 +00:00
|
|
|
struct isc_ether_header eh;
|
1999-05-27 17:34:54 +00:00
|
|
|
|
1999-11-11 16:10:59 +00:00
|
|
|
memcpy (&eh, buf + bufix, ETHER_HEADER_SIZE);
|
1999-05-27 17:34:54 +00:00
|
|
|
|
|
|
|
#ifdef USERLAND_FILTER
|
|
|
|
if (ntohs (eh.ether_type) != ETHERTYPE_IP)
|
|
|
|
return -1;
|
|
|
|
#endif
|
2000-01-05 18:01:15 +00:00
|
|
|
memcpy (&from -> hbuf [1], eh.ether_shost, sizeof (eh.ether_shost));
|
|
|
|
from -> hbuf [0] = ARPHRD_ETHER;
|
|
|
|
from -> hlen = (sizeof eh.ether_shost) + 1;
|
1999-05-27 17:34:54 +00:00
|
|
|
|
2000-01-05 18:01:15 +00:00
|
|
|
return ETHER_HEADER_SIZE;
|
1999-05-27 17:34:54 +00:00
|
|
|
}
|
|
|
|
#endif /* PACKET_DECODING */
|