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 * Redistribution and use in source and binary forms, with or without modification,
pehrhovey 0:a548a085de55 3 * are permitted provided that the following conditions are met:
pehrhovey 0:a548a085de55 4 *
pehrhovey 0:a548a085de55 5 * 1. Redistributions of source code must retain the above copyright notice,
pehrhovey 0:a548a085de55 6 * this list of conditions and the following disclaimer.
pehrhovey 0:a548a085de55 7 * 2. Redistributions in binary form must reproduce the above copyright notice,
pehrhovey 0:a548a085de55 8 * this list of conditions and the following disclaimer in the documentation
pehrhovey 0:a548a085de55 9 * and/or other materials provided with the distribution.
pehrhovey 0:a548a085de55 10 * 3. The name of the author may not be used to endorse or promote products
pehrhovey 0:a548a085de55 11 * derived from this software without specific prior written permission.
pehrhovey 0:a548a085de55 12 *
pehrhovey 0:a548a085de55 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
pehrhovey 0:a548a085de55 14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
pehrhovey 0:a548a085de55 15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
pehrhovey 0:a548a085de55 16 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
pehrhovey 0:a548a085de55 17 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
pehrhovey 0:a548a085de55 18 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
pehrhovey 0:a548a085de55 19 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
pehrhovey 0:a548a085de55 20 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
pehrhovey 0:a548a085de55 21 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
pehrhovey 0:a548a085de55 22 * OF SUCH DAMAGE.
pehrhovey 0:a548a085de55 23 *
pehrhovey 0:a548a085de55 24 * This file is part of the lwIP TCP/IP stack.
pehrhovey 0:a548a085de55 25 *
pehrhovey 0:a548a085de55 26 * Author: Simon Goldschmidt
pehrhovey 0:a548a085de55 27 *
pehrhovey 0:a548a085de55 28 */
pehrhovey 0:a548a085de55 29
pehrhovey 0:a548a085de55 30 #include "lwip/opt.h"
pehrhovey 0:a548a085de55 31
pehrhovey 0:a548a085de55 32 #if LWIP_DNS && LWIP_SOCKET
pehrhovey 0:a548a085de55 33
pehrhovey 0:a548a085de55 34 #include <stddef.h> /* for size_t */
pehrhovey 0:a548a085de55 35
pehrhovey 0:a548a085de55 36 #include "lwip/sockets.h"
pehrhovey 0:a548a085de55 37
pehrhovey 0:a548a085de55 38 /* some rarely used options */
pehrhovey 0:a548a085de55 39 #ifndef LWIP_DNS_API_DECLARE_H_ERRNO
pehrhovey 0:a548a085de55 40 #define LWIP_DNS_API_DECLARE_H_ERRNO 1
pehrhovey 0:a548a085de55 41 #endif
pehrhovey 0:a548a085de55 42
pehrhovey 0:a548a085de55 43 #ifndef LWIP_DNS_API_DEFINE_ERRORS
pehrhovey 0:a548a085de55 44 #define LWIP_DNS_API_DEFINE_ERRORS 1
pehrhovey 0:a548a085de55 45 #endif
pehrhovey 0:a548a085de55 46
pehrhovey 0:a548a085de55 47 #ifndef LWIP_DNS_API_DECLARE_STRUCTS
pehrhovey 0:a548a085de55 48 #define LWIP_DNS_API_DECLARE_STRUCTS 1
pehrhovey 0:a548a085de55 49 #endif
pehrhovey 0:a548a085de55 50
pehrhovey 0:a548a085de55 51 #if LWIP_DNS_API_DEFINE_ERRORS
pehrhovey 0:a548a085de55 52 /** Errors used by the DNS API functions, h_errno can be one of them */
pehrhovey 0:a548a085de55 53 #define EAI_NONAME 200
pehrhovey 0:a548a085de55 54 #define EAI_SERVICE 201
pehrhovey 0:a548a085de55 55 #define EAI_FAIL 202
pehrhovey 0:a548a085de55 56 #define EAI_MEMORY 203
pehrhovey 0:a548a085de55 57
pehrhovey 0:a548a085de55 58 #define HOST_NOT_FOUND 210
pehrhovey 0:a548a085de55 59 #define NO_DATA 211
pehrhovey 0:a548a085de55 60 #define NO_RECOVERY 212
pehrhovey 0:a548a085de55 61 #define TRY_AGAIN 213
pehrhovey 0:a548a085de55 62 #endif /* LWIP_DNS_API_DEFINE_ERRORS */
pehrhovey 0:a548a085de55 63
pehrhovey 0:a548a085de55 64 #if LWIP_DNS_API_DECLARE_STRUCTS
pehrhovey 0:a548a085de55 65 struct hostent {
pehrhovey 0:a548a085de55 66 char *h_name; /* Official name of the host. */
pehrhovey 0:a548a085de55 67 char **h_aliases; /* A pointer to an array of pointers to alternative host names,
pehrhovey 0:a548a085de55 68 terminated by a null pointer. */
pehrhovey 0:a548a085de55 69 int h_addrtype; /* Address type. */
pehrhovey 0:a548a085de55 70 int h_length; /* The length, in bytes, of the address. */
pehrhovey 0:a548a085de55 71 char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
pehrhovey 0:a548a085de55 72 network byte order) for the host, terminated by a null pointer. */
pehrhovey 0:a548a085de55 73 #define h_addr h_addr_list[0] /* for backward compatibility */
pehrhovey 0:a548a085de55 74 };
pehrhovey 0:a548a085de55 75
pehrhovey 0:a548a085de55 76 struct addrinfo {
pehrhovey 0:a548a085de55 77 int ai_flags; /* Input flags. */
pehrhovey 0:a548a085de55 78 int ai_family; /* Address family of socket. */
pehrhovey 0:a548a085de55 79 int ai_socktype; /* Socket type. */
pehrhovey 0:a548a085de55 80 int ai_protocol; /* Protocol of socket. */
pehrhovey 0:a548a085de55 81 socklen_t ai_addrlen; /* Length of socket address. */
pehrhovey 0:a548a085de55 82 struct sockaddr *ai_addr; /* Socket address of socket. */
pehrhovey 0:a548a085de55 83 char *ai_canonname; /* Canonical name of service location. */
pehrhovey 0:a548a085de55 84 struct addrinfo *ai_next; /* Pointer to next in list. */
pehrhovey 0:a548a085de55 85 };
pehrhovey 0:a548a085de55 86 #endif /* LWIP_DNS_API_DECLARE_STRUCTS */
pehrhovey 0:a548a085de55 87
pehrhovey 0:a548a085de55 88 #if LWIP_DNS_API_DECLARE_H_ERRNO
pehrhovey 0:a548a085de55 89 /* application accessable error code set by the DNS API functions */
pehrhovey 0:a548a085de55 90 extern int h_errno;
pehrhovey 0:a548a085de55 91 #endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/
pehrhovey 0:a548a085de55 92
pehrhovey 0:a548a085de55 93 struct hostent *lwip_gethostbyname(const char *name);
pehrhovey 0:a548a085de55 94 int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
pehrhovey 0:a548a085de55 95 size_t buflen, struct hostent **result, int *h_errnop);
pehrhovey 0:a548a085de55 96 void lwip_freeaddrinfo(struct addrinfo *ai);
pehrhovey 0:a548a085de55 97 int lwip_getaddrinfo(const char *nodename,
pehrhovey 0:a548a085de55 98 const char *servname,
pehrhovey 0:a548a085de55 99 const struct addrinfo *hints,
pehrhovey 0:a548a085de55 100 struct addrinfo **res);
pehrhovey 0:a548a085de55 101
pehrhovey 0:a548a085de55 102 #if LWIP_COMPAT_SOCKETS
pehrhovey 0:a548a085de55 103 #define gethostbyname(name) lwip_gethostbyname(name)
pehrhovey 0:a548a085de55 104 #define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \
pehrhovey 0:a548a085de55 105 lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop)
pehrhovey 0:a548a085de55 106 #define freeaddrinfo(addrinfo) lwip_freeaddrinfo(a)
pehrhovey 0:a548a085de55 107 #define getaddrinfo(nodname, servname, hints, res) \
pehrhovey 0:a548a085de55 108 lwip_getaddrinfo(nodname, servname, hints, res)
pehrhovey 0:a548a085de55 109 #endif /* LWIP_COMPAT_SOCKETS */
pehrhovey 0:a548a085de55 110
pehrhovey 0:a548a085de55 111 #endif /* LWIP_DNS && LWIP_SOCKET */