]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
Added sequential (socket API) function gethostbyname and the struct hostent it uses
authorgoldsimon <goldsimon>
Fri, 16 Nov 2007 17:29:30 +0000 (17:29 +0000)
committergoldsimon <goldsimon>
Fri, 16 Nov 2007 17:29:30 +0000 (17:29 +0000)
CHANGELOG
src/api/sockets.c
src/include/lwip/sockets.h

index ecde64ad2b8d9820ddc6e461c2c898040de0b0be..db65b0fd610c616a68a1819b010564ab1147bede 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -20,8 +20,9 @@ HISTORY
   ++ New features:
 
   2007-11-16 Simon Goldschmidt
-  * api.h, api_msg.h, api_lib.c, api_msg.c: Added sequential dns resolver
-    function for netconn api (netconn_gethostbyname).  
+  * api.h, api_msg.h, api_lib.c, api_msg.c, socket.h, socket.c: Added sequential
+    dns resolver function for netconn api (netconn_gethostbyname) and socket api
+    (gethostbyname).
 
   2007-11-15 Jim Pettinato, Frédéric Bernon
   * opt.h, init.c, tcpip.c, dhcp.c, dns.h, dns.c: add DNS client for simple name
index cca3b932c80fbf950ccaef2fe3fb4c59ad52defe..bb49f79e3a4226fa88cfd4effcdb33c81bcd376e 100644 (file)
@@ -96,6 +96,13 @@ static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len
 static void lwip_getsockopt_internal(void *arg);
 static void lwip_setsockopt_internal(void *arg);
 
+#if LWIP_DNS
+static struct hostent s_hostent;
+static char *s_aliases;
+static struct ip_addr s_hostent_addr;
+static struct ip_addr *s_phostent_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 +1802,39 @@ lwip_ioctl(int s, long cmd, void *argp)
   } /* switch (cmd) */
 }
 
+#if LWIP_DNS
+static void
+lwip_fill_hostent(struct hostent *he, char *name, struct ip_addr **addr, char **aliases)
+{
+  he->h_name = name;
+  he->h_aliases = aliases;
+  he->h_addrtype = AF_INET;
+  he->h_length = sizeof(struct ip_addr);
+  he->h_addr_list = (char**)addr;
+}
+
+
+struct hostent*
+gethostbyname(const char *name)
+{
+  err_t err;
+  struct ip_addr addr;
+
+  err = netconn_gethostbyname(name, &addr);
+  if (err != ERR_OK) {
+    return NULL;
+  }
+
+  s_hostent_addr = addr;
+  s_phostent_addr = &s_hostent_addr;
+  s_hostent.h_name = (char*)name;
+  s_hostent.h_aliases = &s_aliases;
+  s_hostent.h_addrtype = AF_INET;
+  s_hostent.h_length = sizeof(struct ip_addr);
+  s_hostent.h_addr_list = (char**)&s_phostent_addr;
+
+  return &s_hostent;
+}
+#endif /* LWIP_DNS*/
+
 #endif /* LWIP_SOCKET */
index 6d45fa445fbb84159c257c502886f3cb4a1f33ee..08e142fd04e3313b8fc358e9eeffd6207a47d468 100644 (file)
@@ -60,6 +60,19 @@ struct sockaddr {
   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 h_addr h_addr_list[0] /* for backward compatibility */
+};
+#endif /* LWIP_DNS */
+
 #ifndef socklen_t
 #  define socklen_t u32_t
 #endif
@@ -300,6 +313,10 @@ int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptse
                 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)