Added sequential (socket API) function gethostbyname and the struct hostent it uses

This commit is contained in:
goldsimon 2007-11-16 17:29:30 +00:00
parent e2cd201f6a
commit e6ec23d7cc
3 changed files with 62 additions and 2 deletions

View File

@ -20,8 +20,9 @@ HISTORY
++ New features: ++ New features:
2007-11-16 Simon Goldschmidt 2007-11-16 Simon Goldschmidt
* api.h, api_msg.h, api_lib.c, api_msg.c: Added sequential dns resolver * api.h, api_msg.h, api_lib.c, api_msg.c, socket.h, socket.c: Added sequential
function for netconn api (netconn_gethostbyname). dns resolver function for netconn api (netconn_gethostbyname) and socket api
(gethostbyname).
2007-11-15 Jim Pettinato, Frédéric Bernon 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 * opt.h, init.c, tcpip.c, dhcp.c, dns.h, dns.c: add DNS client for simple name

View 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_getsockopt_internal(void *arg);
static void lwip_setsockopt_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[] = { static const int err_to_errno_table[] = {
0, /* ERR_OK 0 No error, everything OK. */ 0, /* ERR_OK 0 No error, everything OK. */
ENOMEM, /* ERR_MEM -1 Out of memory error. */ ENOMEM, /* ERR_MEM -1 Out of memory error. */
@ -1795,4 +1802,39 @@ lwip_ioctl(int s, long cmd, void *argp)
} /* switch (cmd) */ } /* 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 */ #endif /* LWIP_SOCKET */

View File

@ -60,6 +60,19 @@ struct sockaddr {
char sa_data[14]; 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 #ifndef socklen_t
# define socklen_t u32_t # define socklen_t u32_t
#endif #endif
@ -300,6 +313,10 @@ int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptse
struct timeval *timeout); struct timeval *timeout);
int lwip_ioctl(int s, long cmd, void *argp); 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 #if LWIP_COMPAT_SOCKETS
#define accept(a,b,c) lwip_accept(a,b,c) #define accept(a,b,c) lwip_accept(a,b,c)
#define bind(a,b,c) lwip_bind(a,b,c) #define bind(a,b,c) lwip_bind(a,b,c)