This library is deprecated.

Dependents:   HTTPClientStreamingExample HTTPClientExample HTTPServerExample HTTPServerHelloWorld ... more

Committer:
donatien
Date:
Fri Jun 11 16:25:22 2010 +0000
Revision:
0:422060928e37
Child:
5:bc7df6da7589

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:422060928e37 1 /*
donatien 0:422060928e37 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
donatien 0:422060928e37 3 * All rights reserved.
donatien 0:422060928e37 4 *
donatien 0:422060928e37 5 * Redistribution and use in source and binary forms, with or without modification,
donatien 0:422060928e37 6 * are permitted provided that the following conditions are met:
donatien 0:422060928e37 7 *
donatien 0:422060928e37 8 * 1. Redistributions of source code must retain the above copyright notice,
donatien 0:422060928e37 9 * this list of conditions and the following disclaimer.
donatien 0:422060928e37 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
donatien 0:422060928e37 11 * this list of conditions and the following disclaimer in the documentation
donatien 0:422060928e37 12 * and/or other materials provided with the distribution.
donatien 0:422060928e37 13 * 3. The name of the author may not be used to endorse or promote products
donatien 0:422060928e37 14 * derived from this software without specific prior written permission.
donatien 0:422060928e37 15 *
donatien 0:422060928e37 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
donatien 0:422060928e37 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
donatien 0:422060928e37 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
donatien 0:422060928e37 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
donatien 0:422060928e37 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
donatien 0:422060928e37 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
donatien 0:422060928e37 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
donatien 0:422060928e37 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
donatien 0:422060928e37 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
donatien 0:422060928e37 25 * OF SUCH DAMAGE.
donatien 0:422060928e37 26 *
donatien 0:422060928e37 27 * This file is part of the lwIP TCP/IP stack.
donatien 0:422060928e37 28 *
donatien 0:422060928e37 29 * Author: Adam Dunkels <adam@sics.se>
donatien 0:422060928e37 30 *
donatien 0:422060928e37 31 */
donatien 0:422060928e37 32 #ifndef __LWIP_UDP_H__
donatien 0:422060928e37 33 #define __LWIP_UDP_H__
donatien 0:422060928e37 34
donatien 0:422060928e37 35 #include "lwip/opt.h"
donatien 0:422060928e37 36
donatien 0:422060928e37 37 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
donatien 0:422060928e37 38
donatien 0:422060928e37 39 #include "lwip/pbuf.h"
donatien 0:422060928e37 40 #include "lwip/netif.h"
donatien 0:422060928e37 41 #include "lwip/ip_addr.h"
donatien 0:422060928e37 42 #include "lwip/ip.h"
donatien 0:422060928e37 43
donatien 0:422060928e37 44 #ifdef __cplusplus
donatien 0:422060928e37 45 extern "C" {
donatien 0:422060928e37 46 #endif
donatien 0:422060928e37 47
donatien 0:422060928e37 48 #define UDP_HLEN 8
donatien 0:422060928e37 49
donatien 0:422060928e37 50 /* Fields are (of course) in network byte order. */
donatien 0:422060928e37 51 #ifdef PACK_STRUCT_USE_INCLUDES
donatien 0:422060928e37 52 # include "arch/bpstruct.h"
donatien 0:422060928e37 53 #endif
donatien 0:422060928e37 54 PACK_STRUCT_BEGIN
donatien 0:422060928e37 55 struct udp_hdr {
donatien 0:422060928e37 56 PACK_STRUCT_FIELD(u16_t src);
donatien 0:422060928e37 57 PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */
donatien 0:422060928e37 58 PACK_STRUCT_FIELD(u16_t len);
donatien 0:422060928e37 59 PACK_STRUCT_FIELD(u16_t chksum);
donatien 0:422060928e37 60 } PACK_STRUCT_STRUCT;
donatien 0:422060928e37 61 PACK_STRUCT_END
donatien 0:422060928e37 62 #ifdef PACK_STRUCT_USE_INCLUDES
donatien 0:422060928e37 63 # include "arch/epstruct.h"
donatien 0:422060928e37 64 #endif
donatien 0:422060928e37 65
donatien 0:422060928e37 66 #define UDP_FLAGS_NOCHKSUM 0x01U
donatien 0:422060928e37 67 #define UDP_FLAGS_UDPLITE 0x02U
donatien 0:422060928e37 68 #define UDP_FLAGS_CONNECTED 0x04U
donatien 0:422060928e37 69
donatien 0:422060928e37 70 struct udp_pcb;
donatien 0:422060928e37 71
donatien 0:422060928e37 72 /** Function prototype for udp pcb receive callback functions
donatien 0:422060928e37 73 * addr and port are in same byte order as in the pcb
donatien 0:422060928e37 74 * The callback is responsible for freeing the pbuf
donatien 0:422060928e37 75 * if it's not used any more.
donatien 0:422060928e37 76 *
donatien 0:422060928e37 77 * ATTENTION: Be aware that 'addr' points into the pbuf 'p' so freeing this pbuf
donatien 0:422060928e37 78 * makes 'addr' invalid, too.
donatien 0:422060928e37 79 *
donatien 0:422060928e37 80 * @param arg user supplied argument (udp_pcb.recv_arg)
donatien 0:422060928e37 81 * @param pcb the udp_pcb which received data
donatien 0:422060928e37 82 * @param p the packet buffer that was received
donatien 0:422060928e37 83 * @param addr the remote IP address from which the packet was received
donatien 0:422060928e37 84 * @param port the remote port from which the packet was received
donatien 0:422060928e37 85 */
donatien 0:422060928e37 86 typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
donatien 0:422060928e37 87 ip_addr_t *addr, u16_t port);
donatien 0:422060928e37 88
donatien 0:422060928e37 89
donatien 0:422060928e37 90 struct udp_pcb {
donatien 0:422060928e37 91 /* Common members of all PCB types */
donatien 0:422060928e37 92 IP_PCB;
donatien 0:422060928e37 93
donatien 0:422060928e37 94 /* Protocol specific PCB members */
donatien 0:422060928e37 95
donatien 0:422060928e37 96 struct udp_pcb *next;
donatien 0:422060928e37 97
donatien 0:422060928e37 98 u8_t flags;
donatien 0:422060928e37 99 /** ports are in host byte order */
donatien 0:422060928e37 100 u16_t local_port, remote_port;
donatien 0:422060928e37 101
donatien 0:422060928e37 102 #if LWIP_IGMP
donatien 0:422060928e37 103 /** outgoing network interface for multicast packets */
donatien 0:422060928e37 104 ip_addr_t multicast_ip;
donatien 0:422060928e37 105 #endif /* LWIP_IGMP */
donatien 0:422060928e37 106
donatien 0:422060928e37 107 #if LWIP_UDPLITE
donatien 0:422060928e37 108 /** used for UDP_LITE only */
donatien 0:422060928e37 109 u16_t chksum_len_rx, chksum_len_tx;
donatien 0:422060928e37 110 #endif /* LWIP_UDPLITE */
donatien 0:422060928e37 111
donatien 0:422060928e37 112 /** receive callback function */
donatien 0:422060928e37 113 udp_recv_fn recv;
donatien 0:422060928e37 114 /** user-supplied argument for the recv callback */
donatien 0:422060928e37 115 void *recv_arg;
donatien 0:422060928e37 116 };
donatien 0:422060928e37 117 /* udp_pcbs export for exernal reference (e.g. SNMP agent) */
donatien 0:422060928e37 118 extern struct udp_pcb *udp_pcbs;
donatien 0:422060928e37 119
donatien 0:422060928e37 120 /* The following functions is the application layer interface to the
donatien 0:422060928e37 121 UDP code. */
donatien 0:422060928e37 122 struct udp_pcb * udp_new (void);
donatien 0:422060928e37 123 void udp_remove (struct udp_pcb *pcb);
donatien 0:422060928e37 124 err_t udp_bind (struct udp_pcb *pcb, ip_addr_t *ipaddr,
donatien 0:422060928e37 125 u16_t port);
donatien 0:422060928e37 126 err_t udp_connect (struct udp_pcb *pcb, ip_addr_t *ipaddr,
donatien 0:422060928e37 127 u16_t port);
donatien 0:422060928e37 128 void udp_disconnect (struct udp_pcb *pcb);
donatien 0:422060928e37 129 void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv,
donatien 0:422060928e37 130 void *recv_arg);
donatien 0:422060928e37 131 err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p,
donatien 0:422060928e37 132 ip_addr_t *dst_ip, u16_t dst_port,
donatien 0:422060928e37 133 struct netif *netif);
donatien 0:422060928e37 134 err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p,
donatien 0:422060928e37 135 ip_addr_t *dst_ip, u16_t dst_port);
donatien 0:422060928e37 136 err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
donatien 0:422060928e37 137
donatien 0:422060928e37 138 #define udp_flags(pcb) ((pcb)->flags)
donatien 0:422060928e37 139 #define udp_setflags(pcb, f) ((pcb)->flags = (f))
donatien 0:422060928e37 140
donatien 0:422060928e37 141 /* The following functions are the lower layer interface to UDP. */
donatien 0:422060928e37 142 void udp_input (struct pbuf *p, struct netif *inp);
donatien 0:422060928e37 143
donatien 0:422060928e37 144 #define udp_init() /* Compatibility define, not init needed. */
donatien 0:422060928e37 145
donatien 0:422060928e37 146 #if UDP_DEBUG
donatien 0:422060928e37 147 void udp_debug_print(struct udp_hdr *udphdr);
donatien 0:422060928e37 148 #else
donatien 0:422060928e37 149 #define udp_debug_print(udphdr)
donatien 0:422060928e37 150 #endif
donatien 0:422060928e37 151
donatien 0:422060928e37 152 #ifdef __cplusplus
donatien 0:422060928e37 153 }
donatien 0:422060928e37 154 #endif
donatien 0:422060928e37 155
donatien 0:422060928e37 156 #endif /* LWIP_UDP */
donatien 0:422060928e37 157
donatien 0:422060928e37 158 #endif /* __LWIP_UDP_H__ */