Index: src/api/api_lib.c
===================================================================
RCS file: /sources/lwip/lwip/src/api/api_lib.c,v
retrieving revision 1.75
diff -u -r1.75 api_lib.c
--- src/api/api_lib.c	12 Nov 2007 22:39:24 -0000	1.75
+++ src/api/api_lib.c	15 Nov 2007 21:02:04 -0000
@@ -566,4 +566,42 @@
 }
 #endif /* LWIP_IGMP */
 
+#if LWIP_DNS
+/**
+ * Execute a DNS query
+ *
+ * @param conn a netconn which is only necessary because its mbox is needed to
+ *        wait for the response
+ * @param hostname a string representation of the DNS host name
+ * @param addres a preallocated struct ip_addr where to store the resolved address
+ * @return an error returned by the dns module, ERR_OK if resolving succeeded
+ */
+err_t
+netconn_gethostbyname(const char *name, struct ip_addr *addr)
+{
+  struct api_msg_msg msg;
+  err_t err;
+  sys_sem_t sem;
+
+  LWIP_ERROR("netconn_gethostbyname: invalid name", (name != NULL), return ERR_ARG;);
+  LWIP_ERROR("netconn_gethostbyname: invalid addr", (addr != NULL), return ERR_ARG;);
+
+  sem = sys_sem_new(0);
+  if (sem == SYS_SEM_NULL) {
+    return ERR_MEM;
+  }
+
+  msg.msg.dns.name = name;
+  msg.msg.dns.addr = addr;
+  msg.msg.dns.err = &err;
+  msg.msg.dns.sem = sem;
+
+  tcpip_callback(do_gethostbyname, &msg);
+  sys_sem_wait(sem);
+  sys_sem_free(sem);
+
+  return err;
+}
+#endif /* LWIP_DNS*/
+
 #endif /* LWIP_NETCONN */
Index: src/api/api_msg.c
===================================================================
RCS file: /sources/lwip/lwip/src/api/api_msg.c,v
retrieving revision 1.77
diff -u -r1.77 api_msg.c
--- src/api/api_msg.c	12 Nov 2007 22:39:24 -0000	1.77
+++ src/api/api_msg.c	15 Nov 2007 21:03:33 -0000
@@ -50,6 +50,7 @@
 #include "lwip/memp.h"
 #include "lwip/tcpip.h"
 #include "lwip/igmp.h"
+#include "lwip/dns.h"
 
 /* forward declarations */
 #if LWIP_TCP
@@ -989,5 +990,49 @@
 }
 #endif /* LWIP_IGMP */
 
+#if LWIP_DNS
+static void
+do_dns_found(const char *name, struct ip_addr *ipaddr, void *arg)
+{
+  struct api_msg_msg *msg = (struct api_msg_msg*)arg;
+
+  LWIP_ASSERT("DNS response for wrong host name", strcmp(msg->msg.dns.name, name) == 0);
+
+  if (ipaddr == NULL) {
+    *msg->msg.dns.err = ERR_VAL;
+  } else {
+    *msg->msg.dns.err = ERR_OK;
+    *msg->msg.dns.addr = *ipaddr;
+  }
+  sys_sem_signal(msg->msg.dns.sem);
+}
+
+/**
+ * Join multicast groups for UDP netconns.
+ * Called from netconn_join_leave_group
+ *
+ * @param msg the api_msg_msg pointing to the connection
+ */
+void
+do_gethostbyname(void *arg)
+{
+  DNS_RESULT res;
+  struct api_msg_msg *msg = (struct api_msg_msg*)arg;
+
+  res = dns_gethostbyname(msg->msg.dns.name, msg->msg.dns.addr, do_dns_found, msg);
+  if (res != DNS_QUERY_QUEUED) {
+    /* If not queued, return to app thread directly */
+    if (res == DNS_QUERY_INVALID) {
+      /* some error occurred */
+      *msg->msg.dns.err = ERR_ARG;
+    } else if (res == DNS_COMPLETE) {
+      /* name was already in octet notation or cached */
+      *msg->msg.dns.err = ERR_OK;
+    }
+    sys_sem_signal(msg->msg.dns.sem);
+  }
+}
+#endif /* LWIP_DNS */
+
 #endif /* LWIP_NETCONN */
 
