]> git.ipfire.org Git - thirdparty/dhcp.git/blame - common/ethernet.c
Added option definition
[thirdparty/dhcp.git] / common / ethernet.c
CommitLineData
a770670e 1/* ethernet.c
0c699a23
TL
2
3 Packet assembly code, originally contributed by Archie Cobbs. */
4
5/*
7512d88b 6 * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
98311e4b 7 * Copyright (c) 1996-2003 by Internet Software Consortium
0c699a23 8 *
7512d88b
TM
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
0c699a23 12 *
98311e4b
DH
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.
0c699a23 20 *
98311e4b
DH
21 * Internet Systems Consortium, Inc.
22 * 950 Charter Street
23 * Redwood City, CA 94063
24 * <info@isc.org>
2c85ac9b 25 * https://www.isc.org/
49733f31 26 *
0c699a23
TL
27 */
28
0c699a23
TL
29#include "dhcpd.h"
30
31#if defined (PACKET_ASSEMBLY) || defined (PACKET_DECODING)
32#include "includes/netinet/if_ether.h"
33#endif /* PACKET_ASSEMBLY || PACKET_DECODING */
34
35#if defined (PACKET_ASSEMBLY)
36/* Assemble an hardware header... */
0c699a23
TL
37
38void assemble_ethernet_header (interface, buf, bufix, to)
39 struct interface_info *interface;
40 unsigned char *buf;
b1b7b521 41 unsigned *bufix;
0c699a23
TL
42 struct hardware *to;
43{
d758ad8c 44 struct isc_ether_header eh;
0c699a23 45
31730f17
TL
46 if (to && to -> hlen == 7) /* XXX */
47 memcpy (eh.ether_dhost, &to -> hbuf [1],
48 sizeof eh.ether_dhost);
0c699a23
TL
49 else
50 memset (eh.ether_dhost, 0xff, sizeof (eh.ether_dhost));
31730f17
TL
51 if (interface -> hw_address.hlen - 1 == sizeof (eh.ether_shost))
52 memcpy (eh.ether_shost, &interface -> hw_address.hbuf [1],
0c699a23
TL
53 sizeof (eh.ether_shost));
54 else
55 memset (eh.ether_shost, 0x00, sizeof (eh.ether_shost));
56
0c699a23 57 eh.ether_type = htons (ETHERTYPE_IP);
0c699a23 58
98c83345
TL
59 memcpy (&buf [*bufix], &eh, ETHER_HEADER_SIZE);
60 *bufix += ETHER_HEADER_SIZE;
0c699a23
TL
61}
62#endif /* PACKET_ASSEMBLY */
63
64#ifdef PACKET_DECODING
65/* Decode a hardware header... */
66
67ssize_t decode_ethernet_header (interface, buf, bufix, from)
68 struct interface_info *interface;
69 unsigned char *buf;
b1b7b521 70 unsigned bufix;
0c699a23
TL
71 struct hardware *from;
72{
d758ad8c 73 struct isc_ether_header eh;
0c699a23 74
98c83345 75 memcpy (&eh, buf + bufix, ETHER_HEADER_SIZE);
0c699a23
TL
76
77#ifdef USERLAND_FILTER
78 if (ntohs (eh.ether_type) != ETHERTYPE_IP)
79 return -1;
80#endif
31730f17
TL
81 memcpy (&from -> hbuf [1], eh.ether_shost, sizeof (eh.ether_shost));
82 from -> hbuf [0] = ARPHRD_ETHER;
83 from -> hlen = (sizeof eh.ether_shost) + 1;
0c699a23 84
31730f17 85 return ETHER_HEADER_SIZE;
0c699a23
TL
86}
87#endif /* PACKET_DECODING */