Some quick code to use UDP-only (no TCP) with mBed. Echos received packets and sends packets when a button is pressed
netdb.h
00001 /* 00002 * Redistribution and use in source and binary forms, with or without modification, 00003 * are permitted provided that the following conditions are met: 00004 * 00005 * 1. Redistributions of source code must retain the above copyright notice, 00006 * this list of conditions and the following disclaimer. 00007 * 2. Redistributions in binary form must reproduce the above copyright notice, 00008 * this list of conditions and the following disclaimer in the documentation 00009 * and/or other materials provided with the distribution. 00010 * 3. The name of the author may not be used to endorse or promote products 00011 * derived from this software without specific prior written permission. 00012 * 00013 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00014 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00015 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00016 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00017 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00018 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00019 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00020 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00021 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00022 * OF SUCH DAMAGE. 00023 * 00024 * This file is part of the lwIP TCP/IP stack. 00025 * 00026 * Author: Simon Goldschmidt 00027 * 00028 */ 00029 00030 #include "lwip/opt.h" 00031 00032 #if LWIP_DNS && LWIP_SOCKET 00033 00034 #include <stddef.h> /* for size_t */ 00035 00036 #include "lwip/sockets.h" 00037 00038 /* some rarely used options */ 00039 #ifndef LWIP_DNS_API_DECLARE_H_ERRNO 00040 #define LWIP_DNS_API_DECLARE_H_ERRNO 1 00041 #endif 00042 00043 #ifndef LWIP_DNS_API_DEFINE_ERRORS 00044 #define LWIP_DNS_API_DEFINE_ERRORS 1 00045 #endif 00046 00047 #ifndef LWIP_DNS_API_DECLARE_STRUCTS 00048 #define LWIP_DNS_API_DECLARE_STRUCTS 1 00049 #endif 00050 00051 #if LWIP_DNS_API_DEFINE_ERRORS 00052 /** Errors used by the DNS API functions, h_errno can be one of them */ 00053 #define EAI_NONAME 200 00054 #define EAI_SERVICE 201 00055 #define EAI_FAIL 202 00056 #define EAI_MEMORY 203 00057 00058 #define HOST_NOT_FOUND 210 00059 #define NO_DATA 211 00060 #define NO_RECOVERY 212 00061 #define TRY_AGAIN 213 00062 #endif /* LWIP_DNS_API_DEFINE_ERRORS */ 00063 00064 #if LWIP_DNS_API_DECLARE_STRUCTS 00065 struct hostent { 00066 char *h_name; /* Official name of the host. */ 00067 char **h_aliases; /* A pointer to an array of pointers to alternative host names, 00068 terminated by a null pointer. */ 00069 int h_addrtype; /* Address type. */ 00070 int h_length; /* The length, in bytes, of the address. */ 00071 char **h_addr_list; /* A pointer to an array of pointers to network addresses (in 00072 network byte order) for the host, terminated by a null pointer. */ 00073 #define h_addr h_addr_list[0] /* for backward compatibility */ 00074 }; 00075 00076 struct addrinfo { 00077 int ai_flags; /* Input flags. */ 00078 int ai_family; /* Address family of socket. */ 00079 int ai_socktype; /* Socket type. */ 00080 int ai_protocol; /* Protocol of socket. */ 00081 socklen_t ai_addrlen; /* Length of socket address. */ 00082 struct sockaddr *ai_addr; /* Socket address of socket. */ 00083 char *ai_canonname; /* Canonical name of service location. */ 00084 struct addrinfo *ai_next; /* Pointer to next in list. */ 00085 }; 00086 #endif /* LWIP_DNS_API_DECLARE_STRUCTS */ 00087 00088 #if LWIP_DNS_API_DECLARE_H_ERRNO 00089 /* application accessable error code set by the DNS API functions */ 00090 extern int h_errno; 00091 #endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/ 00092 00093 struct hostent *lwip_gethostbyname(const char *name); 00094 int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf, 00095 size_t buflen, struct hostent **result, int *h_errnop); 00096 void lwip_freeaddrinfo(struct addrinfo *ai); 00097 int lwip_getaddrinfo(const char *nodename, 00098 const char *servname, 00099 const struct addrinfo *hints, 00100 struct addrinfo **res); 00101 00102 #if LWIP_COMPAT_SOCKETS 00103 #define gethostbyname(name) lwip_gethostbyname(name) 00104 #define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \ 00105 lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop) 00106 #define freeaddrinfo(addrinfo) lwip_freeaddrinfo(a) 00107 #define getaddrinfo(nodname, servname, hints, res) \ 00108 lwip_getaddrinfo(nodname, servname, hints, res) 00109 #endif /* LWIP_COMPAT_SOCKETS */ 00110 00111 #endif /* LWIP_DNS && LWIP_SOCKET */
Generated on Tue Jul 12 2022 19:17:23 by 1.7.2