libnet-macros.h
Go to the documentation of this file.
1/*
2 * $Id: libnet-macros.h,v 1.7 2004/04/13 17:32:28 mike Exp $
3 *
4 * libnet-macros.h - Network routine library macro header file
5 *
6 * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31
32#ifndef __LIBNET_MACROS_H
33#define __LIBNET_MACROS_H
44#define LIBNET_DONT_RESOLVE 0
45
50#define LIBNET_RESOLVE 1
51
55#define LIBNET_ON 0
56
60#define LIBNET_OFF 1
61
65#ifndef IN6ADDR_ERROR_INIT
66#define IN6ADDR_ERROR_INIT { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
67 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
68 0xff, 0xff } } }
69#endif
70
74#define LIBNET_PR2 0
75#define LIBNET_PR8 1
76#define LIBNET_PR16 2
77#define LIBNET_PRu16 3
78#define LIBNET_PR32 4
79#define LIBNET_PRu32 5
80#define LIBNET_PRAND_MAX 0xffffffff
81
85#define LIBNET_MAX_PACKET 0xffff
86#ifndef IP_MAXPACKET
87#define IP_MAXPACKET 0xffff
88#endif
89
90
91/* ethernet addresses are 6 octets long */
92#ifndef ETHER_ADDR_LEN
93#define ETHER_ADDR_LEN 0x6
94#endif
95
96/* FDDI addresses are 6 octets long */
97#ifndef FDDI_ADDR_LEN
98#define FDDI_ADDR_LEN 0x6
99#endif
100
101/* token ring addresses are 6 octets long */
102#ifndef TOKEN_RING_ADDR_LEN
103#define TOKEN_RING_ADDR_LEN 0x6
104#endif
105
106/* LLC Organization Code is 3 bytes long */
107#define LIBNET_ORG_CODE_SIZE 0x3
108
112#define LIBNET_ERRBUF_SIZE 0x100
113
117#define LIBNET_MAXOPTION_SIZE 0x28
118
119/* some BSD variants have this endianess problem */
120#if (LIBNET_BSD_BYTE_SWAP)
121#define FIX(n) ntohs(n)
122#define UNFIX(n) htons(n)
123#else
124#define FIX(n) (n)
125#define UNFIX(n) (n)
126#endif
127
128/* used internally for packet builders */
129#define LIBNET_DO_PAYLOAD(l, p) \
130 if (payload_s && !payload) \
131{ \
132 snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, \
133 "%s(): payload inconsistency\n", __func__); \
134 goto bad; \
135} \
136 if (payload_s) \
137{ \
138 n = libnet_pblock_append(l, p, payload, payload_s); \
139 if (n == (uint32_t) - 1) \
140 { \
141 goto bad; \
142 } \
143} \
144
145/* used internally for LLDP stuff */
146#define LIBNET_LLDP_TLV_SET_TYPE(tlv, type) (tlv |= (type << 9))
147#define LIBNET_LLDP_TLV_SET_LEN(tlv, len) (tlv |= len)
148
149/* used internally for checksum stuff */
150#define LIBNET_CKSUM_CARRY(x) \
151 (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
152
153/* used interally for OSPF stuff */
154#define LIBNET_OSPF_AUTHCPY(x, y) \
155 memcpy((uint8_t *)x, (uint8_t *)y, sizeof(y))
156#define LIBNET_OSPF_CKSUMBUF(x, y) \
157 memcpy((uint8_t *)x, (uint8_t *)y, sizeof(y))
158
159/* used internally for NTP leap indicator, version, and mode */
160#define LIBNET_NTP_DO_LI_VN_MODE(li, vn, md) \
161 ((uint8_t)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7)))
162
163/* Not all systems have IFF_LOOPBACK */
164#ifdef IFF_LOOPBACK
165#define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
166#else
167#define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo") == 0)
168#endif
169
170/* advanced mode check */
171#define LIBNET_ISADVMODE(x) (x & 0x08)
172
173/* context queue macros and constants */
174#define LIBNET_LABEL_SIZE 64
175#define LIBNET_LABEL_DEFAULT "cardshark"
176#define CQ_LOCK_UNLOCKED (uint32_t)0x00000000
177#define CQ_LOCK_READ (uint32_t)0x00000001
178#define CQ_LOCK_WRITE (uint32_t)0x00000002
179
185#define for_each_context_in_cq(l) \
186 for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next())
187
188/* return 1 if write lock is set on cq */
189#define cq_is_wlocked() (l_cqd.cq_lock & CQ_LOCK_WRITE)
190
191/* return 1 if read lock is set on cq */
192#define cq_is_rlocked() (l_cqd.cq_lock & CQ_LOCK_READ)
193
194/* return 1 if any lock is set on cq */
195#define cq_is_locked() (l_cqd.cq_lock & (CQ_LOCK_READ | CQ_LOCK_WRITE))
196
197/* check if a context queue is locked */
198#define check_cq_lock(x) (l_cqd.cq_lock & x)
199
200#endif /* __LIBNET_MACROS_H */
201