# ip.h

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
    00003  * All rights reserved.
    00004  *
    00005  * Redistribution and use in source and binary forms, with or without
    00006  * modification, are permitted provided that the following conditions
    00007  * are met:
    00008  * 1. Redistributions of source code must retain the above copyright
    00009  *    notice, this list of conditions and the following disclaimer.
    00010  * 2. Redistributions in binary form must reproduce the above copyright
    00011  *    notice, this list of conditions and the following disclaimer in the
    00012  *    documentation and/or other materials provided with the distribution.
    00013  * 3. Neither the name of the Institute nor the names of its contributors
    00014  *    may be used to endorse or promote products derived from this software
    00015  *    without specific prior written permission.
    00016  *
    00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
    00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
    00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    00027  * SUCH DAMAGE.
    00028  *
    00029  * This file is part of the lwIP TCP/IP stack.
    00030  *
    00031  * Author: Adam Dunkels <adam@sics.se>
    00032  *
    00033  * $Id: ipv4_2ip_8h-source.html 88 2016-01-12 00:11:29Z reddawg $
    00034  */
    00035 #ifndef __LWIP_IP_H__
    00036 #define __LWIP_IP_H__
    00037
    00038 #include "net/arch.h"
    00039
    00040 #include "net/def.h"
    00041 #include "net/pbuf.h"
    00042 #include "net/ipv4/ip_addr.h"
    00043 #include "net/netif.h"
    00044
    00045 #include "net/err.h"
    00046
    00047 void ip_init(void);
    00048 uInt8 ip_lookup(void *header, struct netif *inp);
    00049 struct netif *ip_route(struct ip_addr *dest);
    00050 err_t ip_input(struct pbuf *p, struct netif *inp);
    00051 err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
    00052                 uInt8 ttl, uInt8 proto);
    00053 err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
    00054                    uInt8 ttl, uInt8 proto,
    00055                    struct netif *netif);
    00056
    00057 #define IP_HLEN 20
    00058
    00059 #define IP_PROTO_ICMP 1
    00060 #define IP_PROTO_UDP 17
    00061 #define IP_PROTO_UDPLITE 170
    00062 #define IP_PROTO_TCP 6
    00063
    00064 /* This is passed as the destination address to ip_output_if (not
    00065    to ip_output), meaning that an IP header already is constructed
    00066    in the pbuf. This is used when TCP retransmits. */
    00067 #ifdef IP_HDRINCL
    00068 #undef IP_HDRINCL
    00069 #endif /* IP_HDRINCL */
    00070 #define IP_HDRINCL  NULL
    00071
    00072 struct ip_hdr {
    00073   /* version / header length / type of service */
    00074   PACK_STRUCT_FIELD(uInt16 _v_hl_tos);
    00075   /* total length */
    00076   PACK_STRUCT_FIELD(uInt16 _len);
    00077   /* identification */
    00078   PACK_STRUCT_FIELD(uInt16 _id);
    00079   /* fragment offset field */
    00080   PACK_STRUCT_FIELD(uInt16 _offset);
    00081 #define IP_RF 0x8000        /* reserved fragment flag */
    00082 #define IP_DF 0x4000        /* dont fragment flag */
    00083 #define IP_MF 0x2000        /* more fragments flag */
    00084 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
    00085   /* time to live / protocol*/
    00086   PACK_STRUCT_FIELD(uInt16 _ttl_proto);
    00087   /* checksum */
    00088   PACK_STRUCT_FIELD(uInt16 _chksum);
    00089   /* source and destination IP addresses */
    00090   PACK_STRUCT_FIELD(struct ip_addr src);
    00091   PACK_STRUCT_FIELD(struct ip_addr dest);
    00092 } PACK_STRUCT_STRUCT;
    00093
    00094 #define IPH_V(hdr)  (NTOHS((hdr)->_v_hl_tos) >> 12)
    00095 #define IPH_HL(hdr) ((NTOHS((hdr)->_v_hl_tos) >> 8) & 0x0f)
    00096 #define IPH_TOS(hdr) HTONS((NTOHS((hdr)->_v_hl_tos) & 0xff))
    00097 #define IPH_LEN(hdr) ((hdr)->_len)
    00098 #define IPH_ID(hdr) ((hdr)->_id)
    00099 #define IPH_OFFSET(hdr) ((hdr)->_offset)
    00100 #define IPH_TTL(hdr) (NTOHS((hdr)->_ttl_proto) >> 8)
    00101 #define IPH_PROTO(hdr) (NTOHS((hdr)->_ttl_proto) & 0xff)
    00102 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
    00103
    00104 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = HTONS(((v) << 12) | ((hl) << 8) | (tos))
    00105 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
    00106 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
    00107 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
    00108 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = HTONS(IPH_PROTO(hdr) | ((ttl) << 8))
    00109 #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = HTONS((proto) | (IPH_TTL(hdr) << 8))
    00110 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
    00111
    00112
    00113
    00114 #if IP_DEBUG
    00115 void ip_debug_print(struct pbuf *p);
    00116 #endif /* IP_DEBUG */
    00117
    00118 #endif /* __LWIP_IP_H__ */
    00119
    00120