2007-09-01 20:06:15 +02:00
|
|
|
/****************************************************************************
|
2007-11-22 19:36:46 +01:00
|
|
|
* net/uip/uip.h
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-22 19:36:46 +01:00
|
|
|
* The uIP header file contains definitions for a number of C macros that
|
|
|
|
* are used by uIP programs as well as internal uIP structures and function
|
|
|
|
* declarations.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2008-09-01 15:59:54 +02:00
|
|
|
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
2007-09-01 20:06:15 +02:00
|
|
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
|
|
|
*
|
|
|
|
* This logic was leveraged from uIP which also has a BSD-style license:
|
|
|
|
*
|
|
|
|
* Author Adam Dunkels <adam@dunkels.com>
|
|
|
|
* Copyright (c) 2001-2003, Adam Dunkels.
|
|
|
|
* All rights reserved.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
2007-11-22 19:36:46 +01:00
|
|
|
*
|
2007-08-27 01:12:17 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#ifndef __NET_UIP_UIP_H
|
|
|
|
#define __NET_UIP_UIP_H
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2007-11-22 19:36:46 +01:00
|
|
|
|
2007-09-03 22:34:44 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <queue.h>
|
2007-09-02 17:32:03 +02:00
|
|
|
#include <arpa/inet.h>
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
#include <net/uip/uipopt.h>
|
2008-09-01 15:59:54 +02:00
|
|
|
|
2007-08-27 01:12:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-11-08 17:01:18 +01:00
|
|
|
/* The following flags may be set in the set of flags before calling the
|
|
|
|
* application callback. The UIP_ACKDATA, UIP_NEWDATA, and UIP_CLOSE flags
|
|
|
|
* may be set at the same time, whereas the others are mutualy exclusive.
|
2008-09-01 15:59:54 +02:00
|
|
|
*
|
|
|
|
* UIP_ACKDATA IN: Signifies that the outstanding data was acked and
|
|
|
|
* the application should send out new data instead
|
2008-09-01 17:22:54 +02:00
|
|
|
* of retransmitting the last data (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* OUT: Input state must be preserved on output.
|
|
|
|
* UIP_NEWDATA IN: Set to indicate that the peer has sent us new data.
|
|
|
|
* OUT: Cleared (only) by the application logic to indicate
|
|
|
|
* that the new data was consumed, suppressing further
|
|
|
|
* attempts to process the new data.
|
|
|
|
* UIP_SNDACK IN: Not used; always zero
|
|
|
|
* OUT: Set by the application if the new data was consumed
|
2008-09-01 17:22:54 +02:00
|
|
|
* and an ACK should be sent in the response. (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* UIP_REXMIT IN: Tells the application to retransmit the data that
|
2008-09-01 17:22:54 +02:00
|
|
|
* was last sent. (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* OUT: Not used
|
|
|
|
* UIP_POLL IN: Used for polling the application. This is provided
|
|
|
|
* periodically from the drivers to support (1) timed
|
|
|
|
* operations, and (2) to check if the application has
|
2008-11-20 20:24:06 +01:00
|
|
|
* data that it wants to send
|
|
|
|
* OUT: Not used
|
|
|
|
* UIP_BACKLOG IN: There is a new connection in the backlog list set
|
|
|
|
* up by the listen() command. (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* OUT: Not used
|
|
|
|
* UIP_CLOSE IN: The remote host has closed the connection, thus the
|
2008-09-01 17:22:54 +02:00
|
|
|
* connection has gone away. (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* OUT: The application signals that it wants to close the
|
2008-09-01 17:22:54 +02:00
|
|
|
* connection. (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* UIP_ABORT IN: The remote host has aborted the connection, thus the
|
2008-09-01 17:22:54 +02:00
|
|
|
* connection has gone away. (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* OUT: The application signals that it wants to abort the
|
2008-09-01 17:22:54 +02:00
|
|
|
* connection. (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* UIP_CONNECTED IN: We have got a connection from a remote host and have
|
|
|
|
* set up a new connection for it, or an active connection
|
2008-09-01 17:22:54 +02:00
|
|
|
* has been successfully established. (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* OUT: Not used
|
|
|
|
* UIP_TIMEDOUT IN: The connection has been aborted due to too many
|
2008-09-01 17:22:54 +02:00
|
|
|
* retransmissions. (TCP only)
|
2008-09-01 15:59:54 +02:00
|
|
|
* OUT: Not used
|
2008-09-02 22:42:01 +02:00
|
|
|
* UIP_ECHOREPLY IN: An ICMP Echo Reply has been received. Used to support
|
|
|
|
* ICMP ping from applications. (ICMP only)
|
|
|
|
* OUT: Cleared (only) by the application logic to indicate
|
|
|
|
* that the reply was processed, suppressing further
|
|
|
|
* attempts to process the reply.
|
2007-08-27 01:12:17 +02:00
|
|
|
*/
|
|
|
|
|
2008-09-01 15:59:54 +02:00
|
|
|
#define UIP_ACKDATA (1 << 0)
|
|
|
|
#define UIP_NEWDATA (1 << 1)
|
|
|
|
#define UIP_SNDACK (1 << 2)
|
|
|
|
#define UIP_REXMIT (1 << 3)
|
|
|
|
#define UIP_POLL (1 << 4)
|
2008-11-20 20:24:06 +01:00
|
|
|
#define UIP_BACKLOG (1 << 5)
|
|
|
|
#define UIP_CLOSE (1 << 6)
|
|
|
|
#define UIP_ABORT (1 << 7)
|
|
|
|
#define UIP_CONNECTED (1 << 8)
|
|
|
|
#define UIP_TIMEDOUT (1 << 9)
|
|
|
|
#define UIP_ECHOREPLY (1 << 10)
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-09-16 00:45:45 +02:00
|
|
|
#define UIP_CONN_EVENTS (UIP_CLOSE|UIP_ABORT|UIP_CONNECTED|UIP_TIMEDOUT)
|
|
|
|
|
|
|
|
/* The buffer size available for user data in the d_buf buffer.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-20 02:26:34 +01:00
|
|
|
* This macro holds the available size for user data in the
|
2007-09-16 00:45:45 +02:00
|
|
|
* d_buf buffer. The macro is intended to be used for checking
|
2007-08-27 01:12:17 +02:00
|
|
|
* bounds of available user data.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
2007-09-16 00:45:45 +02:00
|
|
|
* snprintf(dev->d_appdata, UIP_APPDATA_SIZE, "%u\n", i);
|
2007-08-27 01:12:17 +02:00
|
|
|
*/
|
|
|
|
|
2007-11-20 00:09:39 +01:00
|
|
|
#define UIP_APPDATA_SIZE (CONFIG_NET_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
#define UIP_PROTO_ICMP 1
|
|
|
|
#define UIP_PROTO_TCP 6
|
|
|
|
#define UIP_PROTO_UDP 17
|
|
|
|
#define UIP_PROTO_ICMP6 58
|
|
|
|
|
2007-10-31 01:13:07 +01:00
|
|
|
/* Header sizes */
|
2007-09-02 23:58:35 +02:00
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2007-11-22 19:36:46 +01:00
|
|
|
# define UIP_IPH_LEN 40 /* Size of IP header */
|
|
|
|
#else
|
2007-08-27 01:12:17 +02:00
|
|
|
# define UIP_IPH_LEN 20 /* Size of IP header */
|
2007-11-22 19:36:46 +01:00
|
|
|
#endif
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Type Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-09-01 15:59:54 +02:00
|
|
|
/* Representation of an IP address */
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
typedef in_addr_t uip_ip4addr_t;
|
2007-08-27 01:12:17 +02:00
|
|
|
typedef uint16 uip_ip6addr_t[8];
|
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2007-08-27 01:12:17 +02:00
|
|
|
typedef uip_ip6addr_t uip_ipaddr_t;
|
2007-11-22 19:36:46 +01:00
|
|
|
#else
|
2007-08-27 01:12:17 +02:00
|
|
|
typedef uip_ip4addr_t uip_ipaddr_t;
|
2007-11-20 00:09:39 +01:00
|
|
|
#endif
|
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
/* The IP header */
|
2007-11-20 00:09:39 +01:00
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
struct uip_ip_hdr
|
2007-09-02 23:58:35 +02:00
|
|
|
{
|
2007-09-01 20:06:15 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2007-09-16 00:45:45 +02:00
|
|
|
|
2007-11-16 19:48:39 +01:00
|
|
|
/* IPv6 Ip header */
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-11-07 19:54:35 +01:00
|
|
|
uint8 vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
|
|
|
|
uint8 tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
|
|
|
|
uint16 flow; /* 16-bit flow label (LS) */
|
|
|
|
uint8 len[2]; /* 16-bit Payload length */
|
|
|
|
uint8 proto; /* 8-bit Next header (same as IPv4 protocol field) */
|
|
|
|
uint8 ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
|
|
|
|
uip_ip6addr_t srcipaddr; /* 128-bit Source address */
|
|
|
|
uip_ip6addr_t destipaddr; /* 128-bit Destination address */
|
2007-09-02 23:58:35 +02:00
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#else /* CONFIG_NET_IPv6 */
|
2007-09-16 00:45:45 +02:00
|
|
|
|
2007-11-16 19:48:39 +01:00
|
|
|
/* IPv4 IP header */
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-11-07 19:54:35 +01:00
|
|
|
uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */
|
|
|
|
uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */
|
|
|
|
uint8 len[2]; /* 16-bit Total length */
|
|
|
|
uint8 ipid[2]; /* 16-bit Identification */
|
|
|
|
uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */
|
|
|
|
uint8 ttl; /* 8-bit Time to Live */
|
|
|
|
uint8 proto; /* 8-bit Protocol */
|
|
|
|
uint16 ipchksum; /* 16-bit Header checksum */
|
|
|
|
uint16 srcipaddr[2]; /* 32-bit Source IP address */
|
|
|
|
uint16 destipaddr[2]; /* 32-bit Destination IP address */
|
2007-09-16 00:45:45 +02:00
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
2007-08-27 01:12:17 +02:00
|
|
|
};
|
|
|
|
|
2008-09-01 15:59:54 +02:00
|
|
|
/* Describes a uIP callback
|
|
|
|
*
|
|
|
|
* flink - Supports a singly linked list
|
|
|
|
* event - Provides the address of the callback function entry point.
|
|
|
|
* pvconn is a pointer to one of struct uip_conn or struct uip_udp_conn.
|
|
|
|
* private - Holds a reference to application specific data that will
|
|
|
|
* provided
|
|
|
|
* flags - Set by the application to inform the uIP layer which flags
|
|
|
|
* are and are not handled by the callback.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct uip_driver_s; /* Forward reference */
|
|
|
|
struct uip_callback_s
|
|
|
|
{
|
|
|
|
FAR struct uip_callback_s *flink;
|
|
|
|
uint16 (*event)(struct uip_driver_s *dev, void *pvconn, void *pvprivate, uint16 flags);
|
|
|
|
void *private;
|
|
|
|
uint16 flags;
|
|
|
|
};
|
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
/* Protocol-specific support */
|
2007-09-02 23:58:35 +02:00
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
#include <net/uip/uip-tcp.h>
|
|
|
|
#include <net/uip/uip-udp.h>
|
|
|
|
#include <net/uip/uip-icmp.h>
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
/* The structure holding the uIP statistics that are gathered if
|
|
|
|
* CONFIG_NET_STATISTICS is defined.
|
|
|
|
*/
|
2007-09-16 00:45:45 +02:00
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
#ifdef CONFIG_NET_STATISTICS
|
|
|
|
struct uip_ip_stats_s
|
|
|
|
{
|
|
|
|
uip_stats_t drop; /* Number of dropped packets at the IP layer */
|
|
|
|
uip_stats_t recv; /* Number of received packets at the IP layer */
|
|
|
|
uip_stats_t sent; /* Number of sent packets at the IP layer */
|
|
|
|
uip_stats_t vhlerr; /* Number of packets dropped due to wrong
|
|
|
|
IP version or header length */
|
|
|
|
uip_stats_t hblenerr; /* Number of packets dropped due to wrong
|
|
|
|
IP length, high byte */
|
|
|
|
uip_stats_t lblenerr; /* Number of packets dropped due to wrong
|
|
|
|
IP length, low byte */
|
|
|
|
uip_stats_t fragerr; /* Number of packets dropped since they
|
|
|
|
were IP fragments */
|
|
|
|
uip_stats_t chkerr; /* Number of packets dropped due to IP
|
|
|
|
checksum errors */
|
|
|
|
uip_stats_t protoerr; /* Number of packets dropped since they
|
|
|
|
were neither ICMP, UDP nor TCP */
|
2007-08-27 01:12:17 +02:00
|
|
|
};
|
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
struct uip_stats
|
2007-09-02 23:58:35 +02:00
|
|
|
{
|
2007-11-22 19:36:46 +01:00
|
|
|
struct uip_ip_stats_s ip; /* IP statistics */
|
2007-09-16 00:45:45 +02:00
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
#ifdef CONFIG_NET_ICMP
|
|
|
|
struct uip_icmp_stats_s icmp; /* ICMP statistics */
|
|
|
|
#endif
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
#ifdef CONFIG_NET_TCP
|
|
|
|
struct uip_tcp_stats_s tcp; /* TCP statistics */
|
|
|
|
#endif
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
#ifdef CONFIG_NET_UDP
|
|
|
|
struct uip_udp_stats_s udp; /* UDP statistics */
|
|
|
|
#endif
|
2007-08-27 01:12:17 +02:00
|
|
|
};
|
2007-11-22 19:36:46 +01:00
|
|
|
#endif /* CONFIG_NET_STATISTICS */
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
/* This is the structure in which the statistics are gathered. */
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-11-22 19:36:46 +01:00
|
|
|
#ifdef CONFIG_NET_STATISTICS
|
2007-08-27 01:12:17 +02:00
|
|
|
extern struct uip_stats uip_stat;
|
2007-11-22 19:36:46 +01:00
|
|
|
#endif
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* uIP initialization functions
|
|
|
|
*
|
|
|
|
* The uIP initialization functions are used for booting uIP.
|
|
|
|
*
|
|
|
|
* This function should be called at boot up to initilize the uIP
|
|
|
|
* TCP/IP stack.
|
|
|
|
*/
|
|
|
|
|
2007-11-20 00:09:39 +01:00
|
|
|
extern void uip_initialize(void);
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/* This function may be used at boot time to set the initial ip_id.*/
|
|
|
|
|
2007-11-20 00:09:39 +01:00
|
|
|
extern void uip_setipid(uint16 id);
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/* uIP application functions
|
|
|
|
*
|
|
|
|
* Functions used by an application running of top of uIP. This includes
|
|
|
|
* functions for opening and closing connections, sending and receiving
|
|
|
|
* data, etc.
|
2007-09-02 23:58:35 +02:00
|
|
|
*/
|
|
|
|
|
2007-08-27 01:12:17 +02:00
|
|
|
/* Send data on the current connection.
|
|
|
|
*
|
|
|
|
* This function is used to send out a single segment of TCP
|
|
|
|
* data. Only applications that have been invoked by uIP for event
|
|
|
|
* processing can send data.
|
|
|
|
*
|
|
|
|
* The amount of data that actually is sent out after a call to this
|
|
|
|
* funcion is determined by the maximum amount of data TCP allows. uIP
|
|
|
|
* will automatically crop the data so that only the appropriate
|
|
|
|
* amount of data is sent. The function uip_mss() can be used to query
|
|
|
|
* uIP for the amount of data that actually will be sent.
|
|
|
|
*
|
|
|
|
* Note: This function does not guarantee that the sent data will
|
|
|
|
* arrive at the destination. If the data is lost in the network, the
|
2007-11-27 20:19:30 +01:00
|
|
|
* application will be invoked with the UIP_REXMIT flag set. The
|
|
|
|
* application will then have to resend the data using this function.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
|
|
|
* data A pointer to the data which is to be sent.
|
|
|
|
*
|
|
|
|
* len The maximum amount of data bytes to be sent.
|
|
|
|
*/
|
|
|
|
|
2007-11-20 00:09:39 +01:00
|
|
|
extern void uip_send(struct uip_driver_s *dev, const void *buf, int len);
|
|
|
|
|
2007-08-27 01:12:17 +02:00
|
|
|
/* uIP convenience and converting functions.
|
|
|
|
*
|
|
|
|
* These functions can be used for converting between different data
|
|
|
|
* formats used by uIP.
|
|
|
|
*
|
|
|
|
* Construct an IP address from four bytes.
|
|
|
|
*
|
2007-11-23 22:16:43 +01:00
|
|
|
* This function constructs an IPv4 address in network byte order.
|
|
|
|
*
|
|
|
|
* addr A pointer to a uip_ipaddr_t variable that will be
|
|
|
|
* filled in with the IPv4 address.
|
|
|
|
* addr0 The first octet of the IPv4 address.
|
|
|
|
* addr1 The second octet of the IPv4 address.
|
|
|
|
* addr2 The third octet of the IPv4 address.
|
|
|
|
* addr3 The forth octet of the IPv4 address.
|
2007-08-27 01:12:17 +02:00
|
|
|
*/
|
|
|
|
|
2007-09-05 02:13:18 +02:00
|
|
|
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3) \
|
|
|
|
do { \
|
2007-09-17 00:12:04 +02:00
|
|
|
addr = HTONL((addr0) << 24 | (addr1) << 16 | (addr2) << 8 | (addr3)); \
|
2007-09-05 02:13:18 +02:00
|
|
|
} while(0)
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-10-31 01:13:07 +01:00
|
|
|
/* Convert an IPv4 address of the form uint16[2] to an in_addr_t */
|
|
|
|
|
|
|
|
#ifdef CONFIG_ENDIAN_BIG
|
|
|
|
# define uip_ip4addr_conv(addr) (((in_addr_t)((uint16*)addr)[0] << 16) | (in_addr_t)((uint16*)addr)[1])
|
2007-11-01 00:27:55 +01:00
|
|
|
#else
|
|
|
|
# define uip_ip4addr_conv(addr) (((in_addr_t)((uint16*)addr)[1] << 16) | (in_addr_t)((uint16*)addr)[0])
|
2007-10-31 01:13:07 +01:00
|
|
|
#endif
|
|
|
|
|
2007-08-27 01:12:17 +02:00
|
|
|
/* Construct an IPv6 address from eight 16-bit words.
|
|
|
|
*
|
|
|
|
* This function constructs an IPv6 address.
|
|
|
|
*/
|
|
|
|
|
2007-11-23 22:16:43 +01:00
|
|
|
#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) \
|
|
|
|
do { \
|
|
|
|
((uint16*)(addr))[0] = HTONS((addr0)); \
|
|
|
|
((uint16*)(addr))[1] = HTONS((addr1)); \
|
|
|
|
((uint16*)(addr))[2] = HTONS((addr2)); \
|
|
|
|
((uint16*)(addr))[3] = HTONS((addr3)); \
|
|
|
|
((uint16*)(addr))[4] = HTONS((addr4)); \
|
|
|
|
((uint16*)(addr))[5] = HTONS((addr5)); \
|
|
|
|
((uint16*)(addr))[6] = HTONS((addr6)); \
|
|
|
|
((uint16*)(addr))[7] = HTONS((addr7)); \
|
|
|
|
} while(0)
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/* Copy an IP address to another IP address.
|
|
|
|
*
|
|
|
|
* Copies an IP address from one place to another.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* uip_ipaddr_t ipaddr1, ipaddr2;
|
|
|
|
*
|
|
|
|
* uip_ipaddr(&ipaddr1, 192,16,1,2);
|
|
|
|
* uip_ipaddr_copy(&ipaddr2, &ipaddr1);
|
|
|
|
*
|
|
|
|
* dest The destination for the copy.
|
|
|
|
* src The source from where to copy.
|
|
|
|
*/
|
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#ifndef CONFIG_NET_IPv6
|
2007-10-31 01:13:07 +01:00
|
|
|
# define uip_ipaddr_copy(dest, src) \
|
|
|
|
do { \
|
|
|
|
(dest) = (in_addr_t)(src); \
|
|
|
|
} while(0)
|
|
|
|
# define uiphdr_ipaddr_copy(dest, src) \
|
|
|
|
do { \
|
|
|
|
((uint16*)(dest))[0] = ((uint16*)(src))[0]; \
|
|
|
|
((uint16*)(dest))[1] = ((uint16*)(src))[1]; \
|
|
|
|
} while(0)
|
2007-09-01 20:06:15 +02:00
|
|
|
#else /* !CONFIG_NET_IPv6 */
|
2007-10-31 01:13:07 +01:00
|
|
|
# define uip_ipaddr_copy(dest, src) memcpy(&dest, &src, sizeof(uip_ip6addr_t))
|
|
|
|
# define uiphdr_ipaddr_copy(dest, src) uip_ipaddr_copy(dest, src)
|
2007-09-01 20:06:15 +02:00
|
|
|
#endif /* !CONFIG_NET_IPv6 */
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
/* Compare two IP addresses
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* uip_ipaddr_t ipaddr1, ipaddr2;
|
|
|
|
*
|
|
|
|
* uip_ipaddr(&ipaddr1, 192,16,1,2);
|
|
|
|
* if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
|
|
|
|
* printf("They are the same");
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* addr1 The first IP address.
|
|
|
|
* addr2 The second IP address.
|
|
|
|
*/
|
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#ifndef CONFIG_NET_IPv6
|
2007-10-31 01:13:07 +01:00
|
|
|
# define uip_ipaddr_cmp(addr1, addr2) (addr1 == addr2)
|
|
|
|
# define uiphdr_ipaddr_cmp(addr1, addr2) uip_ipaddr_cmp(uip_ip4addr_conv(addr1), uip_ip4addr_conv(addr2))
|
2007-09-01 20:06:15 +02:00
|
|
|
#else /* !CONFIG_NET_IPv6 */
|
2007-10-31 01:13:07 +01:00
|
|
|
# define uip_ipaddr_cmp(addr1, addr2) (memcmp(&addr1, &addr2, sizeof(uip_ip6addr_t)) == 0)
|
|
|
|
# define uiphdr_ipaddr_cmp(addr1, addr2) uip_ipaddr_cmp(addr, addr2)
|
2007-09-01 20:06:15 +02:00
|
|
|
#endif /* !CONFIG_NET_IPv6 */
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/* Compare two IP addresses with netmasks
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
|
|
|
* Compares two IP addresses with netmasks. The masks are used to mask
|
|
|
|
* out the bits that are to be compared.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* uip_ipaddr_t ipaddr1, ipaddr2, mask;
|
|
|
|
*
|
|
|
|
* uip_ipaddr(&mask, 255,255,255,0);
|
|
|
|
* uip_ipaddr(&ipaddr1, 192,16,1,2);
|
|
|
|
* uip_ipaddr(&ipaddr2, 192,16,1,3);
|
2007-11-22 15:42:52 +01:00
|
|
|
* if(uip_ipaddr_maskcmp(ipaddr1, ipaddr2, &mask))
|
|
|
|
* {
|
|
|
|
* printf("They are the same");
|
|
|
|
* }
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
|
|
|
* addr1 The first IP address.
|
|
|
|
* addr2 The second IP address.
|
|
|
|
* mask The netmask.
|
|
|
|
*/
|
|
|
|
|
2007-10-31 01:13:07 +01:00
|
|
|
#ifndef CONFIG_NET_IPv6
|
|
|
|
# define uip_ipaddr_maskcmp(addr1, addr2, mask) \
|
2007-11-22 15:42:52 +01:00
|
|
|
(((in_addr_t)(addr1) & (in_addr_t)(mask)) == \
|
|
|
|
((in_addr_t)(addr2) & (in_addr_t)(mask)))
|
|
|
|
#else
|
|
|
|
extern boolean uip_ipaddr_maskcmp(uip_addr_t addr1, uip_addr_t addr2,
|
|
|
|
uip_addr_t mask);
|
|
|
|
#endif
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/* Mask out the network part of an IP address.
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
|
|
|
* Masks out the network part of an IP address, given the address and
|
|
|
|
* the netmask.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* uip_ipaddr_t ipaddr1, ipaddr2, netmask;
|
|
|
|
*
|
|
|
|
* uip_ipaddr(&ipaddr1, 192,16,1,2);
|
|
|
|
* uip_ipaddr(&netmask, 255,255,255,0);
|
|
|
|
* uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
|
|
|
|
*
|
|
|
|
* In the example above, the variable "ipaddr2" will contain the IP
|
|
|
|
* address 192.168.1.0.
|
|
|
|
*
|
|
|
|
* dest Where the result is to be placed.
|
|
|
|
* src The IP address.
|
|
|
|
* mask The netmask.
|
|
|
|
*/
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
#define uip_ipaddr_mask(dest, src, mask) \
|
|
|
|
do { \
|
|
|
|
(in_addr_t)(dest) = (in_addr_t)(src) & (in_addr_t)(mask); \
|
|
|
|
} while(0)
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#endif /* __NET_UIP_UIP_H */
|