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_UDP_H__
hlipka 0:8b387bed54c2 33 #define __LWIP_UDP_H__
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 36
hlipka 0:8b387bed54c2 37 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
hlipka 0:8b387bed54c2 38
hlipka 0:8b387bed54c2 39 #include "lwip/pbuf.h"
hlipka 0:8b387bed54c2 40 #include "lwip/netif.h"
hlipka 0:8b387bed54c2 41 #include "lwip/ip_addr.h"
hlipka 0:8b387bed54c2 42 #include "lwip/ip.h"
hlipka 0:8b387bed54c2 43
hlipka 0:8b387bed54c2 44 #ifdef __cplusplus
hlipka 0:8b387bed54c2 45 extern "C" {
hlipka 0:8b387bed54c2 46 #endif
hlipka 0:8b387bed54c2 47
hlipka 0:8b387bed54c2 48 #define UDP_HLEN 8
hlipka 0:8b387bed54c2 49
hlipka 0:8b387bed54c2 50 /* Fields are (of course) in network byte order. */
hlipka 0:8b387bed54c2 51 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 52 # include "arch/bpstruct.h"
hlipka 0:8b387bed54c2 53 #endif
hlipka 0:8b387bed54c2 54 PACK_STRUCT_BEGIN
hlipka 0:8b387bed54c2 55 struct udp_hdr {
hlipka 0:8b387bed54c2 56 PACK_STRUCT_FIELD(u16_t src);
hlipka 0:8b387bed54c2 57 PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */
hlipka 0:8b387bed54c2 58 PACK_STRUCT_FIELD(u16_t len);
hlipka 0:8b387bed54c2 59 PACK_STRUCT_FIELD(u16_t chksum);
hlipka 0:8b387bed54c2 60 } PACK_STRUCT_STRUCT;
hlipka 0:8b387bed54c2 61 PACK_STRUCT_END
hlipka 0:8b387bed54c2 62 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 63 # include "arch/epstruct.h"
hlipka 0:8b387bed54c2 64 #endif
hlipka 0:8b387bed54c2 65
hlipka 0:8b387bed54c2 66 #define UDP_FLAGS_NOCHKSUM 0x01U
hlipka 0:8b387bed54c2 67 #define UDP_FLAGS_UDPLITE 0x02U
hlipka 0:8b387bed54c2 68 #define UDP_FLAGS_CONNECTED 0x04U
hlipka 0:8b387bed54c2 69 #define UDP_FLAGS_MULTICAST_LOOP 0x08U
hlipka 0:8b387bed54c2 70
hlipka 0:8b387bed54c2 71 struct udp_pcb;
hlipka 0:8b387bed54c2 72
hlipka 0:8b387bed54c2 73 /** Function prototype for udp pcb receive callback functions
hlipka 0:8b387bed54c2 74 * addr and port are in same byte order as in the pcb
hlipka 0:8b387bed54c2 75 * The callback is responsible for freeing the pbuf
hlipka 0:8b387bed54c2 76 * if it's not used any more.
hlipka 0:8b387bed54c2 77 *
hlipka 0:8b387bed54c2 78 * ATTENTION: Be aware that 'addr' points into the pbuf 'p' so freeing this pbuf
hlipka 0:8b387bed54c2 79 * makes 'addr' invalid, too.
hlipka 0:8b387bed54c2 80 *
hlipka 0:8b387bed54c2 81 * @param arg user supplied argument (udp_pcb.recv_arg)
hlipka 0:8b387bed54c2 82 * @param pcb the udp_pcb which received data
hlipka 0:8b387bed54c2 83 * @param p the packet buffer that was received
hlipka 0:8b387bed54c2 84 * @param addr the remote IP address from which the packet was received
hlipka 0:8b387bed54c2 85 * @param port the remote port from which the packet was received
hlipka 0:8b387bed54c2 86 */
hlipka 0:8b387bed54c2 87 typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
hlipka 0:8b387bed54c2 88 ip_addr_t *addr, u16_t port);
hlipka 0:8b387bed54c2 89
hlipka 0:8b387bed54c2 90
hlipka 0:8b387bed54c2 91 struct udp_pcb {
hlipka 0:8b387bed54c2 92 /* Common members of all PCB types */
hlipka 0:8b387bed54c2 93 IP_PCB;
hlipka 0:8b387bed54c2 94
hlipka 0:8b387bed54c2 95 /* Protocol specific PCB members */
hlipka 0:8b387bed54c2 96
hlipka 0:8b387bed54c2 97 struct udp_pcb *next;
hlipka 0:8b387bed54c2 98
hlipka 0:8b387bed54c2 99 u8_t flags;
hlipka 0:8b387bed54c2 100 /** ports are in host byte order */
hlipka 0:8b387bed54c2 101 u16_t local_port, remote_port;
hlipka 0:8b387bed54c2 102
hlipka 0:8b387bed54c2 103 #if LWIP_IGMP
hlipka 0:8b387bed54c2 104 /** outgoing network interface for multicast packets */
hlipka 0:8b387bed54c2 105 ip_addr_t multicast_ip;
hlipka 0:8b387bed54c2 106 #endif /* LWIP_IGMP */
hlipka 0:8b387bed54c2 107
hlipka 0:8b387bed54c2 108 #if LWIP_UDPLITE
hlipka 0:8b387bed54c2 109 /** used for UDP_LITE only */
hlipka 0:8b387bed54c2 110 u16_t chksum_len_rx, chksum_len_tx;
hlipka 0:8b387bed54c2 111 #endif /* LWIP_UDPLITE */
hlipka 0:8b387bed54c2 112
hlipka 0:8b387bed54c2 113 /** receive callback function */
hlipka 0:8b387bed54c2 114 udp_recv_fn recv;
hlipka 0:8b387bed54c2 115 /** user-supplied argument for the recv callback */
hlipka 0:8b387bed54c2 116 void *recv_arg;
hlipka 0:8b387bed54c2 117 };
hlipka 0:8b387bed54c2 118 /* udp_pcbs export for exernal reference (e.g. SNMP agent) */
hlipka 0:8b387bed54c2 119 extern struct udp_pcb *udp_pcbs;
hlipka 0:8b387bed54c2 120
hlipka 0:8b387bed54c2 121 /* The following functions is the application layer interface to the
hlipka 0:8b387bed54c2 122 UDP code. */
hlipka 0:8b387bed54c2 123 struct udp_pcb * udp_new (void);
hlipka 0:8b387bed54c2 124 void udp_remove (struct udp_pcb *pcb);
hlipka 0:8b387bed54c2 125 err_t udp_bind (struct udp_pcb *pcb, ip_addr_t *ipaddr,
hlipka 0:8b387bed54c2 126 u16_t port);
hlipka 0:8b387bed54c2 127 err_t udp_connect (struct udp_pcb *pcb, ip_addr_t *ipaddr,
hlipka 0:8b387bed54c2 128 u16_t port);
hlipka 0:8b387bed54c2 129 void udp_disconnect (struct udp_pcb *pcb);
hlipka 0:8b387bed54c2 130 void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv,
hlipka 0:8b387bed54c2 131 void *recv_arg);
hlipka 0:8b387bed54c2 132 err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p,
hlipka 0:8b387bed54c2 133 ip_addr_t *dst_ip, u16_t dst_port,
hlipka 0:8b387bed54c2 134 struct netif *netif);
hlipka 0:8b387bed54c2 135 err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p,
hlipka 0:8b387bed54c2 136 ip_addr_t *dst_ip, u16_t dst_port);
hlipka 0:8b387bed54c2 137 err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
hlipka 0:8b387bed54c2 138
hlipka 0:8b387bed54c2 139 #if LWIP_CHECKSUM_ON_COPY
hlipka 0:8b387bed54c2 140 err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p,
hlipka 0:8b387bed54c2 141 ip_addr_t *dst_ip, u16_t dst_port,
hlipka 0:8b387bed54c2 142 struct netif *netif, u8_t have_chksum,
hlipka 0:8b387bed54c2 143 u16_t chksum);
hlipka 0:8b387bed54c2 144 err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p,
hlipka 0:8b387bed54c2 145 ip_addr_t *dst_ip, u16_t dst_port,
hlipka 0:8b387bed54c2 146 u8_t have_chksum, u16_t chksum);
hlipka 0:8b387bed54c2 147 err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
hlipka 0:8b387bed54c2 148 u8_t have_chksum, u16_t chksum);
hlipka 0:8b387bed54c2 149 #endif /* LWIP_CHECKSUM_ON_COPY */
hlipka 0:8b387bed54c2 150
hlipka 0:8b387bed54c2 151 #define udp_flags(pcb) ((pcb)->flags)
hlipka 0:8b387bed54c2 152 #define udp_setflags(pcb, f) ((pcb)->flags = (f))
hlipka 0:8b387bed54c2 153
hlipka 0:8b387bed54c2 154 /* The following functions are the lower layer interface to UDP. */
hlipka 0:8b387bed54c2 155 void udp_input (struct pbuf *p, struct netif *inp);
hlipka 0:8b387bed54c2 156
hlipka 0:8b387bed54c2 157 #define udp_init() /* Compatibility define, not init needed. */
hlipka 0:8b387bed54c2 158
hlipka 0:8b387bed54c2 159 #if UDP_DEBUG
hlipka 0:8b387bed54c2 160 void udp_debug_print(struct udp_hdr *udphdr);
hlipka 0:8b387bed54c2 161 #else
hlipka 0:8b387bed54c2 162 #define udp_debug_print(udphdr)
hlipka 0:8b387bed54c2 163 #endif
hlipka 0:8b387bed54c2 164
hlipka 0:8b387bed54c2 165 #ifdef __cplusplus
hlipka 0:8b387bed54c2 166 }
hlipka 0:8b387bed54c2 167 #endif
hlipka 0:8b387bed54c2 168
hlipka 0:8b387bed54c2 169 #endif /* LWIP_UDP */
hlipka 0:8b387bed54c2 170
hlipka 0:8b387bed54c2 171 #endif /* __LWIP_UDP_H__ */