]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - common/ethernet.c
1621aa291477c8686191b1fa04116349d3e155c7
3 Packet assembly code, originally contributed by Archie Cobbs. */
6 * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1996-2003 by Internet Software Consortium
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/.
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.
21 * Internet Systems Consortium, Inc.
23 * Newmarket, NH 03857 USA
25 * https://www.isc.org/
31 #if defined (PACKET_ASSEMBLY) || defined (PACKET_DECODING)
32 #include "includes/netinet/if_ether.h"
33 #endif /* PACKET_ASSEMBLY || PACKET_DECODING */
35 #if defined (PACKET_ASSEMBLY)
36 /* Assemble an hardware header... */
38 void assemble_ethernet_header (interface
, buf
, bufix
, to
)
39 struct interface_info
*interface
;
44 struct isc_ether_header eh
;
46 if (to
&& to
-> hlen
== 7) /* XXX */
47 memcpy (eh
.ether_dhost
, &to
-> hbuf
[1],
48 sizeof eh
.ether_dhost
);
50 memset (eh
.ether_dhost
, 0xff, sizeof (eh
.ether_dhost
));
51 if (interface
-> hw_address
.hlen
- 1 == sizeof (eh
.ether_shost
))
52 memcpy (eh
.ether_shost
, &interface
-> hw_address
.hbuf
[1],
53 sizeof (eh
.ether_shost
));
55 memset (eh
.ether_shost
, 0x00, sizeof (eh
.ether_shost
));
57 eh
.ether_type
= htons (ETHERTYPE_IP
);
59 memcpy (&buf
[*bufix
], &eh
, ETHER_HEADER_SIZE
);
60 *bufix
+= ETHER_HEADER_SIZE
;
62 #endif /* PACKET_ASSEMBLY */
64 #ifdef PACKET_DECODING
65 /* Decode a hardware header... */
67 ssize_t
decode_ethernet_header (interface
, buf
, bufix
, from
)
68 struct interface_info
*interface
;
71 struct hardware
*from
;
73 struct isc_ether_header eh
;
75 memcpy (&eh
, buf
+ bufix
, ETHER_HEADER_SIZE
);
77 #ifdef USERLAND_FILTER
78 if (ntohs (eh
.ether_type
) != ETHERTYPE_IP
)
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;
85 return ETHER_HEADER_SIZE
;
87 #endif /* PACKET_DECODING */