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

ip.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_H__
00039 #define __LWIP_IP_H__
00040 
00041 #include "lwip/arch.h"
00042 
00043 #include "lwip/def.h"
00044 #include "lwip/pbuf.h"
00045 #include "lwip/ip_addr.h"
00046 
00047 #include "lwip/err.h"
00048 
00049 struct netif;
00050 
00051 void ip_init(void);
00052 u8_t ip_lookup(void *header, struct netif *inp);
00053 struct netif *ip_route(struct ip_addr *dest);
00054 err_t ip_input(struct pbuf *p, struct netif *inp);
00055 err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00056                 u8_t ttl, u8_t proto);
00057 err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00058                    u8_t ttl, u8_t proto,
00059                    struct netif *netif);
00060 
00061 #define IP_HLEN 20
00062 
00063 #define IP_PROTO_ICMP 1
00064 #define IP_PROTO_UDP 17
00065 #define IP_PROTO_UDPLITE 170
00066 #define IP_PROTO_TCP 6
00067 
00068 /* This is passed as the destination address to ip_output_if (not
00069    to ip_output), meaning that an IP header already is constructed
00070    in the pbuf. This is used when TCP retransmits. */
00071 #ifdef IP_HDRINCL
00072 #undef IP_HDRINCL
00073 #endif /* IP_HDRINCL */
00074 #define IP_HDRINCL  NULL
00075 
00076 #ifdef PACK_STRUCT_USE_INCLUDES
00077 #  include "arch/bpstruct.h"
00078 #endif
00079 PACK_STRUCT_BEGIN
00080 struct ip_hdr {
00081   /* version / header length / type of service */
00082   PACK_STRUCT_FIELD(u16_t _v_hl_tos);
00083   /* total length */
00084   PACK_STRUCT_FIELD(u16_t _len);
00085   /* identification */
00086   PACK_STRUCT_FIELD(u16_t _id);
00087   /* fragment offset field */
00088   PACK_STRUCT_FIELD(u16_t _offset);
00089 #define IP_RF 0x8000        /* reserved fragment flag */
00090 #define IP_DF 0x4000        /* dont fragment flag */
00091 #define IP_MF 0x2000        /* more fragments flag */
00092 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
00093   /* time to live / protocol*/
00094   PACK_STRUCT_FIELD(u16_t _ttl_proto);
00095   /* checksum */
00096   PACK_STRUCT_FIELD(u16_t _chksum);
00097   /* source and destination IP addresses */
00098   PACK_STRUCT_FIELD(struct ip_addr src);
00099   PACK_STRUCT_FIELD(struct ip_addr dest); 
00100 } PACK_STRUCT_STRUCT;
00101 PACK_STRUCT_END
00102 #ifdef PACK_STRUCT_USE_INCLUDES
00103 #  include "arch/epstruct.h"
00104 #endif
00105 
00106 #define IPH_V(hdr)  (ntohs((hdr)->_v_hl_tos) >> 12)
00107 #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
00108 #define IPH_TOS(hdr) (htons((ntohs((hdr)->_v_hl_tos) & 0xff)))
00109 #define IPH_LEN(hdr) ((hdr)->_len)
00110 #define IPH_ID(hdr) ((hdr)->_id)
00111 #define IPH_OFFSET(hdr) ((hdr)->_offset)
00112 #define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)
00113 #define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)
00114 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
00115 
00116 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
00117 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
00118 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
00119 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
00120 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | ((ttl) << 8)))
00121 #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8)))
00122 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
00123 
00124 #if IP_DEBUG
00125 void ip_debug_print(struct pbuf *p);
00126 #endif /* IP_DEBUG */
00127 
00128 #endif /* __LWIP_IP_H__ */
00129 
00130 

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