OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / include / libnet / libnet-macros.h
1 /*
2  *  $Id: libnet-macros.h,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3  *
4  *  libnet-macros.h - Network routine library macro header file
5  *
6  *  Copyright (c) 1998 - 2001 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 /*
36  *  for libnet_hostlookup
37  */
38 #define LIBNET_DONT_RESOLVE 0
39 #define LIBNET_RESOLVE      1
40
41 /*
42  *  prand constants
43  */
44 #define LIBNET_PR2          0
45 #define LIBNET_PR8          1
46 #define LIBNET_PR16         2
47 #define LIBNET_PRu16        3
48 #define LIBNET_PR32         4
49 #define LIBNET_PRu32        5
50 #define LIBNET_PRAND_MAX    0xffffffff
51
52 /*
53  *  Concession to legacy naming scheme
54  */
55 #define PR2         LIBNET_PR2
56 #define PR8         LIBNET_PR8
57 #define PR16        LIBNET_PR16
58 #define PRu16       LIBNET_PRu16
59 #define PR32        LIBNET_PR32
60 #define PRu32       LIBNET_PRu32
61 #define PRAND_MAX   LIBNET_PRAND_MAX
62
63 /*
64  *  Misc packet sizes for malloc
65  */
66 #define LIBNET_PACKET       LIBNET_IP_H + LIBNET_TCP_H  /* IP, UDP or TCP */
67 #define LIBNET_OPTS         0x34            /* options! options! options! */
68 #define LIBNET_MAX_PACKET   0xffff          /* as big as we can get */
69
70
71 /*
72  *  Error handling constants.
73  */
74 #define LIBNET_ERR_WARNING  1
75 #define LIBNET_ERR_CRITICAL 2
76 #define LIBNET_ERR_FATAL    3
77
78 /*
79  *  Concession to legacy naming scheme
80  */
81 #define LN_ERR_WARNING  LIBNET_ERR_WARNING
82 #define LN_ERR_CRITICAL LIBNET_ERR_CRITICAL
83 #define LN_ERR_FATAL    LIBNET_ERR_FATAL
84
85
86 #define LIBNET_ERRBUF_SIZE  256
87
88
89 /*
90  *  Some BSD variants have this endianess problem.
91  */
92 #if (LIBNET_BSD_BYTE_SWAP)
93 #define FIX(n)      ntohs(n)
94 #define UNFIX(n)    htons(n)
95 #else
96 #define FIX(n)      (n)
97 #define UNFIX(n)    (n)
98 #endif
99
100 /*
101  *  Arena stuff
102  */
103 #define LIBNET_GET_ARENA_SIZE(a)               (a.size)
104 #define LIBNET_GET_ARENA_REMAINING_BYTES(a)    (a.size - a.current)
105
106
107 /*
108  *  Checksum stuff
109  */
110 #define LIBNET_CKSUM_CARRY(x) \
111     (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
112
113
114 /*
115  *  OSPF stuff
116  */
117 #define LIBNET_OSPF_AUTHCPY(x,y)  memcpy((u_char *)x, (u_char *)y, sizeof(y))
118 #define LIBNET_OSPF_CKSUMBUF(x,y) memcpy((u_char *)x, (u_char *)y, sizeof(y))  
119
120 /*
121  *  Not all systems have IFF_LOOPBACK
122  *  Used by if_addr.c
123  */
124 #ifdef IFF_LOOPBACK
125 #define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
126 #else
127 #define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0)
128 #endif
129
130 #define LIBNET_PRINT_ETH_ADDR(e) \
131 { \
132     int i = 0; \
133     for (i = 0; i < 6; i++) \
134     { \
135         printf("%x", e.ether_addr_octet[i]); \
136         if (i != 5) \
137         { \
138             printf(":"); \
139         } \
140     } \
141     printf("\n"); \
142 }
143
144 #endif  /* __LIBNET_MACROS_H */
145
146 /* EOF */