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_INET_H__ 33 #define __LWIP_INET_H__ 34 35 #include "lwip/opt.h" 36 #include "lwip/def.h" 37 #include "lwip/ip_addr.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /** For compatibility with BSD code */ 44 #include <netinet/in.h> 45 46 /** 255.255.255.255 */ 47 #define INADDR_NONE IPADDR_NONE 48 /** 127.0.0.1 */ 49 #define INADDR_LOOPBACK IPADDR_LOOPBACK 50 /** 0.0.0.0 */ 51 #define INADDR_ANY IPADDR_ANY 52 /** 255.255.255.255 */ 53 #define INADDR_BROADCAST IPADDR_BROADCAST 54 55 /* Definitions of the bits in an Internet address integer. 56 57 On subnets, host and network parts are found according to 58 the subnet mask, not these masks. */ 59 #define IN_CLASSA(a) IP_CLASSA(a) 60 #define IN_CLASSA_NET IP_CLASSA_NET 61 #define IN_CLASSA_NSHIFT IP_CLASSA_NSHIFT 62 #define IN_CLASSA_HOST IP_CLASSA_HOST 63 #define IN_CLASSA_MAX IP_CLASSA_MAX 64 65 #define IN_CLASSB(b) IP_CLASSB(b) 66 #define IN_CLASSB_NET IP_CLASSB_NET 67 #define IN_CLASSB_NSHIFT IP_CLASSB_NSHIFT 68 #define IN_CLASSB_HOST IP_CLASSB_HOST 69 #define IN_CLASSB_MAX IP_CLASSB_MAX 70 71 #define IN_CLASSC(c) IP_CLASSC(c) 72 #define IN_CLASSC_NET IP_CLASSC_NET 73 #define IN_CLASSC_NSHIFT IP_CLASSC_NSHIFT 74 #define IN_CLASSC_HOST IP_CLASSC_HOST 75 #define IN_CLASSC_MAX IP_CLASSC_MAX 76 77 #define IN_CLASSD(d) IP_CLASSD(d) 78 #define IN_CLASSD_NET IP_CLASSD_NET /* These ones aren't really */ 79 #define IN_CLASSD_NSHIFT IP_CLASSD_NSHIFT /* net and host fields, but */ 80 #define IN_CLASSD_HOST IP_CLASSD_HOST /* routing needn't know. */ 81 #define IN_CLASSD_MAX IP_CLASSD_MAX 82 83 #define IN_MULTICAST(a) IP_MULTICAST(a) 84 85 #define IN_EXPERIMENTAL(a) IP_EXPERIMENTAL(a) 86 #define IN_BADCLASS(a) IP_BADCLASS(a) 87 88 #define IN_LOOPBACKNET IP_LOOPBACKNET 89 90 #define inet_addr_from_ipaddr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) 91 #define inet_addr_to_ipaddr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr)) 92 /* ATTENTION: the next define only works because both s_addr and ip_addr_t are an u32_t effectively! */ 93 #define inet_addr_to_ipaddr_p(target_ipaddr_p, source_inaddr) ((target_ipaddr_p) = (ip_addr_t*)&((source_inaddr)->s_addr)) 94 95 /* directly map this to the lwip internal functions */ 96 #define inet_addr(cp) ipaddr_addr(cp) 97 #define inet_aton(cp, addr) ipaddr_aton(cp, (ip_addr_t*)addr) 98 #define inet_ntoa(addr) ipaddr_ntoa((ip_addr_t*)&(addr)) 99 #define inet_ntoa_r(addr, buf, buflen) ipaddr_ntoa_r((ip_addr_t*)&(addr), buf, buflen) 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 #endif /* __LWIP_INET_H__ */ 106