Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ip4.h Source File

ip4.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * IPv4 protocol definitions
00004  */
00005 
00006 /*
00007  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without modification,
00011  * are permitted provided that the following conditions are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice,
00014  *    this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  *    this list of conditions and the following disclaimer in the documentation
00017  *    and/or other materials provided with the distribution.
00018  * 3. The name of the author may not be used to endorse or promote products
00019  *    derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00023  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00024  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00026  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00030  * OF SUCH DAMAGE.
00031  *
00032  * This file is part of the lwIP TCP/IP stack.
00033  *
00034  * Author: Adam Dunkels <adam@sics.se>
00035  *
00036  */
00037 #ifndef LWIP_HDR_PROT_IP4_H
00038 #define LWIP_HDR_PROT_IP4_H
00039 
00040 #include "lwip/arch.h"
00041 #include "lwip/ip4_addr.h"
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 /** This is the packed version of ip4_addr_t,
00048     used in network headers that are itself packed */
00049 #ifdef PACK_STRUCT_USE_INCLUDES
00050 #  include "arch/bpstruct.h"
00051 #endif
00052 PACK_STRUCT_BEGIN
00053 struct ip4_addr_packed {
00054   PACK_STRUCT_FIELD(u32_t addr);
00055 } PACK_STRUCT_STRUCT;
00056 PACK_STRUCT_END
00057 #ifdef PACK_STRUCT_USE_INCLUDES
00058 #  include "arch/epstruct.h"
00059 #endif
00060 
00061 typedef struct ip4_addr_packed ip4_addr_p_t;
00062 
00063 /* Size of the IPv4 header. Same as 'sizeof(struct ip_hdr)'. */
00064 #define IP_HLEN 20
00065 
00066 #ifdef PACK_STRUCT_USE_INCLUDES
00067 #  include "arch/bpstruct.h"
00068 #endif
00069 PACK_STRUCT_BEGIN
00070 /* The IPv4 header */
00071 struct ip_hdr {
00072   /* version / header length */
00073   PACK_STRUCT_FLD_8(u8_t _v_hl);
00074   /* type of service */
00075   PACK_STRUCT_FLD_8(u8_t _tos);
00076   /* total length */
00077   PACK_STRUCT_FIELD(u16_t _len);
00078   /* identification */
00079   PACK_STRUCT_FIELD(u16_t _id);
00080   /* fragment offset field */
00081   PACK_STRUCT_FIELD(u16_t _offset);
00082 #define IP_RF 0x8000U        /* reserved fragment flag */
00083 #define IP_DF 0x4000U        /* don't fragment flag */
00084 #define IP_MF 0x2000U        /* more fragments flag */
00085 #define IP_OFFMASK 0x1fffU   /* mask for fragmenting bits */
00086   /* time to live */
00087   PACK_STRUCT_FLD_8(u8_t _ttl);
00088   /* protocol*/
00089   PACK_STRUCT_FLD_8(u8_t _proto);
00090   /* checksum */
00091   PACK_STRUCT_FIELD(u16_t _chksum);
00092   /* source and destination IP addresses */
00093   PACK_STRUCT_FLD_S(ip4_addr_p_t src);
00094   PACK_STRUCT_FLD_S(ip4_addr_p_t dest);
00095 } PACK_STRUCT_STRUCT;
00096 PACK_STRUCT_END
00097 #ifdef PACK_STRUCT_USE_INCLUDES
00098 #  include "arch/epstruct.h"
00099 #endif
00100 
00101 /* Macros to get struct ip_hdr fields: */
00102 #define IPH_V(hdr)  ((hdr)->_v_hl >> 4)
00103 #define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
00104 #define IPH_TOS(hdr) ((hdr)->_tos)
00105 #define IPH_LEN(hdr) ((hdr)->_len)
00106 #define IPH_ID(hdr) ((hdr)->_id)
00107 #define IPH_OFFSET(hdr) ((hdr)->_offset)
00108 #define IPH_TTL(hdr) ((hdr)->_ttl)
00109 #define IPH_PROTO(hdr) ((hdr)->_proto)
00110 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
00111 
00112 /* Macros to set struct ip_hdr fields: */
00113 #define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl)))
00114 #define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
00115 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
00116 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
00117 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
00118 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
00119 #define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
00120 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
00121 
00122 
00123 #ifdef __cplusplus
00124 }
00125 #endif
00126 
00127 #endif /* LWIP_HDR_PROT_IP4_H */