Index: src/api/sockets.c
===================================================================
RCS file: /sources/lwip/lwip/src/api/sockets.c,v
retrieving revision 1.97
diff -u -r1.97 sockets.c
--- src/api/sockets.c	12 Nov 2007 22:39:24 -0000	1.97
+++ src/api/sockets.c	15 Nov 2007 20:57:35 -0000
@@ -96,6 +96,11 @@
 static void lwip_getsockopt_internal(void *arg);
 static void lwip_setsockopt_internal(void *arg);
 
+#if LWIP_DNS
+static struct hostent s_hostent;
+static struct ip_addr s_hostent_addr;
+#endif /* LWIP_DNS */
+
 static const int err_to_errno_table[] = {
   0,             /* ERR_OK       0      No error, everything OK. */
   ENOMEM,        /* ERR_MEM     -1      Out of memory error.     */
@@ -1795,4 +1800,26 @@
   } /* switch (cmd) */
 }
 
+#if LWIP_DNS
+struct hostent*
+gethostbyname(const char *name)
+{
+  err_t err;
+  struct ip_addr addr;
+  SYS_ARCH_DECL_PROTECT(lev);
+
+  err = netconn_gethostbyname(name, &addr);
+  if (err != ERR_OK) {
+    return NULL;
+  }
+
+  SYS_ARCH_PROTECT(lev);
+  s_hostent_addr = addr;
+  lwip_fill_hostent(&s_hostent, (char*)name, (char**)&s_hostent_addr);
+  SYS_ARCH_UNPROTECT(lev);
+
+  return &s_hostent;
+}
+#endif /* LWIP_DNS*/
+
 #endif /* LWIP_SOCKET */
Index: src/core/dns.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/dns.c,v
retrieving revision 1.1
diff -u -r1.1 dns.c
--- src/core/dns.c	14 Nov 2007 23:27:13 -0000	1.1
+++ src/core/dns.c	15 Nov 2007 20:11:01 -0000
@@ -209,7 +209,7 @@
   u8_t err;
   char name[DNS_MAX_NAME_LENGTH];
   struct ip_addr ipaddr;
-  void (* found)(char *name, struct ip_addr *ipaddr, void *arg); /* pointer to callback on DNS query done */
+  void (* found)(const char *name, struct ip_addr *ipaddr, void *arg); /* pointer to callback on DNS query done */
   void *arg;
 } PACK_STRUCT_STRUCT;
 PACK_STRUCT_END
@@ -322,7 +322,7 @@
  * hostnames.
  */
 u32_t
-dns_lookup(char *name)
+dns_lookup(const char *name)
 {
   u8_t i;
 
@@ -364,11 +364,12 @@
  * dns_send
  */
 static err_t
-dns_send( char* name, u8_t id)
+dns_send(const char* name, u8_t id)
 { 
   struct dns_hdr *hdr;
   struct pbuf *p;
-  char *query, *nptr, *pHostname;
+  char *query, *nptr;
+  const char *pHostname;
   u8_t n;
 
   LWIP_DEBUGF(DNS_DEBUG, ("dns_send: \"%s\": request\n", name));
@@ -560,7 +561,7 @@
  * param name - The hostname that is to be queried.
  */
 static void
-dns_query(char *name, void (*found)(char *name, struct ip_addr *addr, void *arg), void *arg)
+dns_query(const char *name, void (*found)(const char *name, struct ip_addr *addr, void *arg), void *arg)
 {
   u8_t i;
   u8_t lseq, lseqi;
@@ -603,7 +604,7 @@
 /**
  * NON-BLOCKING callback version for use with raw API
  */
-DNS_RESULT dns_gethostbyname(char *hostname, struct ip_addr *addr, 
+DNS_RESULT dns_gethostbyname(const char *hostname, struct ip_addr *addr, 
                              void (*found)(char *name, struct ip_addr *ipaddr, void *arg),
                              void *arg
                              )
Index: src/include/lwip/api.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/api.h,v
retrieving revision 1.36
diff -u -r1.36 api.h
--- src/include/lwip/api.h	12 Nov 2007 22:39:24 -0000	1.36
+++ src/include/lwip/api.h	15 Nov 2007 20:41:31 -0000
@@ -181,6 +181,9 @@
                                             struct ip_addr *interface,
                                             enum netconn_igmp join_or_leave);
 #endif /* LWIP_IGMP */
+#if LWIP_DNS
+err_t             netconn_gethostbyname(const char *name, struct ip_addr *addr);
+#endif /* LWIP_DNS */
 
 #define netconn_err(conn)          ((conn)->err)
 #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
Index: src/include/lwip/api_msg.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/api_msg.h,v
retrieving revision 1.22
diff -u -r1.22 api_msg.h
--- src/include/lwip/api_msg.h	12 Nov 2007 22:39:24 -0000	1.22
+++ src/include/lwip/api_msg.h	15 Nov 2007 20:44:39 -0000
@@ -37,6 +37,8 @@
 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
 
 #include "lwip/ip_addr.h"
+#include "lwip/err.h"
+#include "lwip/sys.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -78,6 +80,14 @@
       enum netconn_igmp join_or_leave;
     } jl; /* do_join_leave_group */
 #endif /* LWIP_IGMP */
+#if LWIP_DNS
+    struct {
+      const char *name;
+      struct ip_addr *addr;
+      sys_sem_t sem;
+      err_t *err;
+    } dns;
+#endif /* LWIP_DNS */
   } msg;
 };
 
