Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / common / vera / niu_ippktgen / C / libnet / include / libnet / libnet-macros.h
CommitLineData
86530b38
AT
1/*
2 * $Id: libnet-macros.h,v 1.21 2005/11/29 21:51:44 carlosc 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
34/**
35 * @file libnet-macros.h
36 * @brief libnet macros and symbloc constants
37 */
38
39/* for systems without snprintf */
40#if defined(NO_SNPRINTF)
41#define snprintf(buf, len, args...) sprintf(buf, ##args)
42#endif
43
44
45/**
46 * Used for libnet's name resolution functions, specifies that no DNS lookups
47 * should be performed and the IP address should be kept in numeric form.
48 */
49#define LIBNET_DONT_RESOLVE 0
50
51/**
52 * Used for libnet's name resolution functions, specifies that a DNS lookup
53 * can be performed if needed to resolve the IP address to a canonical form.
54 */
55#define LIBNET_RESOLVE 1
56
57/**
58 * Used several places, to specify "on" or "one"
59 */
60#define LIBNET_ON 0
61
62/**
63 * Used several places, to specify "on" or "one"
64 */
65#define LIBNET_OFF 1
66
67/**
68 * IPv6 error code
69 */
70#ifndef IN6ADDR_ERROR_INIT
71#define IN6ADDR_ERROR_INIT { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
72 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
73 0xff, 0xff } } }
74#endif
75
76/**
77 * Used for libnet_get_prand() to specify function disposition
78 */
79#define LIBNET_PR2 0
80#define LIBNET_PR8 1
81#define LIBNET_PR16 2
82#define LIBNET_PRu16 3
83#define LIBNET_PR32 4
84#define LIBNET_PRu32 5
85#define LIBNET_PRAND_MAX 0xffffffff
86
87/**
88 * The biggest an IP packet can be -- 65,535 bytes.
89 */
90#define LIBNET_MAX_PACKET 0xffff
91#ifndef IP_MAXPACKET
92#define IP_MAXPACKET 0xffff
93#endif
94
95
96/* ethernet addresses are 6 octets long */
97#ifndef ETHER_ADDR_LEN
98#define ETHER_ADDR_LEN 0x6
99#endif
100
101/* FDDI addresses are 6 octets long */
102#ifndef FDDI_ADDR_LEN
103#define FDDI_ADDR_LEN 0x6
104#endif
105
106/* token ring addresses are 6 octets long */
107#ifndef TOKEN_RING_ADDR_LEN
108#define TOKEN_RING_ADDR_LEN 0x6
109#endif
110
111/* LLC Organization Code is 3 bytes long */
112#define LIBNET_ORG_CODE_SIZE 0x3
113
114/**
115 * The libnet error buffer is 256 bytes long.
116 */
117#define LIBNET_ERRBUF_SIZE 0x100
118
119/**
120 * IP and TCP options can be up to 40 bytes long.
121 */
122#define LIBNET_MAXOPTION_SIZE 0x28
123
124/* some BSD variants have this endianess problem */
125#if (LIBNET_BSD_BYTE_SWAP)
126#define FIX(n) ntohs(n)
127#define UNFIX(n) htons(n)
128#else
129#define FIX(n) (n)
130#define UNFIX(n) (n)
131#endif
132
133/* used internally for checksum stuff */
134#define LIBNET_CKSUM_CARRY(x) \
135 (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
136
137/* used interally for OSPF stuff */
138#define LIBNET_OSPF_AUTHCPY(x, y) \
139 memcpy((u_int8_t *)x, (u_int8_t *)y, sizeof(y))
140#define LIBNET_OSPF_CKSUMBUF(x, y) \
141 memcpy((u_int8_t *)x, (u_int8_t *)y, sizeof(y))
142
143/* used internally for NTP leap indicator, version, and mode */
144#define LIBNET_NTP_DO_LI_VN_MODE(li, vn, md) \
145 ((u_int8_t)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7)))
146
147/* Not all systems have IFF_LOOPBACK */
148#ifdef IFF_LOOPBACK
149#define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
150#else
151#define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0)
152#endif
153
154/* advanced mode check */
155#define LIBNET_ISADVMODE(x) (x & 0x08)
156
157/* context queue macros and constants */
158#define LIBNET_LABEL_SIZE 64
159#define LIBNET_LABEL_DEFAULT "cardshark"
160#define CQ_LOCK_UNLOCKED (u_int)0x00000000
161#define CQ_LOCK_READ (u_int)0x00000001
162#define CQ_LOCK_WRITE (u_int)0x00000002
163
164/**
165 * Provides an interface to iterate through the context queue of libnet
166 * contexts. Before calling this macro, be sure to set the queue using
167 * libnet_cq_head().
168 */
169#define for_each_context_in_cq(l) \
170 for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next())
171
172/* return 1 if write lock is set on cq */
173#define cq_is_wlocked() (l_cqd.cq_lock & CQ_LOCK_WRITE)
174
175/* return 1 if read lock is set on cq */
176#define cq_is_rlocked() (l_cqd.cq_lock & CQ_LOCK_READ)
177
178/* return 1 if any lock is set on cq */
179#define cq_is_locked() (l_cqd.cq_lock & (CQ_LOCK_READ | CQ_LOCK_WRITE))
180
181/* check if a context queue is locked */
182#define check_cq_lock(x) (l_cqd.cq_lock & x)
183
184#endif /* __LIBNET_MACROS_H */
185
186/* EOF */