Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:8b387bed54c2 1 /*
hlipka 0:8b387bed54c2 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
hlipka 0:8b387bed54c2 3 * All rights reserved.
hlipka 0:8b387bed54c2 4 *
hlipka 0:8b387bed54c2 5 * Redistribution and use in source and binary forms, with or without modification,
hlipka 0:8b387bed54c2 6 * are permitted provided that the following conditions are met:
hlipka 0:8b387bed54c2 7 *
hlipka 0:8b387bed54c2 8 * 1. Redistributions of source code must retain the above copyright notice,
hlipka 0:8b387bed54c2 9 * this list of conditions and the following disclaimer.
hlipka 0:8b387bed54c2 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
hlipka 0:8b387bed54c2 11 * this list of conditions and the following disclaimer in the documentation
hlipka 0:8b387bed54c2 12 * and/or other materials provided with the distribution.
hlipka 0:8b387bed54c2 13 * 3. The name of the author may not be used to endorse or promote products
hlipka 0:8b387bed54c2 14 * derived from this software without specific prior written permission.
hlipka 0:8b387bed54c2 15 *
hlipka 0:8b387bed54c2 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
hlipka 0:8b387bed54c2 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
hlipka 0:8b387bed54c2 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
hlipka 0:8b387bed54c2 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
hlipka 0:8b387bed54c2 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
hlipka 0:8b387bed54c2 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
hlipka 0:8b387bed54c2 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
hlipka 0:8b387bed54c2 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
hlipka 0:8b387bed54c2 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
hlipka 0:8b387bed54c2 25 * OF SUCH DAMAGE.
hlipka 0:8b387bed54c2 26 *
hlipka 0:8b387bed54c2 27 * This file is part of the lwIP TCP/IP stack.
hlipka 0:8b387bed54c2 28 *
hlipka 0:8b387bed54c2 29 * Author: Adam Dunkels <adam@sics.se>
hlipka 0:8b387bed54c2 30 *
hlipka 0:8b387bed54c2 31 */
hlipka 0:8b387bed54c2 32 #ifndef __LWIP_IP_H__
hlipka 0:8b387bed54c2 33 #define __LWIP_IP_H__
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 36
hlipka 0:8b387bed54c2 37 #include "lwip/def.h"
hlipka 0:8b387bed54c2 38 #include "lwip/pbuf.h"
hlipka 0:8b387bed54c2 39 #include "lwip/ip_addr.h"
hlipka 0:8b387bed54c2 40 #include "lwip/err.h"
hlipka 0:8b387bed54c2 41 #include "lwip/netif.h"
hlipka 0:8b387bed54c2 42
hlipka 0:8b387bed54c2 43 #ifdef __cplusplus
hlipka 0:8b387bed54c2 44 extern "C" {
hlipka 0:8b387bed54c2 45 #endif
hlipka 0:8b387bed54c2 46
hlipka 0:8b387bed54c2 47 /** Currently, the function ip_output_if_opt() is only used with IGMP */
hlipka 0:8b387bed54c2 48 #define IP_OPTIONS_SEND LWIP_IGMP
hlipka 0:8b387bed54c2 49
hlipka 0:8b387bed54c2 50 #define IP_HLEN 20
hlipka 0:8b387bed54c2 51
hlipka 0:8b387bed54c2 52 #define IP_PROTO_ICMP 1
hlipka 0:8b387bed54c2 53 #define IP_PROTO_IGMP 2
hlipka 0:8b387bed54c2 54 #define IP_PROTO_UDP 17
hlipka 0:8b387bed54c2 55 #define IP_PROTO_UDPLITE 136
hlipka 0:8b387bed54c2 56 #define IP_PROTO_TCP 6
hlipka 0:8b387bed54c2 57
hlipka 0:8b387bed54c2 58 /* This is passed as the destination address to ip_output_if (not
hlipka 0:8b387bed54c2 59 to ip_output), meaning that an IP header already is constructed
hlipka 0:8b387bed54c2 60 in the pbuf. This is used when TCP retransmits. */
hlipka 0:8b387bed54c2 61 #ifdef IP_HDRINCL
hlipka 0:8b387bed54c2 62 #undef IP_HDRINCL
hlipka 0:8b387bed54c2 63 #endif /* IP_HDRINCL */
hlipka 0:8b387bed54c2 64 #define IP_HDRINCL NULL
hlipka 0:8b387bed54c2 65
hlipka 0:8b387bed54c2 66 #if LWIP_NETIF_HWADDRHINT
hlipka 0:8b387bed54c2 67 #define IP_PCB_ADDRHINT ;u8_t addr_hint
hlipka 0:8b387bed54c2 68 #else
hlipka 0:8b387bed54c2 69 #define IP_PCB_ADDRHINT
hlipka 0:8b387bed54c2 70 #endif /* LWIP_NETIF_HWADDRHINT */
hlipka 0:8b387bed54c2 71
hlipka 0:8b387bed54c2 72 /* This is the common part of all PCB types. It needs to be at the
hlipka 0:8b387bed54c2 73 beginning of a PCB type definition. It is located here so that
hlipka 0:8b387bed54c2 74 changes to this common part are made in one location instead of
hlipka 0:8b387bed54c2 75 having to change all PCB structs. */
hlipka 0:8b387bed54c2 76 #define IP_PCB \
hlipka 0:8b387bed54c2 77 /* ip addresses in network byte order */ \
hlipka 0:8b387bed54c2 78 ip_addr_t local_ip; \
hlipka 0:8b387bed54c2 79 ip_addr_t remote_ip; \
hlipka 0:8b387bed54c2 80 /* Socket options */ \
hlipka 0:8b387bed54c2 81 u8_t so_options; \
hlipka 0:8b387bed54c2 82 /* Type Of Service */ \
hlipka 0:8b387bed54c2 83 u8_t tos; \
hlipka 0:8b387bed54c2 84 /* Time To Live */ \
hlipka 0:8b387bed54c2 85 u8_t ttl \
hlipka 0:8b387bed54c2 86 /* link layer address resolution hint */ \
hlipka 0:8b387bed54c2 87 IP_PCB_ADDRHINT
hlipka 0:8b387bed54c2 88
hlipka 0:8b387bed54c2 89 struct ip_pcb {
hlipka 0:8b387bed54c2 90 /* Common members of all PCB types */
hlipka 0:8b387bed54c2 91 IP_PCB;
hlipka 0:8b387bed54c2 92 };
hlipka 0:8b387bed54c2 93
hlipka 0:8b387bed54c2 94 /*
hlipka 0:8b387bed54c2 95 * Option flags per-socket. These are the same like SO_XXX.
hlipka 0:8b387bed54c2 96 */
hlipka 0:8b387bed54c2 97 /*#define SOF_DEBUG (u8_t)0x01U Unimplemented: turn on debugging info recording */
hlipka 0:8b387bed54c2 98 #define SOF_ACCEPTCONN (u8_t)0x02U /* socket has had listen() */
hlipka 0:8b387bed54c2 99 #define SOF_REUSEADDR (u8_t)0x04U /* allow local address reuse */
hlipka 0:8b387bed54c2 100 #define SOF_KEEPALIVE (u8_t)0x08U /* keep connections alive */
hlipka 0:8b387bed54c2 101 /*#define SOF_DONTROUTE (u8_t)0x10U Unimplemented: just use interface addresses */
hlipka 0:8b387bed54c2 102 #define SOF_BROADCAST (u8_t)0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
hlipka 0:8b387bed54c2 103 /*#define SOF_USELOOPBACK (u8_t)0x40U Unimplemented: bypass hardware when possible */
hlipka 0:8b387bed54c2 104 #define SOF_LINGER (u8_t)0x80U /* linger on close if data present */
hlipka 0:8b387bed54c2 105 /*#define SOF_OOBINLINE (u16_t)0x0100U Unimplemented: leave received OOB data in line */
hlipka 0:8b387bed54c2 106 /*#define SOF_REUSEPORT (u16_t)0x0200U Unimplemented: allow local address & port reuse */
hlipka 0:8b387bed54c2 107
hlipka 0:8b387bed54c2 108 /* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */
hlipka 0:8b387bed54c2 109 #define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER/*|SOF_DEBUG|SOF_DONTROUTE|SOF_OOBINLINE*/)
hlipka 0:8b387bed54c2 110
hlipka 0:8b387bed54c2 111
hlipka 0:8b387bed54c2 112 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 113 # include "arch/bpstruct.h"
hlipka 0:8b387bed54c2 114 #endif
hlipka 0:8b387bed54c2 115 PACK_STRUCT_BEGIN
hlipka 0:8b387bed54c2 116 struct ip_hdr {
hlipka 0:8b387bed54c2 117 /* version / header length / type of service */
hlipka 0:8b387bed54c2 118 PACK_STRUCT_FIELD(u16_t _v_hl_tos);
hlipka 0:8b387bed54c2 119 /* total length */
hlipka 0:8b387bed54c2 120 PACK_STRUCT_FIELD(u16_t _len);
hlipka 0:8b387bed54c2 121 /* identification */
hlipka 0:8b387bed54c2 122 PACK_STRUCT_FIELD(u16_t _id);
hlipka 0:8b387bed54c2 123 /* fragment offset field */
hlipka 0:8b387bed54c2 124 PACK_STRUCT_FIELD(u16_t _offset);
hlipka 0:8b387bed54c2 125 #define IP_RF 0x8000 /* reserved fragment flag */
hlipka 0:8b387bed54c2 126 #define IP_DF 0x4000 /* dont fragment flag */
hlipka 0:8b387bed54c2 127 #define IP_MF 0x2000 /* more fragments flag */
hlipka 0:8b387bed54c2 128 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
hlipka 0:8b387bed54c2 129 /* time to live */
hlipka 0:8b387bed54c2 130 PACK_STRUCT_FIELD(u8_t _ttl);
hlipka 0:8b387bed54c2 131 /* protocol*/
hlipka 0:8b387bed54c2 132 PACK_STRUCT_FIELD(u8_t _proto);
hlipka 0:8b387bed54c2 133 /* checksum */
hlipka 0:8b387bed54c2 134 PACK_STRUCT_FIELD(u16_t _chksum);
hlipka 0:8b387bed54c2 135 /* source and destination IP addresses */
hlipka 0:8b387bed54c2 136 PACK_STRUCT_FIELD(ip_addr_p_t src);
hlipka 0:8b387bed54c2 137 PACK_STRUCT_FIELD(ip_addr_p_t dest);
hlipka 0:8b387bed54c2 138 } PACK_STRUCT_STRUCT;
hlipka 0:8b387bed54c2 139 PACK_STRUCT_END
hlipka 0:8b387bed54c2 140 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 141 # include "arch/epstruct.h"
hlipka 0:8b387bed54c2 142 #endif
hlipka 0:8b387bed54c2 143
hlipka 0:8b387bed54c2 144 #define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
hlipka 0:8b387bed54c2 145 #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
hlipka 0:8b387bed54c2 146 #define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)
hlipka 0:8b387bed54c2 147 #define IPH_LEN(hdr) ((hdr)->_len)
hlipka 0:8b387bed54c2 148 #define IPH_ID(hdr) ((hdr)->_id)
hlipka 0:8b387bed54c2 149 #define IPH_OFFSET(hdr) ((hdr)->_offset)
hlipka 0:8b387bed54c2 150 #define IPH_TTL(hdr) ((hdr)->_ttl)
hlipka 0:8b387bed54c2 151 #define IPH_PROTO(hdr) ((hdr)->_proto)
hlipka 0:8b387bed54c2 152 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
hlipka 0:8b387bed54c2 153
hlipka 0:8b387bed54c2 154 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
hlipka 0:8b387bed54c2 155 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
hlipka 0:8b387bed54c2 156 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
hlipka 0:8b387bed54c2 157 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
hlipka 0:8b387bed54c2 158 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
hlipka 0:8b387bed54c2 159 #define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
hlipka 0:8b387bed54c2 160 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
hlipka 0:8b387bed54c2 161
hlipka 0:8b387bed54c2 162 /** The interface that provided the packet for the current callback invocation. */
hlipka 0:8b387bed54c2 163 extern struct netif *current_netif;
hlipka 0:8b387bed54c2 164 /** Header of the input packet currently being processed. */
hlipka 0:8b387bed54c2 165 extern const struct ip_hdr *current_header;
hlipka 0:8b387bed54c2 166 /** Source IP address of current_header */
hlipka 0:8b387bed54c2 167 extern ip_addr_t current_iphdr_src;
hlipka 0:8b387bed54c2 168 /** Destination IP address of current_header */
hlipka 0:8b387bed54c2 169 extern ip_addr_t current_iphdr_dest;
hlipka 0:8b387bed54c2 170
hlipka 0:8b387bed54c2 171 #define ip_init() /* Compatibility define, not init needed. */
hlipka 0:8b387bed54c2 172 struct netif *ip_route(ip_addr_t *dest);
hlipka 0:8b387bed54c2 173 err_t ip_input(struct pbuf *p, struct netif *inp);
hlipka 0:8b387bed54c2 174 err_t ip_output(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
hlipka 0:8b387bed54c2 175 u8_t ttl, u8_t tos, u8_t proto);
hlipka 0:8b387bed54c2 176 err_t ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
hlipka 0:8b387bed54c2 177 u8_t ttl, u8_t tos, u8_t proto,
hlipka 0:8b387bed54c2 178 struct netif *netif);
hlipka 0:8b387bed54c2 179 #if LWIP_NETIF_HWADDRHINT
hlipka 0:8b387bed54c2 180 err_t ip_output_hinted(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
hlipka 0:8b387bed54c2 181 u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
hlipka 0:8b387bed54c2 182 #endif /* LWIP_NETIF_HWADDRHINT */
hlipka 0:8b387bed54c2 183 #if IP_OPTIONS_SEND
hlipka 0:8b387bed54c2 184 err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
hlipka 0:8b387bed54c2 185 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
hlipka 0:8b387bed54c2 186 u16_t optlen);
hlipka 0:8b387bed54c2 187 #endif /* IP_OPTIONS_SEND */
hlipka 0:8b387bed54c2 188 /** Get the interface that received the current packet.
hlipka 0:8b387bed54c2 189 * This function must only be called from a receive callback (udp_recv,
hlipka 0:8b387bed54c2 190 * raw_recv, tcp_accept). It will return NULL otherwise. */
hlipka 0:8b387bed54c2 191 #define ip_current_netif() (current_netif)
hlipka 0:8b387bed54c2 192 /** Get the IP header of the current packet.
hlipka 0:8b387bed54c2 193 * This function must only be called from a receive callback (udp_recv,
hlipka 0:8b387bed54c2 194 * raw_recv, tcp_accept). It will return NULL otherwise. */
hlipka 0:8b387bed54c2 195 #define ip_current_header() (current_header)
hlipka 0:8b387bed54c2 196 /** Source IP address of current_header */
hlipka 0:8b387bed54c2 197 #define ip_current_src_addr() (&current_iphdr_src)
hlipka 0:8b387bed54c2 198 /** Destination IP address of current_header */
hlipka 0:8b387bed54c2 199 #define ip_current_dest_addr() (&current_iphdr_dest)
hlipka 0:8b387bed54c2 200
hlipka 0:8b387bed54c2 201 #if IP_DEBUG
hlipka 0:8b387bed54c2 202 void ip_debug_print(struct pbuf *p);
hlipka 0:8b387bed54c2 203 #else
hlipka 0:8b387bed54c2 204 #define ip_debug_print(p)
hlipka 0:8b387bed54c2 205 #endif /* IP_DEBUG */
hlipka 0:8b387bed54c2 206
hlipka 0:8b387bed54c2 207 #ifdef __cplusplus
hlipka 0:8b387bed54c2 208 }
hlipka 0:8b387bed54c2 209 #endif
hlipka 0:8b387bed54c2 210
hlipka 0:8b387bed54c2 211 #endif /* __LWIP_IP_H__ */
hlipka 0:8b387bed54c2 212
hlipka 0:8b387bed54c2 213