1 /* fddi.c
2 
3    Packet assembly code, originally contributed by Archie Cobbs. */
4 
5 /*
6  * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1996-2003 by Internet Software Consortium
8  *
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/.
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  */
28 
29 #include "dhcpd.h"
30 
31 #if defined (DEC_FDDI)
32 #include <netinet/if_fddi.h>
33 #include <net/if_llc.h>
34 
35 #if defined (PACKET_ASSEMBLY) || defined (PACKET_DECODING)
36 #include "includes/netinet/if_ether.h"
37 #endif /* PACKET_ASSEMBLY || PACKET_DECODING */
38 
39 #if defined (PACKET_ASSEMBLY)
40 /* Assemble an hardware header... */
41 
assemble_fddi_header(interface,buf,bufix,to)42 void assemble_fddi_header (interface, buf, bufix, to)
43 	struct interface_info *interface;
44 	unsigned char *buf;
45 	unsigned *bufix;
46 	struct hardware *to;
47 {
48 	struct fddi_header   fh;
49 	struct llc     lh;
50 
51 	if (to && to -> hlen == 7)
52 		memcpy (fh.fddi_dhost, &to -> hbuf [1],
53 			sizeof (fh.fddi_dhost));
54 	memcpy (fh.fddi_shost,
55 		&interface -> hw_address.hbuf [1], sizeof (fh.fddi_shost));
56 	fh.fddi_fc = FDDIFC_LLC_ASYNC;
57 	memcpy (&buf [*bufix], &fh, sizeof fh);
58 	*bufix += sizeof fh;
59 
60 	lh.llc_dsap = LLC_SNAP_LSAP;
61 	lh.llc_ssap = LLC_SNAP_LSAP;
62 	lh.llc_un.type_snap.control = LLC_UI;
63 	lh.llc_un.type_snap.ether_type = htons (ETHERTYPE_IP);
64 	memcpy (&buf [*bufix], &lh, LLC_SNAP_LEN);
65 	*bufix += LLC_SNAP_LEN;
66 }
67 #endif /* PACKET_ASSEMBLY */
68 
69 #ifdef PACKET_DECODING
70 /* Decode a hardware header... */
71 
decode_fddi_header(interface,buf,bufix,from)72 ssize_t decode_fddi_header (interface, buf, bufix, from)
73      struct interface_info *interface;
74      unsigned char *buf;
75      unsigned bufix;
76      struct hardware *from;
77 {
78 	struct fddi_header   fh;
79 	struct llc     lh;
80 
81 	from -> hbuf [0] = HTYPE_FDDI;
82 	memcpy (&from -> hbuf [1], fh.fddi_shost, sizeof fh.fddi_shost);
83 	return FDDI_HEADER_SIZE + LLC_SNAP_LEN;
84 }
85 #endif /* PACKET_DECODING */
86 #endif /* DEC_FDDI */
87