mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-11-04 14:29:39 +00:00
Added sequential (socket API) function gethostbyname and the struct hostent it uses
This commit is contained in:
parent
e2cd201f6a
commit
e6ec23d7cc
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user