Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/lwip/ip_addr.h need to be fixed.

0001 /*
0002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
0003  * All rights reserved.
0004  *
0005  * Redistribution and use in source and binary forms, with or without modification,
0006  * are permitted provided that the following conditions are met:
0007  *
0008  * 1. Redistributions of source code must retain the above copyright notice,
0009  *    this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright notice,
0011  *    this list of conditions and the following disclaimer in the documentation
0012  *    and/or other materials provided with the distribution.
0013  * 3. The name of the author may not be used to endorse or promote products
0014  *    derived from this software without specific prior written permission.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
0017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
0018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
0019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
0021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
0024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
0025  * OF SUCH DAMAGE.
0026  *
0027  * This file is part of the lwIP TCP/IP stack.
0028  *
0029  * Author: Adam Dunkels <adam@sics.se>
0030  *
0031  */
0032 #ifndef __LWIP_IP_ADDR_H__
0033 #define __LWIP_IP_ADDR_H__
0034 
0035 #include "lwip/opt.h"
0036 
0037 #include "lwip/inet.h"
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042 
0043 #ifdef PACK_STRUCT_USE_INCLUDES
0044 #  include "arch/bpstruct.h"
0045 #endif
0046 PACK_STRUCT_BEGIN
0047 struct ip_addr {
0048   PACK_STRUCT_FIELD(u32_t addr);
0049 } PACK_STRUCT_STRUCT;
0050 PACK_STRUCT_END
0051 #ifdef PACK_STRUCT_USE_INCLUDES
0052 #  include "arch/epstruct.h"
0053 #endif
0054 
0055 /*
0056  * struct ipaddr2 is used in the definition of the ARP packet format in
0057  * order to support compilers that don't have structure packing.
0058  */
0059 #ifdef PACK_STRUCT_USE_INCLUDES
0060 #  include "arch/bpstruct.h"
0061 #endif
0062 PACK_STRUCT_BEGIN
0063 struct ip_addr2 {
0064   PACK_STRUCT_FIELD(u16_t addrw[2]);
0065 } PACK_STRUCT_STRUCT;
0066 PACK_STRUCT_END
0067 #ifdef PACK_STRUCT_USE_INCLUDES
0068 #  include "arch/epstruct.h"
0069 #endif
0070 
0071 struct netif;
0072 
0073 extern const struct ip_addr ip_addr_any;
0074 extern const struct ip_addr ip_addr_broadcast;
0075 
0076 /** IP_ADDR_ can be used as a fixed IP address
0077  *  for the wildcard and the broadcast address
0078  */
0079 #define IP_ADDR_ANY         ((struct ip_addr *)&ip_addr_any)
0080 #define IP_ADDR_BROADCAST   ((struct ip_addr *)&ip_addr_broadcast)
0081 
0082 /* Definitions of the bits in an Internet address integer.
0083 
0084    On subnets, host and network parts are found according to
0085    the subnet mask, not these masks.  */
0086 
0087 #define IN_CLASSA(a)        ((((u32_t)(a)) & 0x80000000UL) == 0)
0088 #define IN_CLASSA_NET       0xff000000
0089 #define IN_CLASSA_NSHIFT    24
0090 #define IN_CLASSA_HOST      (0xffffffff & ~IN_CLASSA_NET)
0091 #define IN_CLASSA_MAX       128
0092 
0093 #define IN_CLASSB(a)        ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
0094 #define IN_CLASSB_NET       0xffff0000
0095 #define IN_CLASSB_NSHIFT    16
0096 #define IN_CLASSB_HOST      (0xffffffff & ~IN_CLASSB_NET)
0097 #define IN_CLASSB_MAX       65536
0098 
0099 #define IN_CLASSC(a)        ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
0100 #define IN_CLASSC_NET       0xffffff00
0101 #define IN_CLASSC_NSHIFT    8
0102 #define IN_CLASSC_HOST      (0xffffffff & ~IN_CLASSC_NET)
0103 
0104 #define IN_CLASSD(a)        (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
0105 #define IN_CLASSD_NET       0xf0000000          /* These ones aren't really */
0106 #define IN_CLASSD_NSHIFT    28                  /*   net and host fields, but */
0107 #define IN_CLASSD_HOST      0x0fffffff          /*   routing needn't know. */
0108 #define IN_MULTICAST(a)     IN_CLASSD(a)
0109 
0110 #define IN_EXPERIMENTAL(a)  (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
0111 #define IN_BADCLASS(a)      (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
0112 
0113 #define IN_LOOPBACKNET      127                 /* official! */
0114 
0115 #define IP4_ADDR(ipaddr, a,b,c,d) \
0116         (ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \
0117                                ((u32_t)((b) & 0xff) << 16) | \
0118                                ((u32_t)((c) & 0xff) << 8) | \
0119                                 (u32_t)((d) & 0xff))
0120 
0121 #define ip_addr_set(dest, src) (dest)->addr = \
0122                                ((src) == NULL? 0:\
0123                                (src)->addr)
0124 /**
0125  * Determine if two address are on the same network.
0126  *
0127  * @arg addr1 IP address 1
0128  * @arg addr2 IP address 2
0129  * @arg mask network identifier mask
0130  * @return !0 if the network identifiers of both address match
0131  */
0132 #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
0133                                               (mask)->addr) == \
0134                                              ((addr2)->addr & \
0135                                               (mask)->addr))
0136 #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
0137 
0138 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
0139 
0140 u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *);
0141 
0142 #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000UL)) == ntohl(0xe0000000UL))
0143 
0144 #define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL))
0145 
0146 #define ip_addr_debug_print(debug, ipaddr) \
0147   LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F,              \
0148                       ipaddr != NULL ?                                  \
0149                       (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0,  \
0150                       ipaddr != NULL ?                                  \
0151                       (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0,  \
0152                       ipaddr != NULL ?                                  \
0153                       (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0,   \
0154                       ipaddr != NULL ?                                  \
0155                       (u16_t)ntohl((ipaddr)->addr) & 0xff : 0))
0156 
0157 /* These are cast to u16_t, with the intent that they are often arguments
0158  * to printf using the U16_F format from cc.h. */
0159 #define ip4_addr1(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)
0160 #define ip4_addr2(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)
0161 #define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
0162 #define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff)
0163 
0164 /**
0165  * Same as inet_ntoa() but takes a struct ip_addr*
0166  */
0167 #define ip_ntoa(addr)  ((addr != NULL) ? inet_ntoa(*((struct in_addr*)(addr))) : "NULL")
0168 
0169 #ifdef __cplusplus
0170 }
0171 #endif
0172 
0173 #endif /* __LWIP_IP_ADDR_H__ */