Cleanly separate the portability file inet.h and its contents from the stack: moved htonX- functions to def.h (and the new def.c - they are not ipv4 dependent), let inet.h depend on ip_addr.h and not the other way round. This fixes bug #28732.

This commit is contained in:
goldsimon 2010-01-29 08:20:32 +00:00
parent 32c16fad42
commit 5fa0347e64
25 changed files with 450 additions and 346 deletions

View File

@ -56,6 +56,14 @@ HISTORY
++ Bugfixes: ++ Bugfixes:
2010-01-29: Simon Goldschmidt
* ip_addr.h, inet.h, def.h, inet.c, def.c, more: Cleanly separate the
portability file inet.h and its contents from the stack: moved htonX-
functions to def.h (and the new def.c - they are not ipv4 dependent),
let inet.h depend on ip_addr.h and not the other way round.
This fixes bug #28732.
2010-01-28: Kieran Mansley 2010-01-28: Kieran Mansley
* tcp.c: Ensure ssthresh >= 2*MSS * tcp.c: Ensure ssthresh >= 2*MSS

View File

@ -296,7 +296,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
} }
} else { } else {
/* service location specified, use loopback address */ /* service location specified, use loopback address */
addr.addr = htonl(INADDR_LOOPBACK); addr.addr = htonl(IPADDR_LOOPBACK);
} }
total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_in); total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_in);

108
src/core/def.c Normal file
View File

@ -0,0 +1,108 @@
/**
* @file
* Common functions used throughout the stack.
*
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmidt
*
*/
#include "lwip/opt.h"
#include "lwip/def.h"
/**
* These are reference implementations of the byte swapping functions.
* Again with the aim of being simple, correct and fully portable.
* Byte swapping is the second thing you would want to optimize. You will
* need to port it to your architecture and in your cc.h:
*
* #define LWIP_PLATFORM_BYTESWAP 1
* #define LWIP_PLATFORM_HTONS(x) <your_htons>
* #define LWIP_PLATFORM_HTONL(x) <your_htonl>
*
* Note ntohs() and ntohl() are merely references to the htonx counterparts.
*/
#if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN)
/**
* Convert an u16_t from host- to network byte order.
*
* @param n u16_t in host byte order
* @return n in network byte order
*/
u16_t
htons(u16_t n)
{
return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
}
/**
* Convert an u16_t from network- to host byte order.
*
* @param n u16_t in network byte order
* @return n in host byte order
*/
u16_t
ntohs(u16_t n)
{
return htons(n);
}
/**
* Convert an u32_t from host- to network byte order.
*
* @param n u32_t in host byte order
* @return n in network byte order
*/
u32_t
htonl(u32_t n)
{
return ((n & 0xff) << 24) |
((n & 0xff00) << 8) |
((n & 0xff0000UL) >> 8) |
((n & 0xff000000UL) >> 24);
}
/**
* Convert an u32_t from network- to host byte order.
*
* @param n u32_t in network byte order
* @return n in host byte order
*/
u32_t
ntohl(u32_t n)
{
return htonl(n);
}
#endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */

View File

@ -77,7 +77,7 @@
#include "lwip/udp.h" #include "lwip/udp.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/inet.h" #include "lwip/def.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include "lwip/dhcp.h" #include "lwip/dhcp.h"
#include "lwip/autoip.h" #include "lwip/autoip.h"

View File

