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 * @file
pehrhovey 0:a548a085de55 3 * Loop Interface
pehrhovey 0:a548a085de55 4 *
pehrhovey 0:a548a085de55 5 */
pehrhovey 0:a548a085de55 6
pehrhovey 0:a548a085de55 7 /*
pehrhovey 0:a548a085de55 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
pehrhovey 0:a548a085de55 9 * All rights reserved.
pehrhovey 0:a548a085de55 10 *
pehrhovey 0:a548a085de55 11 * Redistribution and use in source and binary forms, with or without modification,
pehrhovey 0:a548a085de55 12 * are permitted provided that the following conditions are met:
pehrhovey 0:a548a085de55 13 *
pehrhovey 0:a548a085de55 14 * 1. Redistributions of source code must retain the above copyright notice,
pehrhovey 0:a548a085de55 15 * this list of conditions and the following disclaimer.
pehrhovey 0:a548a085de55 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
pehrhovey 0:a548a085de55 17 * this list of conditions and the following disclaimer in the documentation
pehrhovey 0:a548a085de55 18 * and/or other materials provided with the distribution.
pehrhovey 0:a548a085de55 19 * 3. The name of the author may not be used to endorse or promote products
pehrhovey 0:a548a085de55 20 * derived from this software without specific prior written permission.
pehrhovey 0:a548a085de55 21 *
pehrhovey 0:a548a085de55 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
pehrhovey 0:a548a085de55 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
pehrhovey 0:a548a085de55 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
pehrhovey 0:a548a085de55 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
pehrhovey 0:a548a085de55 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
pehrhovey 0:a548a085de55 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
pehrhovey 0:a548a085de55 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
pehrhovey 0:a548a085de55 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
pehrhovey 0:a548a085de55 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
pehrhovey 0:a548a085de55 31 * OF SUCH DAMAGE.
pehrhovey 0:a548a085de55 32 *
pehrhovey 0:a548a085de55 33 * This file is part of the lwIP TCP/IP stack.
pehrhovey 0:a548a085de55 34 *
pehrhovey 0:a548a085de55 35 * Author: Adam Dunkels <adam@sics.se>
pehrhovey 0:a548a085de55 36 *
pehrhovey 0:a548a085de55 37 */
pehrhovey 0:a548a085de55 38 #include "lwip/opt.h"
pehrhovey 0:a548a085de55 39
pehrhovey 0:a548a085de55 40 #if LWIP_HAVE_LOOPIF
pehrhovey 0:a548a085de55 41
pehrhovey 0:a548a085de55 42 #include "netif/loopif.h"
pehrhovey 0:a548a085de55 43 #include "lwip/snmp.h"
pehrhovey 0:a548a085de55 44
pehrhovey 0:a548a085de55 45 /**
pehrhovey 0:a548a085de55 46 * Initialize a lwip network interface structure for a loopback interface
pehrhovey 0:a548a085de55 47 *
pehrhovey 0:a548a085de55 48 * @param netif the lwip network interface structure for this loopif
pehrhovey 0:a548a085de55 49 * @return ERR_OK if the loopif is initialized
pehrhovey 0:a548a085de55 50 * ERR_MEM if private data couldn't be allocated
pehrhovey 0:a548a085de55 51 */
pehrhovey 0:a548a085de55 52 err_t
pehrhovey 0:a548a085de55 53 loopif_init(struct netif *netif)
pehrhovey 0:a548a085de55 54 {
pehrhovey 0:a548a085de55 55 /* initialize the snmp variables and counters inside the struct netif
pehrhovey 0:a548a085de55 56 * ifSpeed: no assumption can be made!
pehrhovey 0:a548a085de55 57 */
pehrhovey 0:a548a085de55 58 NETIF_INIT_SNMP(netif, snmp_ifType_softwareLoopback, 0);
pehrhovey 0:a548a085de55 59
pehrhovey 0:a548a085de55 60 netif->name[0] = 'l';
pehrhovey 0:a548a085de55 61 netif->name[1] = 'o';
pehrhovey 0:a548a085de55 62 netif->output = netif_loop_output;
pehrhovey 0:a548a085de55 63 return ERR_OK;
pehrhovey 0:a548a085de55 64 }
pehrhovey 0:a548a085de55 65
pehrhovey 0:a548a085de55 66 #endif /* LWIP_HAVE_LOOPIF */