]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - src/include/ipv4/lwip/ip_addr.h
e524c8db767a3acea6db72b313a799d8014e449c
[pes-rpp/rpp-lwip.git] / src / include / ipv4 / lwip / ip_addr.h
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  *    this list of conditions and the following disclaimer in the documentation
12  *    and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 #ifndef __LWIP_IP_ADDR_H__
33 #define __LWIP_IP_ADDR_H__
34
35 #include "lwip/arch.h"
36
37 struct ip_addr {
38   u32_t addr;
39 };
40
41 struct ip_addr2 {
42   u16_t addrw[2];
43 };
44
45 /* For compatibility with BSD code */
46 struct in_addr {
47   u32_t s_addr;
48 };
49
50 struct netif;
51
52 extern const struct ip_addr ip_addr_any;
53 extern const struct ip_addr ip_addr_broadcast;
54
55 /** IP_ADDR_ can be used as a fixed IP address
56  *  for the wildcard and the broadcast address
57  */
58 #define IP_ADDR_ANY ((struct ip_addr *)&ip_addr_any)
59 #define IP_ADDR_BROADCAST ((struct ip_addr *)&ip_addr_broadcast)
60
61 #define INADDR_NONE    ((u32_t) 0xffffffff)  /* 255.255.255.255 */
62 #define INADDR_LOOPBACK    ((u32_t) 0x7f000001)  /* 127.0.0.1 */
63
64 /* Definitions of the bits in an Internet address integer.
65
66    On subnets, host and network parts are found according to
67    the subnet mask, not these masks.  */
68
69 #define  IN_CLASSA(a)    ((((u32_t)(a)) & 0x80000000) == 0)
70 #define  IN_CLASSA_NET    0xff000000
71 #define  IN_CLASSA_NSHIFT  24
72 #define  IN_CLASSA_HOST    (0xffffffff & ~IN_CLASSA_NET)
73 #define  IN_CLASSA_MAX    128
74
75 #define  IN_CLASSB(a)    ((((u32_t)(a)) & 0xc0000000) == 0x80000000)
76 #define  IN_CLASSB_NET    0xffff0000
77 #define  IN_CLASSB_NSHIFT  16
78 #define  IN_CLASSB_HOST    (0xffffffff & ~IN_CLASSB_NET)
79 #define  IN_CLASSB_MAX    65536
80
81 #define  IN_CLASSC(a)    ((((u32_t)(a)) & 0xe0000000) == 0xc0000000)
82 #define  IN_CLASSC_NET    0xffffff00
83 #define  IN_CLASSC_NSHIFT  8
84 #define  IN_CLASSC_HOST    (0xffffffff & ~IN_CLASSC_NET)
85
86 #define IN_CLASSD(a)        (((u32_t)(a) & 0xf0000000) == 0xe0000000)
87 #define IN_CLASSD_NET       0xf0000000  /* These ones aren't really */
88 #define IN_CLASSD_NSHIFT    28      /* net and host fields, but */
89 #define IN_CLASSD_HOST      0x0fffffff  /* routing needn't know.    */
90 #define IN_MULTICAST(a)     IN_CLASSD(a)
91
92 #define IN_EXPERIMENTAL(a)  (((u32_t)(a) & 0xf0000000) == 0xf0000000)
93 #define IN_BADCLASS(a)      (((u32_t)(a) & 0xf0000000) == 0xf0000000)
94
95 #define IN_LOOPBACKNET      127         /* official! */
96
97
98 #define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = htonl(((u32_t)(a & 0xff) << 24) | ((u32_t)(b & 0xff) << 16) | \
99                                                          ((u32_t)(c & 0xff) << 8) | (u32_t)(d & 0xff))
100
101 #define ip_addr_set(dest, src) (dest)->addr = \
102                                ((src) == NULL? 0:\
103                                (src)->addr)
104 #define ip_addr_maskcmp(addr1, addr2, mask) (((addr1)->addr & \
105                                               (mask)->addr) == \
106                                              ((addr2)->addr & \
107                                               (mask)->addr))
108 #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
109
110 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
111
112 u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *);
113
114 #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000))
115
116
117 #define ip_addr_debug_print(debug, ipaddr) LWIP_DEBUGF(debug, ("%u.%u.%u.%u", \
118         ipaddr?(unsigned int)(ntohl((ipaddr)->addr) >> 24) & 0xff:0, \
119         ipaddr?(unsigned int)(ntohl((ipaddr)->addr) >> 16) & 0xff:0, \
120         ipaddr?(unsigned int)(ntohl((ipaddr)->addr) >> 8) & 0xff:0, \
121         ipaddr?(unsigned int)ntohl((ipaddr)->addr) & 0xff:0U))
122
123 /* cast to unsigned int, as it is used as argument to printf functions
124  * which expect integer arguments */
125 #define ip4_addr1(ipaddr) ((unsigned int)(ntohl((ipaddr)->addr) >> 24) & 0xff)
126 #define ip4_addr2(ipaddr) ((unsigned int)(ntohl((ipaddr)->addr) >> 16) & 0xff)
127 #define ip4_addr3(ipaddr) ((unsigned int)(ntohl((ipaddr)->addr) >> 8) & 0xff)
128 #define ip4_addr4(ipaddr) ((unsigned int)(ntohl((ipaddr)->addr)) & 0xff)
129 #endif /* __LWIP_IP_ADDR_H__ */
130
131
132
133
134
135