@ -84,7 +84,7 @@
/** DNS server IP address */ /** DNS server IP address */
#ifndef DNS_SERVER_ADDRESS #ifndef DNS_SERVER_ADDRESS
#define DNS_SERVER_ADDRESS inet_addr("208.67.222.222") /* resolver1.opendns.com */ #define DNS_SERVER_ADDRESS ipaddr_addr("208.67.222.222") /* resolver1.opendns.com */
#endif #endif
/** DNS server port address */ /** DNS server port address */
@ -361,7 +361,7 @@ dns_init_local()
* *
* @param hostname Hostname to look for in the local host-list * @param hostname Hostname to look for in the local host-list
* @return The first IP address for the hostname in the local host-list or * @return The first IP address for the hostname in the local host-list or
* INADDR_NONE if not found. * IPADDR_NONE if not found.
*/ */
static u32_t static u32_t
dns_lookup_local(const char *hostname) dns_lookup_local(const char *hostname)
@ -382,7 +382,7 @@ dns_lookup_local(const char *hostname)
} }
} }
#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
return INADDR_NONE; return IPADDR_NONE;
} }
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
@ -461,7 +461,7 @@ dns_local_addhost(const char *hostname, const struct ip_addr *addr)
* *
* @param name the hostname to look up * @param name the hostname to look up
* @return the hostname's IP address, as u32_t (instead of struct ip_addr to * @return the hostname's IP address, as u32_t (instead of struct ip_addr to
* better check for failure: != INADDR_NONE) or INADDR_NONE if the hostname * better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname
* was not found in the cached dns_table. * was not found in the cached dns_table.
*/ */
static u32_t static u32_t
@ -472,12 +472,12 @@ dns_lookup(const char *name)
u32_t addr; u32_t addr;
#endif /* DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN) */ #endif /* DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN) */
#if DNS_LOCAL_HOSTLIST #if DNS_LOCAL_HOSTLIST
if ((addr = dns_lookup_local(name)) != INADDR_NONE) { if ((addr = dns_lookup_local(name)) != IPADDR_NONE) {
return addr; return addr;
} }
#endif /* DNS_LOCAL_HOSTLIST */ #endif /* DNS_LOCAL_HOSTLIST */
#ifdef DNS_LOOKUP_LOCAL_EXTERN #ifdef DNS_LOOKUP_LOCAL_EXTERN
if((addr = DNS_LOOKUP_LOCAL_EXTERN(name)) != INADDR_NONE) { if((addr = DNS_LOOKUP_LOCAL_EXTERN(name)) != IPADDR_NONE) {
return addr; return addr;
} }
#endif /* DNS_LOOKUP_LOCAL_EXTERN */ #endif /* DNS_LOOKUP_LOCAL_EXTERN */
@ -493,7 +493,7 @@ dns_lookup(const char *name)
} }
} }
return INADDR_NONE; return IPADDR_NONE;
} }
#if DNS_DOES_NAME_CHECK #if DNS_DOES_NAME_CHECK
@ -971,15 +971,15 @@ dns_gethostbyname(const char *hostname, struct ip_addr *addr, dns_found_callback
#if LWIP_HAVE_LOOPIF #if LWIP_HAVE_LOOPIF
if (strcmp(hostname,"localhost")==0) { if (strcmp(hostname,"localhost")==0) {
addr->addr = htonl(INADDR_LOOPBACK); addr->addr = htonl(IPADDR_LOOPBACK);
return ERR_OK; return ERR_OK;
} }
#endif /* LWIP_HAVE_LOOPIF */ #endif /* LWIP_HAVE_LOOPIF */
/* host name already in octet notation? set ip addr and return ERR_OK /* host name already in octet notation? set ip addr and return ERR_OK
* already have this address cached? */ * already have this address cached? */
if (((addr->addr = inet_addr(hostname)) != INADDR_NONE) || if (((addr->addr = ipaddr_addr(hostname)) != IPADDR_NONE) ||
((addr->addr = dns_lookup(hostname)) != INADDR_NONE)) { ((addr->addr = dns_lookup(hostname)) != IPADDR_NONE)) {
return ERR_OK; return ERR_OK;
} }

View File

@ -44,7 +44,6 @@
#if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */ #if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */
#include "lwip/icmp.h" #include "lwip/icmp.h"
#include "lwip/inet.h"
#include "lwip/inet_chksum.h" #include "lwip/inet_chksum.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/def.h" #include "lwip/def.h"

View File

@ -86,7 +86,6 @@ Steve Reynolds
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/inet.h"
#include "lwip/inet_chksum.h" #include "lwip/inet_chksum.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/icmp.h" #include "lwip/icmp.h"

View File

@ -40,239 +40,3 @@
#include "lwip/inet.h" #include "lwip/inet.h"
/* Here for now until needed in other places in lwIP */
#ifndef isprint
#define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up)
#define isprint(c) in_range(c, 0x20, 0x7f)
#define isdigit(c) in_range(c, '0', '9')
#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
#define islower(c) in_range(c, 'a', 'z')
#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
#endif
/**
* Ascii internet address interpretation routine.
* The value returned is in network order.
*
* @param cp IP address in ascii represenation (e.g. "127.0.0.1")
* @return ip address in network order
*/
u32_t
inet_addr(const char *cp)
{
struct in_addr val;
if (inet_aton(cp, &val)) {
return (val.s_addr);
}
return (INADDR_NONE);
}
/**
* Check whether "cp" is a valid ascii representation
* of an Internet address and convert to a binary address.
* Returns 1 if the address is valid, 0 if not.
* This replaces inet_addr, the return value from which
* cannot distinguish between failure and a local broadcast address.
*
* @param cp IP address in ascii represenation (e.g. "127.0.0.1")
* @param addr pointer to which to save the ip address in network order
* @return 1 if cp could be converted to addr, 0 on failure
*/
int
inet_aton(const char *cp, struct in_addr *addr)
{
u32_t val;
u8_t base;
char c;
u32_t parts[4];
u32_t *pp = parts;
c = *cp;
for (;;) {
/*
* Collect number up to ``.''.
* Values are specified as for C:
* 0x=hex, 0=octal, 1-9=decimal.
*/
if (!isdigit(c))
return (0);
val = 0;
base = 10;
if (c == '0') {
c = *++cp;
if (c == 'x' || c == 'X') {
base = 16;
c = *++cp;
} else
base = 8;
}
for (;;) {
if (isdigit(c)) {
val = (val * base) + (int)(c - '0');
c = *++cp;
} else if (base == 16 && isxdigit(c)) {
val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A'));
c = *++cp;
} else
break;
}
if (c == '.') {
/*
* Internet format:
* a.b.c.d
* a.b.c (with c treated as 16 bits)
* a.b (with b treated as 24 bits)
*/
if (pp >= parts + 3)
return (0);
*pp++ = val;
c = *++cp;
} else
break;
}
/*
* Check for trailing characters.
*/
if (c != '\0' && !isspace(c))
return (0);
/*
* Concoct the address according to
* the number of parts specified.
*/
switch (pp - parts + 1) {
case 0:
return (0); /* initial nondigit */
case 1: /* a -- 32 bits */
break;
case 2: /* a.b -- 8.24 bits */
if (val > 0xffffffUL)
return (0);
val |= parts[0] << 24;
break;
case 3: /* a.b.c -- 8.8.16 bits */
if (val > 0xffff)
return (0);
val |= (parts[0] << 24) | (parts[1] << 16);
break;
case 4: /* a.b.c.d -- 8.8.8.8 bits */
if (val > 0xff)
return (0);
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
break;
}
if (addr)
addr->s_addr = htonl(val);
return (1);
}
/**
* Convert numeric IP address into decimal dotted ASCII representation.
* returns ptr to static buffer; not reentrant!
*
* @param addr ip address in network order to convert
* @return pointer to a global static (!) buffer that holds the ASCII
* represenation of addr
*/
char *
inet_ntoa(struct in_addr addr)
{
static char str[16];
u32_t s_addr = addr.s_addr;
char inv[3];
char *rp;
u8_t *ap;
u8_t rem;
u8_t n;
u8_t i;
rp = str;
ap = (u8_t *)&s_addr;
for(n = 0; n < 4; n++) {
i = 0;
do {
rem = *ap % (u8_t)10;
*ap /= (u8_t)10;
inv[i++] = '0' + rem;
} while(*ap);
while(i--)
*rp++ = inv[i];
*rp++ = '.';
ap++;
}
*--rp = 0;
return str;
}
/**
* These are reference implementations of the byte swapping functions.
* Again with the aim of being simple, correct and fully portable.
* Byte swapping is the second thing you would want to optimize. You will
* need to port it to your architecture and in your cc.h:
*
* #define LWIP_PLATFORM_BYTESWAP 1
* #define LWIP_PLATFORM_HTONS(x) <your_htons>
* #define LWIP_PLATFORM_HTONL(x) <your_htonl>
*
* Note ntohs() and ntohl() are merely references to the htonx counterparts.
*/
#if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN)
/**
* Convert an u16_t from host- to network byte order.
*
* @param n u16_t in host byte order
* @return n in network byte order
*/
u16_t
htons(u16_t n)
{
return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
}
/**
* Convert an u16_t from network- to host byte order.
*
* @param n u16_t in network byte order
* @return n in host byte order
*/
u16_t
ntohs(u16_t n)
{
return htons(n);
}
/**
* Convert an u32_t from host- to network byte order.
*
* @param n u32_t in host byte order
* @return n in network byte order
*/
u32_t
htonl(u32_t n)
{
return ((n & 0xff) << 24) |
((n & 0xff00) << 8) |
((n & 0xff0000UL) >> 8) |
((n & 0xff000000UL) >> 24);
}
/**
* Convert an u32_t from network- to host byte order.
*
* @param n u32_t in network byte order
* @return n in host byte order
*/
u32_t
ntohl(u32_t n)
{
return htonl(n);
}
#endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */

View File

@ -39,7 +39,7 @@
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/inet_chksum.h" #include "lwip/inet_chksum.h"
#include "lwip/inet.h" #include "lwip/def.h"
#include <stddef.h> #include <stddef.h>

View File

@ -43,7 +43,6 @@
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#include "lwip/ip_frag.h" #include "lwip/ip_frag.h"
#include "lwip/inet.h"
#include "lwip/inet_chksum.h" #include "lwip/inet_chksum.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/icmp.h" #include "lwip/icmp.h"

View File

@ -38,7 +38,6 @@
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/inet.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#define IP_ADDR_ANY_VALUE 0x00000000UL #define IP_ADDR_ANY_VALUE 0x00000000UL
@ -82,3 +81,172 @@ u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif)
else else
return 0; return 0;
} }
/* Here for now until needed in other places in lwIP */
#ifndef isprint
#define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up)
#define isprint(c) in_range(c, 0x20, 0x7f)
#define isdigit(c) in_range(c, '0', '9')
#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
#define islower(c) in_range(c, 'a', 'z')
#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
#endif
/**
* Ascii internet address interpretation routine.
* The value returned is in network order.
*
* @param cp IP address in ascii represenation (e.g. "127.0.0.1")
* @return ip address in network order
*/
u32_t
ipaddr_addr(const char *cp)
{
struct ip_addr val;
if (ipaddr_aton(cp, &val)) {
return (val.addr);
}
return (IPADDR_NONE);
}
/**
* Check whether "cp" is a valid ascii representation
* of an Internet address and convert to a binary address.
* Returns 1 if the address is valid, 0 if not.
* This replaces inet_addr, the return value from which
* cannot distinguish between failure and a local broadcast address.
*
* @param cp IP address in ascii represenation (e.g. "127.0.0.1")
* @param addr pointer to which to save the ip address in network order
* @return 1 if cp could be converted to addr, 0 on failure
*/
int
ipaddr_aton(const char *cp, struct ip_addr *addr)
{
u32_t val;
u8_t base;
char c;
u32_t parts[4];
u32_t *pp = parts;
c = *cp;
for (;;) {
/*
* Collect number up to ``.''.
* Values are specified as for C:
* 0x=hex, 0=octal, 1-9=decimal.
*/
if (!isdigit(c))
return (0);
val = 0;
base = 10;
if (c == '0') {
c = *++cp;
if (c == 'x' || c == 'X') {
base = 16;
c = *++cp;
} else
base = 8;
}
for (;;) {
if (isdigit(c)) {
val = (val * base) + (int)(c - '0');
c = *++cp;
} else if (base == 16 && isxdigit(c)) {
val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A'));
c = *++cp;
} else
break;
}
if (c == '.') {
/*
* Internet format:
* a.b.c.d
* a.b.c (with c treated as 16 bits)
* a.b (with b treated as 24 bits)
*/
if (pp >= parts + 3)
return (0);
*pp++ = val;
c = *++cp;
} else
break;
}
/*
* Check for trailing characters.
*/
if (c != '\0' && !isspace(c))
return (0);
/*
* Concoct the address according to
* the number of parts specified.
*/
switch (pp - parts + 1) {
case 0:
return (0); /* initial nondigit */
case 1: /* a -- 32 bits */
break;
case 2: /* a.b -- 8.24 bits */
if (val > 0xffffffUL)
return (0);
val |= parts[0] << 24;
break;
case 3: /* a.b.c -- 8.8.16 bits */
if (val > 0xffff)
return (0);
val |= (parts[0] << 24) | (parts[1] << 16);
break;
case 4: /* a.b.c.d -- 8.8.8.8 bits */
if (val > 0xff)
return (0);
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
break;
}
if (addr)
addr->addr = htonl(val);
return (1);
}
/**
* Convert numeric IP address into decimal dotted ASCII representation.
* returns ptr to static buffer; not reentrant!
*
* @param addr ip address in network order to convert
* @return pointer to a global static (!) buffer that holds the ASCII
* represenation of addr
*/
char *
ipaddr_ntoa(struct ip_addr *addr)
{
static char str[16];
u32_t s_addr = addr->addr;
char inv[3];
char *rp;
u8_t *ap;
u8_t rem;
u8_t n;
u8_t i;
rp = str;
ap = (u8_t *)&s_addr;
for(n = 0; n < 4; n++) {
i = 0;
do {
rem = *ap % (u8_t)10;
*ap /= (u8_t)10;
inv[i++] = '0' + rem;
} while(*ap);
while(i--)
*rp++ = inv[i];
*rp++ = '.';
ap++;
}
*--rp = 0;
return str;
}

