ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

ip_addr.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without modification,
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  *
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 #ifndef __LWIP_IP_ADDR_H__
00033 #define __LWIP_IP_ADDR_H__
00034 
00035 #include "lwip/opt.h"
00036 #include "lwip/def.h"
00037 
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00042 /* This is the aligned version of ip_addr_t,
00043    used as local variable, on the stack, etc. */
00044 struct ip_addr {
00045   u32_t addr;
00046 };
00047 
00048 /* This is the packed version of ip_addr_t,
00049    used in network headers that are itself packed */
00050 #ifdef PACK_STRUCT_USE_INCLUDES
00051 #  include "arch/bpstruct.h"
00052 #endif
00053 PACK_STRUCT_BEGIN
00054 struct ip_addr_packed {
00055   PACK_STRUCT_FIELD(u32_t addr);
00056 } PACK_STRUCT_STRUCT;
00057 PACK_STRUCT_END
00058 #ifdef PACK_STRUCT_USE_INCLUDES
00059 #  include "arch/epstruct.h"
00060 #endif
00061 
00064 typedef struct ip_addr ip_addr_t;
00065 typedef struct ip_addr_packed ip_addr_p_t;
00066 
00067 /*
00068  * struct ipaddr2 is used in the definition of the ARP packet format in
00069  * order to support compilers that don't have structure packing.
00070  */
00071 #ifdef PACK_STRUCT_USE_INCLUDES
00072 #  include "arch/bpstruct.h"
00073 #endif
00074 PACK_STRUCT_BEGIN
00075 struct ip_addr2 {
00076   PACK_STRUCT_FIELD(u16_t addrw[2]);
00077 } PACK_STRUCT_STRUCT;
00078 PACK_STRUCT_END
00079 #ifdef PACK_STRUCT_USE_INCLUDES
00080 #  include "arch/epstruct.h"
00081 #endif
00082 
00083 /* Forward declaration to not include netif.h */
00084 struct netif;
00085 
00086 extern const ip_addr_t ip_addr_any;
00087 extern const ip_addr_t ip_addr_broadcast;
00088 
00092 #define IP_ADDR_ANY         ((ip_addr_t *)&ip_addr_any)
00093 #define IP_ADDR_BROADCAST   ((ip_addr_t *)&ip_addr_broadcast)
00094 
00096 #define IPADDR_NONE         ((u32_t)0xffffffffUL)
00097 
00098 #define IPADDR_LOOPBACK     ((u32_t)0x7f000001UL)
00099 
00100 #define IPADDR_ANY          ((u32_t)0x00000000UL)
00101 
00102 #define IPADDR_BROADCAST    ((u32_t)0xffffffffUL)
00103 
00104 /* Definitions of the bits in an Internet address integer.
00105 
00106    On subnets, host and network parts are found according to
00107    the subnet mask, not these masks.  */
00108 #define IP_CLASSA(a)        ((((u32_t)(a)) & 0x80000000UL) == 0)
00109 #define IP_CLASSA_NET       0xff000000
00110 #define IP_CLASSA_NSHIFT    24
00111 #define IP_CLASSA_HOST      (0xffffffff & ~IP_CLASSA_NET)
00112 #define IP_CLASSA_MAX       128
00113 
00114 #define IP_CLASSB(a)        ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
00115 #define IP_CLASSB_NET       0xffff0000
00116 #define IP_CLASSB_NSHIFT    16
00117 #define IP_CLASSB_HOST      (0xffffffff & ~IP_CLASSB_NET)
00118 #define IP_CLASSB_MAX       65536
00119 
00120 #define IP_CLASSC(a)        ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
00121 #define IP_CLASSC_NET       0xffffff00
00122 #define IP_CLASSC_NSHIFT    8
00123 #define IP_CLASSC_HOST      (0xffffffff & ~IP_CLASSC_NET)
00124 
00125 #define IP_CLASSD(a)        (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
00126 #define IP_CLASSD_NET       0xf0000000          /* These ones aren't really */
00127 #define IP_CLASSD_NSHIFT    28                  /*   net and host fields, but */
00128 #define IP_CLASSD_HOST      0x0fffffff          /*   routing needn't know. */
00129 #define IP_MULTICAST(a)     IP_CLASSD(a)
00130 
00131 #define IP_EXPERIMENTAL(a)  (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
00132 #define IP_BADCLASS(a)      (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
00133 
00134 #define IP_LOOPBACKNET      127                 /* official! */
00135 
00136 
00137 #if BYTE_ORDER == BIG_ENDIAN
00138 
00139 #define IP4_ADDR(ipaddr, a,b,c,d) \
00140         (ipaddr)->addr = ((u32_t)((a) & 0xff) << 24) | \
00141                          ((u32_t)((b) & 0xff) << 16) | \
00142                          ((u32_t)((c) & 0xff) << 8)  | \
00143                           (u32_t)((d) & 0xff)
00144 #else
00145 
00147 #define IP4_ADDR(ipaddr, a,b,c,d) \
00148         (ipaddr)->addr = ((u32_t)((d) & 0xff) << 24) | \
00149                          ((u32_t)((c) & 0xff) << 16) | \
00150                          ((u32_t)((b) & 0xff) << 8)  | \
00151                           (u32_t)((a) & 0xff)
00152 #endif
00153 
00157 #ifndef IPADDR2_COPY
00158 #define IPADDR2_COPY(dest, src) SMEMCPY(dest, src, sizeof(ip_addr_t))
00159 #endif
00160 
00162 #define ip_addr_copy(dest, src) ((dest).addr = (src).addr)
00163 
00164 #define ip_addr_set(dest, src) ((dest)->addr = \
00165                                     ((src) == NULL ? 0 : \
00166                                     (src)->addr))
00167 
00168 #define ip_addr_set_zero(ipaddr)      ((ipaddr)->addr = 0)
00169 
00170 #define ip_addr_set_any(ipaddr)       ((ipaddr)->addr = IPADDR_ANY)
00171 
00172 #define ip_addr_set_loopback(ipaddr)  ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
00173 
00175 #define ip_addr_set_hton(dest, src) ((dest)->addr = \
00176                                ((src) == NULL ? 0:\
00177                                htonl((src)->addr)))
00178 
00179 #define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
00180 
00181 #define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
00182 
00184 #define ip_addr_get_network(target, host, netmask) ((target)->addr = ((host)->addr) & ((netmask)->addr))
00185 
00194 #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
00195                                               (mask)->addr) == \
00196                                              ((addr2)->addr & \
00197                                               (mask)->addr))
00198 #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
00199 
00200 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
00201 
00202 #define ip_addr_isbroadcast(ipaddr, netif) ip4_addr_isbroadcast((ipaddr)->addr, (netif))
00203 u8_t ip4_addr_isbroadcast(u32_t addr, const struct netif *netif);
00204 
00205 #define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
00206 u8_t ip4_addr_netmask_valid(u32_t netmask);
00207 
00208 #define ip_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
00209 
00210 #define ip_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
00211 
00212 #define ip_addr_debug_print(debug, ipaddr) \
00213   LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F,             \
00214                       ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0,       \
00215                       ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0,       \
00216                       ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0,       \
00217                       ipaddr != NULL ? ip4_addr4_16(ipaddr) : 0))
00218 
00219 /* Get one byte from the 4-byte address */
00220 #define ip4_addr1(ipaddr) (((u8_t*)(ipaddr))[0])
00221 #define ip4_addr2(ipaddr) (((u8_t*)(ipaddr))[1])
00222 #define ip4_addr3(ipaddr) (((u8_t*)(ipaddr))[2])
00223 #define ip4_addr4(ipaddr) (((u8_t*)(ipaddr))[3])
00224 /* These are cast to u16_t, with the intent that they are often arguments
00225  * to printf using the U16_F format from cc.h. */
00226 #define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
00227 #define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr))
00228 #define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr))
00229 #define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr))
00230 
00232 #define ip_ntoa(ipaddr)  ipaddr_ntoa(ipaddr)
00233 
00234 u32_t ipaddr_addr(const char *cp);
00235 int ipaddr_aton(const char *cp, ip_addr_t *addr);
00237 char *ipaddr_ntoa(const ip_addr_t *addr);
00238 char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen);
00239 
00240 #ifdef __cplusplus
00241 }
00242 #endif
00243 
00244 #endif /* __LWIP_IP_ADDR_H__ */

Generated on Sat May 26 2012 04:34:59 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.