1 /*
2 * $Id: libnet_build_link.c,v 1.10 2004/04/13 17:32:28 mike Exp $
3 *
4 * libnet
5 * libnet_build_link.c - link-layer packet assembler
6 *
7 * Copyright (c) 2003 Roberto Larcher <roberto.larcher@libero.it>
8 * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 */
33
34 #if (HAVE_CONFIG_H)
35 #include "../include/config.h"
36 #endif
37
38 #if (!(_WIN32) || (__CYGWIN__))
39 #include "../include/libnet.h"
40 #else
41 #include "../include/win32/libnet.h"
42 #endif
43
44 libnet_ptag_t
libnet_build_link(const uint8_t * dst,const uint8_t * src,const uint8_t * oui,uint16_t type,const uint8_t * payload,uint32_t payload_s,libnet_t * l,libnet_ptag_t ptag)45 libnet_build_link(const uint8_t *dst, const uint8_t *src, const uint8_t *oui, uint16_t type,
46 const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
47
48 {
49 uint8_t org[3] = {0x00, 0x00, 0x00};
50 switch (l->link_type)
51 {
52 /* add FDDI */
53 case DLT_EN10MB:
54 return libnet_build_ethernet(dst, src, type, payload, payload_s, l,
55 ptag);
56 case DLT_IEEE802:
57 return libnet_build_token_ring(LIBNET_TOKEN_RING_FRAME,
58 LIBNET_TOKEN_RING_LLC_FRAME, dst, src, LIBNET_SAP_SNAP,
59 LIBNET_SAP_SNAP, 0x03, org, type, payload, payload_s,
60 l, ptag);
61 }
62 snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
63 "%s(): linktype %d not supported\n", __func__, l->link_type);
64 return -1;
65 }
66
67 libnet_ptag_t
libnet_autobuild_link(const uint8_t * dst,const uint8_t * oui,uint16_t type,libnet_t * l)68 libnet_autobuild_link(const uint8_t *dst, const uint8_t *oui, uint16_t type, libnet_t *l)
69 {
70 uint8_t org[3] = {0x00, 0x00, 0x00};
71 switch (l->link_type)
72 {
73 /* add FDDI */
74 case DLT_EN10MB:
75 return (libnet_autobuild_ethernet(dst, type, l));
76 case DLT_IEEE802:
77 return (libnet_autobuild_token_ring(LIBNET_TOKEN_RING_FRAME,
78 LIBNET_TOKEN_RING_LLC_FRAME, dst, LIBNET_SAP_SNAP,
79 LIBNET_SAP_SNAP, 0x03, org, TOKEN_RING_TYPE_IP, l));
80 }
81 snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
82 "%s(): linktype %d not supported\n", __func__, l->link_type);
83 return (-1);
84 }
85
86