summaryrefslogtreecommitdiff
path: root/openbsd-compat/fake-getaddrinfo.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2003-05-14 21:48:51 +1000
committerDarren Tucker <dtucker@zip.com.au>2003-05-14 21:48:51 +1000
commitabef5628e833163d5666736184e06e9af81d2636 (patch)
treecd7f276d4e9a428a68180ae0eab259a4ab9afbe6 /openbsd-compat/fake-getaddrinfo.c
parentbe64d43d01bd6cdad89fee1db0e3b559d97cef96 (diff)
- (dtucker) Set ai_socktype and ai_protocol in fake-getaddrinfo.c. ok djm@
Diffstat (limited to 'openbsd-compat/fake-getaddrinfo.c')
-rw-r--r--openbsd-compat/fake-getaddrinfo.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/openbsd-compat/fake-getaddrinfo.c b/openbsd-compat/fake-getaddrinfo.c
index e63bda970..34e1fce78 100644
--- a/openbsd-compat/fake-getaddrinfo.c
+++ b/openbsd-compat/fake-getaddrinfo.c
@@ -12,7 +12,7 @@
12#include "includes.h" 12#include "includes.h"
13#include "ssh.h" 13#include "ssh.h"
14 14
15RCSID("$Id: fake-getaddrinfo.c,v 1.5 2003/03/24 02:35:59 djm Exp $"); 15RCSID("$Id: fake-getaddrinfo.c,v 1.6 2003/05/14 11:48:51 dtucker Exp $");
16 16
17#ifndef HAVE_GAI_STRERROR 17#ifndef HAVE_GAI_STRERROR
18char *gai_strerror(int ecode) 18char *gai_strerror(int ecode)
@@ -41,7 +41,8 @@ void freeaddrinfo(struct addrinfo *ai)
41#endif /* !HAVE_FREEADDRINFO */ 41#endif /* !HAVE_FREEADDRINFO */
42 42
43#ifndef HAVE_GETADDRINFO 43#ifndef HAVE_GETADDRINFO
44static struct addrinfo *malloc_ai(int port, u_long addr) 44static struct addrinfo *malloc_ai(int port, u_long addr,
45 const struct addrinfo *hints)
45{ 46{
46 struct addrinfo *ai; 47 struct addrinfo *ai;
47 48
@@ -59,6 +60,15 @@ static struct addrinfo *malloc_ai(int port, u_long addr)
59 ((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port; 60 ((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port;
60 ((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr; 61 ((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr;
61 62
63 /* XXX: the following is not generally correct, but does what we want */
64 if (hints->ai_socktype)
65 ai->ai_socktype = hints->ai_socktype;
66 else
67 ai->ai_socktype = SOCK_STREAM;
68
69 if (hints->ai_protocol)
70 ai->ai_protocol = hints->ai_protocol;
71
62 return(ai); 72 return(ai);
63} 73}
64 74
@@ -90,21 +100,21 @@ int getaddrinfo(const char *hostname, const char *servname,
90 addr = htonl(0x00000000); 100 addr = htonl(0x00000000);
91 if (hostname && inet_aton(hostname, &in) != 0) 101 if (hostname && inet_aton(hostname, &in) != 0)
92 addr = in.s_addr; 102 addr = in.s_addr;
93 if (NULL != (*res = malloc_ai(port, addr))) 103 if (NULL != (*res = malloc_ai(port, addr, hints)))
94 return 0; 104 return 0;
95 else 105 else
96 return EAI_MEMORY; 106 return EAI_MEMORY;
97 } 107 }
98 108
99 if (!hostname) { 109 if (!hostname) {
100 if (NULL != (*res = malloc_ai(port, htonl(0x7f000001)))) 110 if (NULL != (*res = malloc_ai(port, htonl(0x7f000001), hints)))
101 return 0; 111 return 0;
102 else 112 else
103 return EAI_MEMORY; 113 return EAI_MEMORY;
104 } 114 }
105 115
106 if (inet_aton(hostname, &in)) { 116 if (inet_aton(hostname, &in)) {
107 if (NULL != (*res = malloc_ai(port, in.s_addr))) 117 if (NULL != (*res = malloc_ai(port, in.s_addr, hints)))
108 return 0; 118 return 0;
109 else 119 else
110 return EAI_MEMORY; 120 return EAI_MEMORY;
@@ -113,7 +123,8 @@ int getaddrinfo(const char *hostname, const char *servname,
113 hp = gethostbyname(hostname); 123 hp = gethostbyname(hostname);
114 if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) { 124 if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) {
115 for (i = 0; hp->h_addr_list[i]; i++) { 125 for (i = 0; hp->h_addr_list[i]; i++) {
116 cur = malloc_ai(port, ((struct in_addr *)hp->h_addr_list[i])->s_addr); 126 cur = malloc_ai(port,
127 ((struct in_addr *)hp->h_addr_list[i])->s_addr, hints);
117 if (cur == NULL) { 128 if (cur == NULL) {
118 if (*res) 129 if (*res)
119 freeaddrinfo(*res); 130 freeaddrinfo(*res);