source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/ip_addr.h @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 6.6 KB
Line 
1/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
3/*
4 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 *    this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 *    this list of conditions and the following disclaimer in the documentation
14 *    and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 *    derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 * OF SUCH DAMAGE.
28 *
29 * This file is part of the lwIP TCP/IP stack.
30 *
31 * Author: Adam Dunkels <adam@sics.se>
32 *
33 */
34#ifndef __LWIP_IP_ADDR_H__
35#define __LWIP_IP_ADDR_H__
36
37#include "lwip/opt.h"
38
39#include "lwip/inet.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45#ifdef PACK_STRUCT_USE_INCLUDES
46#  include "arch/bpstruct.h"
47#endif
48PACK_STRUCT_BEGIN
49struct ip_addr {
50  PACK_STRUCT_FIELD(u32_t addr);
51} PACK_STRUCT_STRUCT;
52PACK_STRUCT_END
53#ifdef PACK_STRUCT_USE_INCLUDES
54#  include "arch/epstruct.h"
55#endif
56
57/*
58 * struct ipaddr2 is used in the definition of the ARP packet format in
59 * order to support compilers that don't have structure packing.
60 */
61#ifdef PACK_STRUCT_USE_INCLUDES
62#  include "arch/bpstruct.h"
63#endif
64PACK_STRUCT_BEGIN
65struct ip_addr2 {
66  PACK_STRUCT_FIELD(u16_t addrw[2]);
67} PACK_STRUCT_STRUCT;
68PACK_STRUCT_END
69#ifdef PACK_STRUCT_USE_INCLUDES
70#  include "arch/epstruct.h"
71#endif
72
73struct netif;
74
75extern const struct ip_addr ip_addr_any;
76extern const struct ip_addr ip_addr_broadcast;
77
78/** IP_ADDR_ can be used as a fixed IP address
79 *  for the wildcard and the broadcast address
80 */
81#define IP_ADDR_ANY         ((struct ip_addr *)&ip_addr_any)
82#define IP_ADDR_BROADCAST   ((struct ip_addr *)&ip_addr_broadcast)
83
84/* Definitions of the bits in an Internet address integer.
85
86   On subnets, host and network parts are found according to
87   the subnet mask, not these masks.  */
88
89#define IN_CLASSA(a)        ((((u32_t)(a)) & 0x80000000UL) == 0)
90#define IN_CLASSA_NET       0xff000000
91#define IN_CLASSA_NSHIFT    24
92#define IN_CLASSA_HOST      (0xffffffff & ~IN_CLASSA_NET)
93#define IN_CLASSA_MAX       128
94
95#define IN_CLASSB(a)        ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
96#define IN_CLASSB_NET       0xffff0000
97#define IN_CLASSB_NSHIFT    16
98#define IN_CLASSB_HOST      (0xffffffff & ~IN_CLASSB_NET)
99#define IN_CLASSB_MAX       65536
100
101#define IN_CLASSC(a)        ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
102#define IN_CLASSC_NET       0xffffff00
103#define IN_CLASSC_NSHIFT    8
104#define IN_CLASSC_HOST      (0xffffffff & ~IN_CLASSC_NET)
105
106#define IN_CLASSD(a)        (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
107#define IN_CLASSD_NET       0xf0000000          /* These ones aren't really */
108#define IN_CLASSD_NSHIFT    28                  /*   net and host fields, but */
109#define IN_CLASSD_HOST      0x0fffffff          /*   routing needn't know. */
110#define IN_MULTICAST(a)     IN_CLASSD(a)
111
112#define IN_EXPERIMENTAL(a)  (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
113#define IN_BADCLASS(a)      (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
114
115#define IN_LOOPBACKNET      127                 /* official! */
116
117#define IP4_ADDR(ipaddr, a,b,c,d) \
118        (ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \
119                               ((u32_t)((b) & 0xff) << 16) | \
120                               ((u32_t)((c) & 0xff) << 8) | \
121                                (u32_t)((d) & 0xff))
122
123#define ip_addr_set(dest, src) (dest)->addr = \
124                               ((src) == NULL? 0:\
125                               (src)->addr)
126/**
127 * Determine if two address are on the same network.
128 *
129 * @arg addr1 IP address 1
130 * @arg addr2 IP address 2
131 * @arg mask network identifier mask
132 * @return !0 if the network identifiers of both address match
133 */
134#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
135                                              (mask)->addr) == \
136                                             ((addr2)->addr & \
137                                              (mask)->addr))
138#define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
139
140#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
141
142u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *);
143
144#define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000UL)) == ntohl(0xe0000000UL))
145
146#define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL))
147
148#define ip_addr_debug_print(debug, ipaddr) \
149  LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F,              \
150                      ipaddr != NULL ?                                  \
151                      (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0,  \
152                      ipaddr != NULL ?                                  \
153                      (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0,  \
154                      ipaddr != NULL ?                                  \
155                      (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0,   \
156                      ipaddr != NULL ?                                  \
157                      (u16_t)ntohl((ipaddr)->addr) & 0xff : 0))
158
159/* These are cast to u16_t, with the intent that they are often arguments
160 * to printf using the U16_F format from cc.h. */
161#define ip4_addr1(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)
162#define ip4_addr2(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)
163#define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
164#define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff)
165
166/**
167 * Same as inet_ntoa() but takes a struct ip_addr*
168 */
169#define ip_ntoa(addr)  ((addr != NULL) ? inet_ntoa(*((struct in_addr*)(addr))) : "NULL")
170
171#ifdef __cplusplus
172}
173#endif
174
175#endif /* __LWIP_IP_ADDR_H__ */
Note: See TracBrowser for help on using the repository browser.