Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Tue Nov 09 20:54:15 2010 +0000
Revision:
0:ac1725ba162c

        

Who changed what in which revision?

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