@@ -101,6 +111,10 @@
 void do_join_leave_group( struct api_msg_msg *msg);
 #endif /* LWIP_IGMP */
 
+#if LWIP_DNS
+void do_gethostbyname(void *arg);
+#endif /* LWIP_DNS */
+
 #ifdef __cplusplus
 }
 #endif
Index: src/include/lwip/dns.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/dns.h,v
retrieving revision 1.1
diff -u -r1.1 dns.h
--- src/include/lwip/dns.h	14 Nov 2007 23:27:13 -0000	1.1
+++ src/include/lwip/dns.h	15 Nov 2007 20:09:42 -0000
@@ -63,11 +63,11 @@
 u32_t dns_getserver(u8_t numdns);
 
 /* returns IP for host 'name' only if already in table */
-u32_t dns_lookup(char *name);
+u32_t dns_lookup(const char *name);
 
 /* resolove a host 'name' in ip address */
-DNS_RESULT dns_gethostbyname(char *hostName, struct ip_addr *addr, 
-                             void (*found)(char *name, struct ip_addr *ipaddr, void *arg),
+DNS_RESULT dns_gethostbyname(const char *hostName, struct ip_addr *addr, 
+                             void (*found)(const char *name, struct ip_addr *ipaddr, void *arg),
                              void *arg);
 
 /* dns_gethostbyname() - Returns immediately with one of DNS_RESULT return codes
Index: src/include/lwip/sockets.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/sockets.h,v
retrieving revision 1.32
diff -u -r1.32 sockets.h
--- src/include/lwip/sockets.h	1 Nov 2007 17:37:51 -0000	1.32
+++ src/include/lwip/sockets.h	15 Nov 2007 20:57:03 -0000
@@ -60,6 +60,28 @@
   char sa_data[14];
 };
 
+#if LWIP_DNS
+struct hostent {
+    char  *h_name;      /* Official name of the host. */
+    char **h_aliases;   /* A pointer to an array of pointers to alternative host names,
+                           terminated by a null pointer. */
+    int    h_addrtype;  /* Address type. */
+    int    h_length;    /* The length, in bytes, of the address. */
+    char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
+                           network byte order) for the host, terminated by a null pointer. */
+};
+
+#define lwip_fill_hostent(he, name, addr) \
+  do { \
+    (he)->h_name = name; \
+    (he)->h_aliases = NULL; \
+    (he)->h_addrtype = AF_INET; \
+    (he)->h_length = sizeof(struct ip_addr); \
+    (he)->h_addr_list = addr; \
+  } while(0)
+
+#endif /* LWIP_DNS */
+
 #ifndef socklen_t
 #  define socklen_t u32_t
 #endif
@@ -300,6 +322,10 @@
                 struct timeval *timeout);
 int lwip_ioctl(int s, long cmd, void *argp);
 
+#if LWIP_DNS
+struct hostent *gethostbyname(const char *name);
+#endif /* LWIP_DNS */
+
 #if LWIP_COMPAT_SOCKETS
 #define accept(a,b,c)         lwip_accept(a,b,c)
 #define bind(a,b,c)           lwip_bind(a,b,c)
