A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ip.h Source File

ip.h

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_H__
00033 #define __LWIP_IP_H__
00034 
00035 #include "lwip/opt.h"
00036 
00037 #include "lwip/def.h"
00038 #include "lwip/pbuf.h"
00039 #include "lwip/ip_addr.h"
00040 #include "lwip/err.h"
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 #define ip_init() /* Compatibility define, not init needed. */
00047 struct netif *ip_route(struct ip_addr *dest);
00048 err_t ip_input(struct pbuf *p, struct netif *inp);
00049 err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00050     u8_t ttl, u8_t tos, u8_t proto);
00051 err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00052        u8_t ttl, u8_t tos, u8_t proto,
00053        struct netif *netif);
00054 
00055 #define IP_HLEN 20
00056 
00057 #define IP_PROTO_ICMP    1
00058 #define IP_PROTO_UDP     17
00059 #define IP_PROTO_UDPLITE 136
00060 #define IP_PROTO_TCP     6
00061 
00062 /* This is passed as the destination address to ip_output_if (not
00063    to ip_output), meaning that an IP header already is constructed
00064    in the pbuf. This is used when TCP retransmits. */
00065 #ifdef IP_HDRINCL
00066 #undef IP_HDRINCL
00067 #endif /* IP_HDRINCL */
00068 #define IP_HDRINCL  NULL
00069 
00070 #if LWIP_NETIF_HWADDRHINT
00071 #define IP_PCB_ADDRHINT ;u8_t addr_hint
00072 #else
00073 #define IP_PCB_ADDRHINT
00074 #endif /* LWIP_NETIF_HWADDRHINT */
00075 
00076 /* This is the common part of all PCB types. It needs to be at the
00077    beginning of a PCB type definition. It is located here so that
00078    changes to this common part are made in one location instead of
00079    having to change all PCB structs. */
00080 #define IP_PCB \
00081   /* ip addresses in network byte order */ \
00082   struct ip_addr local_ip; \
00083   struct ip_addr remote_ip; \
00084    /* Socket options */  \
00085   u16_t so_options;      \
00086    /* Type Of Service */ \
00087   u8_t tos;              \
00088   /* Time To Live */     \
00089   u8_t ttl               \
00090   /* link layer address resolution hint */ \
00091   IP_PCB_ADDRHINT
00092 
00093 struct ip_pcb {
00094 /* Common members of all PCB types */
00095   IP_PCB;
00096 };
00097 
00098 /*
00099  * Option flags per-socket. These are the same like SO_XXX.
00100  */
00101 #define SOF_DEBUG       (u16_t)0x0001U    /* turn on debugging info recording */
00102 #define SOF_ACCEPTCONN  (u16_t)0x0002U    /* socket has had listen() */
00103 #define SOF_REUSEADDR   (u16_t)0x0004U    /* allow local address reuse */
00104 #define SOF_KEEPALIVE   (u16_t)0x0008U    /* keep connections alive */
00105 #define SOF_DONTROUTE   (u16_t)0x0010U    /* just use interface addresses */
00106 #define SOF_BROADCAST   (u16_t)0x0020U    /* permit sending of broadcast msgs */
00107 #define SOF_USELOOPBACK (u16_t)0x0040U    /* bypass hardware when possible */
00108 #define SOF_LINGER      (u16_t)0x0080U    /* linger on close if data present */
00109 #define SOF_OOBINLINE   (u16_t)0x0100U    /* leave received OOB data in line */
00110 #define SOF_REUSEPORT   (u16_t)0x0200U    /* allow local address & port reuse */
00111 
00112 
00113 #ifdef PACK_STRUCT_USE_INCLUDES
00114 #  include "arch/bpstruct.h"
00115 #endif
00116 PACK_STRUCT_BEGIN
00117 struct ip_hdr {
00118   /* version / header length / type of service */
00119   PACK_STRUCT_FIELD(u16_t _v_hl_tos);
00120   /* total length */
00121   PACK_STRUCT_FIELD(u16_t _len);
00122   /* identification */
00123   PACK_STRUCT_FIELD(u16_t _id);
00124   /* fragment offset field */
00125   PACK_STRUCT_FIELD(u16_t _offset);
00126 #define IP_RF 0x8000        /* reserved fragment flag */
00127 #define IP_DF 0x4000        /* dont fragment flag */
00128 #define IP_MF 0x2000        /* more fragments flag */
00129 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
00130   /* time to live / protocol*/
00131   PACK_STRUCT_FIELD(u16_t _ttl_proto);
00132   /* checksum */
00133   PACK_STRUCT_FIELD(u16_t _chksum);
00134   /* source and destination IP addresses */
00135   PACK_STRUCT_FIELD(struct ip_addr src);
00136   PACK_STRUCT_FIELD(struct ip_addr dest); 
00137 } PACK_STRUCT_STRUCT;
00138 PACK_STRUCT_END
00139 #ifdef PACK_STRUCT_USE_INCLUDES
00140 #  include "arch/epstruct.h"
00141 #endif
00142 
00143 #define IPH_V(hdr)  (ntohs((hdr)->_v_hl_tos) >> 12)
00144 #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
00145 #define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)
00146 #define IPH_LEN(hdr) ((hdr)->_len)
00147 #define IPH_ID(hdr) ((hdr)->_id)
00148 #define IPH_OFFSET(hdr) ((hdr)->_offset)
00149 #define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)
00150 #define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)
00151 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
00152 
00153 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
00154 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
00155 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
00156 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
00157 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | ((u16_t)(ttl) << 8)))
00158 #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8)))
00159 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
00160 
00161 #if IP_DEBUG
00162 void ip_debug_print(struct pbuf *p);
00163 #else
00164 #define ip_debug_print(p)
00165 #endif /* IP_DEBUG */
00166 
00167 #ifdef __cplusplus
00168 }
00169 #endif
00170 
00171 #endif /* __LWIP_IP_H__ */
00172 
00173