View File

@ -40,8 +40,7 @@
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/ip_frag.h" #include "lwip/ip_frag.h"
#include "lwip/ip.h" #include "lwip/def.h"
#include "lwip/inet.h"
#include "lwip/inet_chksum.h" #include "lwip/inet_chksum.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"

View File

@ -44,7 +44,6 @@
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/memp.h" #include "lwip/memp.h"
#include "lwip/inet.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/raw.h" #include "lwip/raw.h"

View File

@ -51,7 +51,6 @@
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#include "lwip/memp.h" #include "lwip/memp.h"
#include "lwip/inet.h"
#include "lwip/inet_chksum.h" #include "lwip/inet_chksum.h"
#include "lwip/stats.h" #include "lwip/stats.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"

View File

@ -49,7 +49,6 @@
#include "lwip/sys.h" #include "lwip/sys.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/inet.h"
#include "lwip/inet_chksum.h" #include "lwip/inet_chksum.h"
#include "lwip/stats.h" #include "lwip/stats.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"

View File

@ -53,7 +53,6 @@
#include "lwip/udp.h" #include "lwip/udp.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/memp.h" #include "lwip/memp.h"
#include "lwip/inet.h"
#include "lwip/inet_chksum.h" #include "lwip/inet_chksum.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/netif.h" #include "lwip/netif.h"

