Some quick code to use UDP-only (no TCP) with mBed. Echos received packets and sends packets when a button is pressed

Dependencies:   mbed

Committer:
pehrhovey
Date:
Sun Mar 14 00:54:12 2010 +0000
Revision:
0:a548a085de55

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pehrhovey 0:a548a085de55 1 /*
pehrhovey 0:a548a085de55 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
pehrhovey 0:a548a085de55 3 * All rights reserved.
pehrhovey 0:a548a085de55 4 *
pehrhovey 0:a548a085de55 5 * Redistribution and use in source and binary forms, with or without modification,
pehrhovey 0:a548a085de55 6 * are permitted provided that the following conditions are met:
pehrhovey 0:a548a085de55 7 *
pehrhovey 0:a548a085de55 8 * 1. Redistributions of source code must retain the above copyright notice,
pehrhovey 0:a548a085de55 9 * this list of conditions and the following disclaimer.
pehrhovey 0:a548a085de55 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
pehrhovey 0:a548a085de55 11 * this list of conditions and the following disclaimer in the documentation
pehrhovey 0:a548a085de55 12 * and/or other materials provided with the distribution.
pehrhovey 0:a548a085de55 13 * 3. The name of the author may not be used to endorse or promote products
pehrhovey 0:a548a085de55 14 * derived from this software without specific prior written permission.
pehrhovey 0:a548a085de55 15 *
pehrhovey 0:a548a085de55 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
pehrhovey 0:a548a085de55 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
pehrhovey 0:a548a085de55 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
pehrhovey 0:a548a085de55 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
pehrhovey 0:a548a085de55 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
pehrhovey 0:a548a085de55 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
pehrhovey 0:a548a085de55 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
pehrhovey 0:a548a085de55 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
pehrhovey 0:a548a085de55 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
pehrhovey 0:a548a085de55 25 * OF SUCH DAMAGE.
pehrhovey 0:a548a085de55 26 *
pehrhovey 0:a548a085de55 27 * This file is part of the lwIP TCP/IP stack.
pehrhovey 0:a548a085de55 28 *
pehrhovey 0:a548a085de55 29 * Author: Adam Dunkels <adam@sics.se>
pehrhovey 0:a548a085de55 30 *
pehrhovey 0:a548a085de55 31 */
pehrhovey 0:a548a085de55 32 #ifndef __LWIP_ICMP_H__
pehrhovey 0:a548a085de55 33 #define __LWIP_ICMP_H__
pehrhovey 0:a548a085de55 34
pehrhovey 0:a548a085de55 35 #include "lwip/opt.h"
pehrhovey 0:a548a085de55 36
pehrhovey 0:a548a085de55 37 #if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */
pehrhovey 0:a548a085de55 38
pehrhovey 0:a548a085de55 39 #include "lwip/pbuf.h"
pehrhovey 0:a548a085de55 40 #include "lwip/ip_addr.h"
pehrhovey 0:a548a085de55 41 #include "lwip/netif.h"
pehrhovey 0:a548a085de55 42
pehrhovey 0:a548a085de55 43 #ifdef __cplusplus
pehrhovey 0:a548a085de55 44 extern "C" {
pehrhovey 0:a548a085de55 45 #endif
pehrhovey 0:a548a085de55 46
pehrhovey 0:a548a085de55 47 #define ICMP_ER 0 /* echo reply */
pehrhovey 0:a548a085de55 48 #define ICMP_DUR 3 /* destination unreachable */
pehrhovey 0:a548a085de55 49 #define ICMP_SQ 4 /* source quench */
pehrhovey 0:a548a085de55 50 #define ICMP_RD 5 /* redirect */
pehrhovey 0:a548a085de55 51 #define ICMP_ECHO 8 /* echo */
pehrhovey 0:a548a085de55 52 #define ICMP_TE 11 /* time exceeded */
pehrhovey 0:a548a085de55 53 #define ICMP_PP 12 /* parameter problem */
pehrhovey 0:a548a085de55 54 #define ICMP_TS 13 /* timestamp */
pehrhovey 0:a548a085de55 55 #define ICMP_TSR 14 /* timestamp reply */
pehrhovey 0:a548a085de55 56 #define ICMP_IRQ 15 /* information request */
pehrhovey 0:a548a085de55 57 #define ICMP_IR 16 /* information reply */
pehrhovey 0:a548a085de55 58
pehrhovey 0:a548a085de55 59 enum icmp_dur_type {
pehrhovey 0:a548a085de55 60 ICMP_DUR_NET = 0, /* net unreachable */
pehrhovey 0:a548a085de55 61 ICMP_DUR_HOST = 1, /* host unreachable */
pehrhovey 0:a548a085de55 62 ICMP_DUR_PROTO = 2, /* protocol unreachable */
pehrhovey 0:a548a085de55 63 ICMP_DUR_PORT = 3, /* port unreachable */
pehrhovey 0:a548a085de55 64 ICMP_DUR_FRAG = 4, /* fragmentation needed and DF set */
pehrhovey 0:a548a085de55 65 ICMP_DUR_SR = 5 /* source route failed */
pehrhovey 0:a548a085de55 66 };
pehrhovey 0:a548a085de55 67
pehrhovey 0:a548a085de55 68 enum icmp_te_type {
pehrhovey 0:a548a085de55 69 ICMP_TE_TTL = 0, /* time to live exceeded in transit */
pehrhovey 0:a548a085de55 70 ICMP_TE_FRAG = 1 /* fragment reassembly time exceeded */
pehrhovey 0:a548a085de55 71 };
pehrhovey 0:a548a085de55 72
pehrhovey 0:a548a085de55 73 void icmp_input(struct pbuf *p, struct netif *inp);
pehrhovey 0:a548a085de55 74
pehrhovey 0:a548a085de55 75 void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
pehrhovey 0:a548a085de55 76 void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
pehrhovey 0:a548a085de55 77
pehrhovey 0:a548a085de55 78 #ifdef PACK_STRUCT_USE_INCLUDES
pehrhovey 0:a548a085de55 79 # include "arch/bpstruct.h"
pehrhovey 0:a548a085de55 80 #endif
pehrhovey 0:a548a085de55 81 /** This is the standard ICMP header only that the u32_t data
pehrhovey 0:a548a085de55 82 * is splitted to two u16_t like ICMP echo needs it.
pehrhovey 0:a548a085de55 83 * This header is also used for other ICMP types that do not
pehrhovey 0:a548a085de55 84 * use the data part.
pehrhovey 0:a548a085de55 85 */
pehrhovey 0:a548a085de55 86 PACK_STRUCT_BEGIN
pehrhovey 0:a548a085de55 87 struct icmp_echo_hdr {
pehrhovey 0:a548a085de55 88 PACK_STRUCT_FIELD(u8_t type);
pehrhovey 0:a548a085de55 89 PACK_STRUCT_FIELD(u8_t code);
pehrhovey 0:a548a085de55 90 PACK_STRUCT_FIELD(u16_t chksum);
pehrhovey 0:a548a085de55 91 PACK_STRUCT_FIELD(u16_t id);
pehrhovey 0:a548a085de55 92 PACK_STRUCT_FIELD(u16_t seqno);
pehrhovey 0:a548a085de55 93 } PACK_STRUCT_STRUCT;
pehrhovey 0:a548a085de55 94 PACK_STRUCT_END
pehrhovey 0:a548a085de55 95 #ifdef PACK_STRUCT_USE_INCLUDES
pehrhovey 0:a548a085de55 96 # include "arch/epstruct.h"
pehrhovey 0:a548a085de55 97 #endif
pehrhovey 0:a548a085de55 98
pehrhovey 0:a548a085de55 99 #define ICMPH_TYPE(hdr) ((hdr)->type)
pehrhovey 0:a548a085de55 100 #define ICMPH_CODE(hdr) ((hdr)->code)
pehrhovey 0:a548a085de55 101
pehrhovey 0:a548a085de55 102 /** Combines type and code to an u16_t */
pehrhovey 0:a548a085de55 103 #define ICMPH_TYPE_SET(hdr, t) ((hdr)->type = (t))
pehrhovey 0:a548a085de55 104 #define ICMPH_CODE_SET(hdr, c) ((hdr)->code = (c))
pehrhovey 0:a548a085de55 105
pehrhovey 0:a548a085de55 106 #ifdef __cplusplus
pehrhovey 0:a548a085de55 107 }
pehrhovey 0:a548a085de55 108 #endif
pehrhovey 0:a548a085de55 109
pehrhovey 0:a548a085de55 110 #endif /* LWIP_ICMP */
pehrhovey 0:a548a085de55 111
pehrhovey 0:a548a085de55 112 #endif /* __LWIP_ICMP_H__ */