Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

ip_addr.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2003 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  * CHANGELOG: this file has been modified by Sergio Perez Alcañiz <serpeal@disca.upv.es> 
00032  *            Departamento de Informática de Sistemas y Computadores          
00033  *            Universidad Politécnica de Valencia                             
00034  *            Valencia (Spain)    
00035  *            Date: April 2003                                          
00036  *
00037  */
00038 #ifndef __LWIP_IP_ADDR_H__
00039 #define __LWIP_IP_ADDR_H__
00040 
00041 #include "lwip/arch.h"
00042 
00043 #define IP_ADDR_ANY (&ip_addr_any)
00044 #define IP_ADDR_BROADCAST (&ip_addr_broadcast)
00045 
00046 #define INADDR_NONE             ((u32_t) 0xffffffff)    /* 255.255.255.255 */
00047 #define INADDR_LOOPBACK         ((u32_t) 0x7f000001)    /* 127.0.0.1 */
00048 
00049 /* Definitions of the bits in an Internet address integer.
00050 
00051    On subnets, host and network parts are found according to
00052    the subnet mask, not these masks.  */
00053 
00054 #define IN_CLASSA(a)            ((((u32_t)(a)) & 0x80000000) == 0)
00055 #define IN_CLASSA_NET           0xff000000
00056 #define IN_CLASSA_NSHIFT        24
00057 #define IN_CLASSA_HOST          (0xffffffff & ~IN_CLASSA_NET)
00058 #define IN_CLASSA_MAX           128
00059 
00060 #define IN_CLASSB(a)            ((((u32_t)(a)) & 0xc0000000) == 0x80000000)
00061 #define IN_CLASSB_NET           0xffff0000
00062 #define IN_CLASSB_NSHIFT        16
00063 #define IN_CLASSB_HOST          (0xffffffff & ~IN_CLASSB_NET)
00064 #define IN_CLASSB_MAX           65536
00065 
00066 #define IN_CLASSC(a)            ((((u32_t)(a)) & 0xe0000000) == 0xc0000000)
00067 #define IN_CLASSC_NET           0xffffff00
00068 #define IN_CLASSC_NSHIFT        8
00069 #define IN_CLASSC_HOST          (0xffffffff & ~IN_CLASSC_NET)
00070 
00071 #define IN_CLASSD(a)        (((u32_t)(a) & 0xf0000000) == 0xe0000000)
00072 #define IN_CLASSD_NET       0xf0000000  /* These ones aren't really */
00073 #define IN_CLASSD_NSHIFT    28      /* net and host fields, but */
00074 #define IN_CLASSD_HOST      0x0fffffff  /* routing needn't know.    */
00075 #define IN_MULTICAST(a)     IN_CLASSD(a)
00076 
00077 #define IN_EXPERIMENTAL(a)  (((u32_t)(a) & 0xf0000000) == 0xf0000000)
00078 #define IN_BADCLASS(a)      (((u32_t)(a) & 0xf0000000) == 0xf0000000)
00079 
00080 #define IN_LOOPBACKNET      127         /* official! */
00081 
00082 #ifdef PACK_STRUCT_USE_INCLUDES
00083 #  include "arch/bpstruct.h"
00084 #endif
00085 PACK_STRUCT_BEGIN
00086 struct ip_addr {
00087   PACK_STRUCT_FIELD(u32_t addr);
00088 } PACK_STRUCT_STRUCT;
00089 PACK_STRUCT_END
00090 #ifdef PACK_STRUCT_USE_INCLUDES
00091 #  include "arch/epstruct.h"
00092 #endif
00093 
00094 /* For compatibility with BSD code */
00095 struct in_addr {
00096           u32_t s_addr;
00097 };
00098 
00099 extern struct ip_addr ip_addr_any;
00100 extern struct ip_addr ip_addr_broadcast;
00101 
00102 #define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = htonl(((u32_t)(a & 0xff) << 24) | ((u32_t)(b & 0xff) << 16) | \
00103                                                          ((u32_t)(c & 0xff) << 8) | (u32_t)(d & 0xff))
00104 
00105 #define ip_addr_set(dest, src) (dest)->addr = ((struct ip_addr *)src)->addr
00106 #define ip_addr_maskcmp(addr1, addr2, mask) (((addr1)->addr & \
00107                                               (mask)->addr) == \
00108                                              ((addr2)->addr & \
00109                                               (mask)->addr))
00110 #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
00111 
00112 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
00113 
00114 #define ip_addr_isbroadcast(addr1, mask) (((((addr1)->addr) & ~((mask)->addr)) == \
00115                                          (0xffffffff & ~((mask)->addr))) || \
00116                                          ((addr1)->addr == 0xffffffff) || \
00117                                          ((addr1)->addr == 0x00000000))
00118 
00119 
00120 #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000))
00121                                    
00122 
00123 #define ip_addr_debug_print(ipaddr) DEBUGF(LWIP_DEBUG, ("%d.%d.%d.%d", \
00124                     (u8_t)(ntohl((ipaddr)->addr) >> 24) & 0xff, \
00125                     (u8_t)(ntohl((ipaddr)->addr) >> 16) & 0xff, \
00126                     (u8_t)(ntohl((ipaddr)->addr) >> 8) & 0xff, \
00127                     (u8_t)ntohl((ipaddr)->addr) & 0xff))
00128 
00129 
00130 #define ip4_addr1(ipaddr) ((u8_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)
00131 #define ip4_addr2(ipaddr) ((u8_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)
00132 #define ip4_addr3(ipaddr) ((u8_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
00133 #define ip4_addr4(ipaddr) ((u8_t)(ntohl((ipaddr)->addr)) & 0xff)
00134 
00135 void string2ip_addr(struct ip_addr *ip, char *name, int size);
00136 
00137 #endif /* __LWIP_IP_ADDR_H__ */
00138 
00139 
00140 
00141 
00142 
00143 

Generated on Wed Jan 14 12:58:56 2004 for RTL-lwIP-0.4 by doxygen 1.3.4