summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-10-15 16:11:48 -0700
committerJeremy Allison <jra@samba.org>2007-10-15 16:11:48 -0700
commit666f50b01f282e520c59b94944d4b1583168d46a (patch)
tree9acb499f1bdfdb1a285a3392708b0c942fc2c17e /source3/libsmb
parent48cd61d30ed46e2c61c0df9d510f50ae7a11accd (diff)
downloadsamba-666f50b01f282e520c59b94944d4b1583168d46a.tar.gz
samba-666f50b01f282e520c59b94944d4b1583168d46a.tar.bz2
samba-666f50b01f282e520c59b94944d4b1583168d46a.zip
Move to protocol independent code in most of lib/util_sock.c
We don't use gethostbyname any more except in one case where we're looking for host aliases (I don't know how to do that with getaddrinfo yet). New function should be getaddrinfo(). Next step will be fixing lib/access.c, and then changing libsmb/namequery.c to cope with IPv6 address returns. Jeremy. (This used to be commit 4a56b697b6adcf095e25895c4a9ba3192ed34124)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/namequery.c60
1 files changed, 50 insertions, 10 deletions
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index 182d3641f7..5459210c64 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -1028,8 +1028,12 @@ static NTSTATUS resolve_hosts(const char *name, int name_type,
/*
* "host" means do a localhost, or dns lookup.
*/
- struct hostent *hp;
-
+ struct addrinfo hints;
+ struct addrinfo *ailist = NULL;
+ struct addrinfo *res = NULL;
+ int ret = -1;
+ int i = 0;
+
if ( name_type != 0x20 && name_type != 0x0) {
DEBUG(5, ("resolve_hosts: not appropriate for name type <0x%x>\n", name_type));
return NT_STATUS_INVALID_PARAMETER;
@@ -1039,18 +1043,54 @@ static NTSTATUS resolve_hosts(const char *name, int name_type,
*return_count = 0;
DEBUG(3,("resolve_hosts: Attempting host lookup for name %s<0x%x>\n", name, name_type));
-
- if (((hp = sys_gethostbyname(name)) != NULL) && (hp->h_addr != NULL)) {
+
+ ZERO_STRUCT(hints);
+ /* By default make sure it supports TCP. */
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_ADDRCONFIG;
+
+ ret = getaddrinfo(name,
+ NULL,
+ &hints,
+ &ailist);
+ if (ret) {
+ DEBUG(3,("resolve_hosts: getaddrinfo failed for name %s [%s]\n",
+ name,
+ gai_strerror(ret) ));
+ }
+
+ for (res = ailist; res; res = res->ai_next) {
struct in_addr return_ip;
- putip((char *)&return_ip,(char *)hp->h_addr);
- *return_iplist = SMB_MALLOC_P(struct ip_service);
- if(*return_iplist == NULL) {
+
+ /* IPv4 only for now until I convert ip_service */
+ if (res->ai_family != AF_INET) {
+ continue;
+ }
+ if (!res->ai_addr) {
+ continue;
+ }
+
+ putip((char *)&return_ip,
+ &((struct sockaddr_in *)res->ai_addr)->sin_addr);
+
+ *return_count += 1;
+ i++;
+
+ *return_iplist = SMB_REALLOC_ARRAY(*return_iplist,
+ struct ip_service,
+ *return_count);
+ if (!*return_iplist) {
DEBUG(3,("resolve_hosts: malloc fail !\n"));
+ freeaddrinfo(ailist);
return NT_STATUS_NO_MEMORY;
}
- (*return_iplist)->ip = return_ip;
- (*return_iplist)->port = PORT_NONE;
- *return_count = 1;
+ (*return_iplist)[i].ip = return_ip;
+ (*return_iplist)[i].port = PORT_NONE;
+ }
+ if (ailist) {
+ freeaddrinfo(ailist);
+ }
+ if (*return_count) {
return NT_STATUS_OK;
}
return NT_STATUS_UNSUCCESSFUL;