View File

@ -33,68 +33,66 @@
#define __LWIP_INET_H__ #define __LWIP_INET_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/ip_addr.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* For compatibility with BSD code */ /** For compatibility with BSD code */
struct in_addr { struct in_addr {
u32_t s_addr; u32_t s_addr;
}; };
#define INADDR_NONE ((u32_t)0xffffffffUL) /* 255.255.255.255 */ /** 255.255.255.255 */
#define INADDR_LOOPBACK ((u32_t)0x7f000001UL) /* 127.0.0.1 */ #define INADDR_NONE IPADDR_NONE
#define INADDR_ANY ((u32_t)0x00000000UL) /* 0.0.0.0 */ /** 127.0.0.1 */
#define INADDR_BROADCAST ((u32_t)0xffffffffUL) /* 255.255.255.255 */ #define INADDR_LOOPBACK IPADDR_LOOPBACK
/** 0.0.0.0 */
#define INADDR_ANY IPADDR_ANY
/** 255.255.255.255 */
#define INADDR_BROADCAST IPADDR_BROADCAST
u32_t inet_addr(const char *cp); /* Definitions of the bits in an Internet address integer.
int inet_aton(const char *cp, struct in_addr *addr);
char *inet_ntoa(struct in_addr addr); /* returns ptr to static buffer; not reentrant! */
#ifdef htons On subnets, host and network parts are found according to
#undef htons the subnet mask, not these masks. */
#endif /* htons */ #define IN_CLASSA(a) IP_CLASSA(a)
#ifdef htonl #define IN_CLASSA_NET IP_CLASSA_NET
#undef htonl #define IN_CLASSA_NSHIFT IP_CLASSA_NSHIFT
#endif /* htonl */ #define IN_CLASSA_HOST IP_CLASSA_HOST
#ifdef ntohs #define IN_CLASSA_MAX IP_CLASSA_MAX
#undef ntohs
#endif /* ntohs */
#ifdef ntohl
#undef ntohl
#endif /* ntohl */
#ifndef LWIP_PLATFORM_BYTESWAP #define IN_CLASSB(b) IP_CLASSB(b)
#define LWIP_PLATFORM_BYTESWAP 0 #define IN_CLASSB_NET IP_CLASSB_NET
#endif #define IN_CLASSB_NSHIFT IP_CLASSB_NSHIFT
#define IN_CLASSB_HOST IP_CLASSB_HOST
#define IN_CLASSB_MAX IP_CLASSB_MAX
#if BYTE_ORDER == BIG_ENDIAN #define IN_CLASSC(c) IP_CLASSC(c)
#define htons(x) (x) #define IN_CLASSC_NET IP_CLASSC_NET
#define ntohs(x) (x) #define IN_CLASSC_NSHIFT IP_CLASSC_NSHIFT
#define htonl(x) (x) #define IN_CLASSC_HOST IP_CLASSC_HOST
#define ntohl(x) (x) #define IN_CLASSC_MAX IP_CLASSC_MAX
#else /* BYTE_ORDER != BIG_ENDIAN */
#ifdef LWIP_PREFIX_BYTEORDER_FUNCS
/* workaround for naming collisions on some platforms */
#define htons lwip_htons
#define ntohs lwip_ntohs
#define htonl lwip_htonl
#define ntohl lwip_ntohl
#endif /* LWIP_PREFIX_BYTEORDER_FUNCS */
#if LWIP_PLATFORM_BYTESWAP
#define htons(x) LWIP_PLATFORM_HTONS(x)
#define ntohs(x) LWIP_PLATFORM_HTONS(x)
#define htonl(x) LWIP_PLATFORM_HTONL(x)
#define ntohl(x) LWIP_PLATFORM_HTONL(x)
#else /* LWIP_PLATFORM_BYTESWAP */
u16_t htons(u16_t x);
u16_t ntohs(u16_t x);
u32_t htonl(u32_t x);
u32_t ntohl(u32_t x);
#endif /* LWIP_PLATFORM_BYTESWAP */
#endif /* BYTE_ORDER == BIG_ENDIAN */ #define IN_CLASSD(d) IP_CLASSD(d)
#define IN_CLASSD_NET IP_CLASSD_NET /* These ones aren't really */
#define IN_CLASSD_NSHIFT IP_CLASSD_NSHIFT /* net and host fields, but */
#define IN_CLASSD_HOST IP_CLASSD_HOST /* routing needn't know. */
#define IN_CLASSD_MAX IP_CLASSD_MAX
#define IN_MULTICAST(a) IP_MULTICAST(a)
#define IN_EXPERIMENTAL(a) IP_EXPERIMENTAL(a)
#define IN_BADCLASS(a) IP_BADCLASS(a)
#define IN_LOOPBACKNET IP_LOOPBACKNET
/* directly map this to the lwip internal functions */
#define inet_addr(cp) ipaddr_addr(cp)
#define inet_aton(cp, addr) ipaddr_aton(cp, (struct ip_addr*)addr)
#define inet_ntoa(addr) ipaddr_ntoa((struct ip_addr*)&(addr))
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -33,8 +33,7 @@
#define __LWIP_IP_ADDR_H__ #define __LWIP_IP_ADDR_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/inet.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -79,38 +78,47 @@ extern const struct ip_addr ip_addr_broadcast;
#define IP_ADDR_ANY ((struct ip_addr *)&ip_addr_any) #define IP_ADDR_ANY ((struct ip_addr *)&ip_addr_any)
#define IP_ADDR_BROADCAST ((struct ip_addr *)&ip_addr_broadcast) #define IP_ADDR_BROADCAST ((struct ip_addr *)&ip_addr_broadcast)
/** 255.255.255.255 */
#define IPADDR_NONE ((u32_t)0xffffffffUL)
/** 127.0.0.1 */
#define IPADDR_LOOPBACK ((u32_t)0x7f000001UL)
/** 0.0.0.0 */
#define IPADDR_ANY ((u32_t)0x00000000UL)
/** 255.255.255.255 */
#define IPADDR_BROADCAST ((u32_t)0xffffffffUL)
/* Definitions of the bits in an Internet address integer. /* Definitions of the bits in an Internet address integer.
On subnets, host and network parts are found according to On subnets, host and network parts are found according to
the subnet mask, not these masks. */ the subnet mask, not these masks. */
#define IP_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0)
#define IP_CLASSA_NET 0xff000000
#define IP_CLASSA_NSHIFT 24
#define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET)
#define IP_CLASSA_MAX 128
#define IN_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0) #define IP_CLASSB(a) ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
#define IN_CLASSA_NET 0xff000000 #define IP_CLASSB_NET 0xffff0000
#define IN_CLASSA_NSHIFT 24 #define IP_CLASSB_NSHIFT 16
#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) #define IP_CLASSB_HOST (0xffffffff & ~IP_CLASSB_NET)
#define IN_CLASSA_MAX 128 #define IP_CLASSB_MAX 65536
#define IN_CLASSB(a) ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL) #define IP_CLASSC(a) ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
#define IN_CLASSB_NET 0xffff0000 #define IP_CLASSC_NET 0xffffff00
#define IN_CLASSB_NSHIFT 16 #define IP_CLASSC_NSHIFT 8
#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) #define IP_CLASSC_HOST (0xffffffff & ~IP_CLASSC_NET)
#define IN_CLASSB_MAX 65536
#define IN_CLASSC(a) ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL) #define IP_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
#define IN_CLASSC_NET 0xffffff00 #define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */
#define IN_CLASSC_NSHIFT 8 #define IP_CLASSD_NSHIFT 28 /* net and host fields, but */
#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) #define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */
#define IP_MULTICAST(a) IP_CLASSD(a)
#define IN_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL) #define IP_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ #define IP_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
#define IN_MULTICAST(a) IN_CLASSD(a)
#define IN_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL) #define IP_LOOPBACKNET 127 /* official! */
#define IN_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
#define IN_LOOPBACKNET 127 /* official! */
#define IP4_ADDR(ipaddr, a,b,c,d) \ #define IP4_ADDR(ipaddr, a,b,c,d) \
(ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \ (ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \
@ -161,10 +169,13 @@ u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *);
#define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff) #define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
#define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff) #define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff)
/** /** For backwards compatibility */
* Same as inet_ntoa() but takes a struct ip_addr* #define ip_ntoa(addr) ipaddr_ntoa(addr)
*/
#define ip_ntoa(addr) ((addr != NULL) ? inet_ntoa(*((struct in_addr*)(addr))) : "NULL") u32_t ipaddr_addr(const char *cp);
int ipaddr_aton(const char *cp, struct ip_addr *addr);
/** returns ptr to static buffer; not reentrant! */
char *ipaddr_ntoa(struct ip_addr *addr);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -32,8 +32,13 @@
#ifndef __LWIP_DEF_H__ #ifndef __LWIP_DEF_H__
#define __LWIP_DEF_H__ #define __LWIP_DEF_H__
/* this might define NULL already */ /* arch.h might define NULL already */
#include "lwip/arch.h" #include "lwip/arch.h"
#include "lwip/opt.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y)) #define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y))
#define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y)) #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y))
@ -42,6 +47,53 @@
#define NULL ((void *)0) #define NULL ((void *)0)
#endif #endif
#ifdef htons
#undef htons
#endif /* htons */
#ifdef htonl
#undef htonl
#endif /* htonl */
#ifdef ntohs
#undef ntohs
#endif /* ntohs */
#ifdef ntohl
#undef ntohl
#endif /* ntohl */
#ifndef LWIP_PLATFORM_BYTESWAP
#define LWIP_PLATFORM_BYTESWAP 0
#endif
#if BYTE_ORDER == BIG_ENDIAN
#define htons(x) (x)
#define ntohs(x) (x)
#define htonl(x) (x)
#define ntohl(x) (x)
#else /* BYTE_ORDER != BIG_ENDIAN */
#ifdef LWIP_PREFIX_BYTEORDER_FUNCS
/* workaround for naming collisions on some platforms */
#define htons lwip_htons
#define ntohs lwip_ntohs
#define htonl lwip_htonl
#define ntohl lwip_ntohl
#endif /* LWIP_PREFIX_BYTEORDER_FUNCS */
#if LWIP_PLATFORM_BYTESWAP
#define htons(x) LWIP_PLATFORM_HTONS(x)
#define ntohs(x) LWIP_PLATFORM_HTONS(x)
#define htonl(x) LWIP_PLATFORM_HTONL(x)
#define ntohl(x) LWIP_PLATFORM_HTONL(x)
#else /* LWIP_PLATFORM_BYTESWAP */
u16_t htons(u16_t x);
u16_t ntohs(u16_t x);
u32_t htonl(u32_t x);
u32_t ntohl(u32_t x);
#endif /* LWIP_PLATFORM_BYTESWAP */
#endif /* BYTE_ORDER == BIG_ENDIAN */
#ifdef __cplusplus
}
#endif
#endif /* __LWIP_DEF_H__ */ #endif /* __LWIP_DEF_H__ */

