mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
socket-util: New function lookup_hostname().
This is equivalent to lookup_ip() except that it accepts DNS names also.
This commit is contained in:
@@ -145,6 +145,37 @@ lookup_ipv6(const char *host_name, struct in6_addr *addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Translates 'host_name', which must be a host name or a string representation
|
||||
* of an IP address, into a numeric IP address in '*addr'. Returns 0 if
|
||||
* successful, otherwise a positive errno value.
|
||||
*
|
||||
* Most Open vSwitch code should not use this because it causes deadlocks:
|
||||
* gethostbyname() sends out a DNS request but that starts a new flow for which
|
||||
* OVS must set up a flow, but it can't because it's waiting for a DNS reply.
|
||||
* The synchronous lookup also delays other activty. (Of course we can solve
|
||||
* this but it doesn't seem worthwhile quite yet.) */
|
||||
int
|
||||
lookup_hostname(const char *host_name, struct in_addr *addr)
|
||||
{
|
||||
struct hostent *h;
|
||||
|
||||
if (inet_aton(host_name, addr)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
h = gethostbyname(host_name);
|
||||
if (h) {
|
||||
*addr = *(struct in_addr *) h->h_addr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (h_errno == HOST_NOT_FOUND ? ENOENT
|
||||
: h_errno == TRY_AGAIN ? EAGAIN
|
||||
: h_errno == NO_RECOVERY ? EIO
|
||||
: h_errno == NO_ADDRESS ? ENXIO
|
||||
: EINVAL);
|
||||
}
|
||||
|
||||
/* Returns the error condition associated with socket 'fd' and resets the
|
||||
* socket's error status. */
|
||||
int
|
||||
|
@@ -24,8 +24,12 @@
|
||||
|
||||
int set_nonblocking(int fd);
|
||||
int get_max_fds(void);
|
||||
|
||||
int lookup_ip(const char *host_name, struct in_addr *address);
|
||||
int lookup_ipv6(const char *host_name, struct in6_addr *address);
|
||||
|
||||
int lookup_hostname(const char *host_name, struct in_addr *);
|
||||
|
||||
int get_socket_error(int sock);
|
||||
int check_connection_completion(int fd);
|
||||
int drain_rcvbuf(int fd);
|
||||
|
Reference in New Issue
Block a user