View File

@ -40,7 +40,7 @@
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/inet.h" #include "lwip/def.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#if LWIP_DHCP #if LWIP_DHCP
struct dhcp; struct dhcp;

View File

@ -37,7 +37,7 @@
#if LWIP_RAW /* don't build if not configured for use in lwipopts.h */ #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/inet.h" #include "lwip/def.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"

View File

@ -47,7 +47,8 @@
#if LWIP_ARP || LWIP_ETHERNET #if LWIP_ARP || LWIP_ETHERNET
#include "lwip/inet.h" #include "lwip/ip_addr.h"
#include "lwip/def.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/stats.h" #include "lwip/stats.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"

View File

@ -82,6 +82,8 @@
#include "cbcp.h" #include "cbcp.h"
#endif /* CBCP_SUPPORT */ #endif /* CBCP_SUPPORT */
#include "lwip/inet.h"
#include <string.h> #include <string.h>
#if 0 /* UNUSED */ #if 0 /* UNUSED */

View File

@ -63,6 +63,8 @@
#include "vj.h" #include "vj.h"
#include "ipcp.h" #include "ipcp.h"
#include "lwip/inet.h"
#include <string.h> #include <string.h>
/* #define OLD_CI_ADDRS 1 */ /* Support deprecated address negotiation. */ /* #define OLD_CI_ADDRS 1 */ /* Support deprecated address negotiation. */
@ -166,8 +168,6 @@ static void ipcp_clear_addrs (int);
(x) == CONFNAK ? "NAK" : "REJ") (x) == CONFNAK ? "NAK" : "REJ")
#define inet_ntoa(addr) ip_ntoa(((struct ip_addr*)&(addr)))
/* /*
* ipcp_init - Initialize IPCP. * ipcp_init - Initialize IPCP.
*/ */

View File

@ -1249,12 +1249,12 @@ GetMask(u32_t addr)
u32_t mask, nmask; u32_t mask, nmask;
htonl(addr); htonl(addr);
if (IN_CLASSA(addr)) { /* determine network mask for address class */ if (IP_CLASSA(addr)) { /* determine network mask for address class */
nmask = IN_CLASSA_NET; nmask = IP_CLASSA_NET;
} else if (IN_CLASSB(addr)) { } else if (IP_CLASSB(addr)) {
nmask = IN_CLASSB_NET; nmask = IP_CLASSB_NET;
} else { } else {
nmask = IN_CLASSC_NET; nmask = IP_CLASSC_NET;
} }
/* class D nets are disallowed by bad_ip_adrs */ /* class D nets are disallowed by bad_ip_adrs */