summaryrefslogtreecommitdiff
path: root/src/gns/nss/nss_gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/nss/nss_gns.c')
-rw-r--r--src/gns/nss/nss_gns.c192
1 files changed, 96 insertions, 96 deletions
diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c
index d76eac845..43fc030b9 100644
--- a/src/gns/nss/nss_gns.c
+++ b/src/gns/nss/nss_gns.c
@@ -17,7 +17,7 @@
17 along with nss-mdns; if not, write to the Free Software 17 along with nss-mdns; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 USA. 19 USA.
20***/ 20 ***/
21 21
22#include <gnunet_config.h> 22#include <gnunet_config.h>
23#include <unistd.h> 23#include <unistd.h>
@@ -37,9 +37,9 @@
37 37
38/** macro to align idx to 32bit boundary */ 38/** macro to align idx to 32bit boundary */
39#define ALIGN(idx) do { \ 39#define ALIGN(idx) do { \
40 if (idx % sizeof(void*)) \ 40 if (idx % sizeof(void*)) \
41 idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \ 41 idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \
42} while(0) 42 } while (0)
43 43
44 44
45/** 45/**
@@ -75,7 +75,7 @@ _nss_gns_gethostbyname2_r(const char *name,
75#ifdef NSS_IPV6_ONLY 75#ifdef NSS_IPV6_ONLY
76 af = AF_INET6; 76 af = AF_INET6;
77#else 77#else
78 af = AF_INET; 78 af = AF_INET;
79#endif 79#endif
80 80
81#ifdef NSS_IPV4_ONLY 81#ifdef NSS_IPV4_ONLY
@@ -83,70 +83,70 @@ _nss_gns_gethostbyname2_r(const char *name,
83#elif NSS_IPV6_ONLY 83#elif NSS_IPV6_ONLY
84 if (af != AF_INET6) 84 if (af != AF_INET6)
85#else 85#else
86 if ( (af != AF_INET) && 86 if ((af != AF_INET) &&
87 (af != AF_INET6) ) 87 (af != AF_INET6))
88#endif 88#endif
89 { 89 {
90 *errnop = EINVAL; 90 *errnop = EINVAL;
91 *h_errnop = NO_RECOVERY; 91 *h_errnop = NO_RECOVERY;
92 92
93 goto finish; 93 goto finish;
94 } 94 }
95 95
96 address_length = (af == AF_INET) ? sizeof(ipv4_address_t) : sizeof(ipv6_address_t); 96 address_length = (af == AF_INET) ? sizeof(ipv4_address_t) : sizeof(ipv6_address_t);
97 if (buflen < 97 if (buflen <
98 sizeof(char*) + /* alias names */ 98 sizeof(char*) + /* alias names */
99 strlen (name) + 1) 99 strlen(name) + 1)
100 { /* official name */ 100 { /* official name */
101 *errnop = ERANGE; 101 *errnop = ERANGE;
102 *h_errnop = NO_RECOVERY; 102 *h_errnop = NO_RECOVERY;
103 status = NSS_STATUS_TRYAGAIN; 103 status = NSS_STATUS_TRYAGAIN;
104 104
105 goto finish; 105 goto finish;
106 } 106 }
107 u.count = 0; 107 u.count = 0;
108 u.data_len = 0; 108 u.data_len = 0;
109 i = gns_resolve_name (af, 109 i = gns_resolve_name(af,
110 name, 110 name,
111 &u); 111 &u);
112 if (-1 == i) 112 if (-1 == i)
113 { 113 {
114 *errnop = errno; 114 *errnop = errno;
115 status = NSS_STATUS_UNAVAIL; 115 status = NSS_STATUS_UNAVAIL;
116 *h_errnop = NO_RECOVERY; 116 *h_errnop = NO_RECOVERY;
117 goto finish; 117 goto finish;
118 } 118 }
119 if (-2 == i) 119 if (-2 == i)
120 { 120 {
121 *errnop = ENOENT; 121 *errnop = ENOENT;
122 *h_errnop = NO_RECOVERY; 122 *h_errnop = NO_RECOVERY;
123 status = NSS_STATUS_UNAVAIL; 123 status = NSS_STATUS_UNAVAIL;
124 goto finish; 124 goto finish;
125 } 125 }
126 if (-3 == i) 126 if (-3 == i)
127 { 127 {
128 *errnop = ETIMEDOUT; 128 *errnop = ETIMEDOUT;
129 *h_errnop = HOST_NOT_FOUND; 129 *h_errnop = HOST_NOT_FOUND;
130 status = NSS_STATUS_NOTFOUND; 130 status = NSS_STATUS_NOTFOUND;
131 goto finish; 131 goto finish;
132 } 132 }
133 if (0 == u.count) 133 if (0 == u.count)
134 { 134 {
135 *errnop = 0; /* success */ 135 *errnop = 0; /* success */
136 *h_errnop = NO_DATA; /* success */ 136 *h_errnop = NO_DATA; /* success */
137 status = NSS_STATUS_NOTFOUND; 137 status = NSS_STATUS_NOTFOUND;
138 goto finish; 138 goto finish;
139 } 139 }
140 /* Alias names */ 140 /* Alias names */
141 *((char**) buffer) = NULL; 141 *((char**)buffer) = NULL;
142 result->h_aliases = (char**) buffer; 142 result->h_aliases = (char**)buffer;
143 idx = sizeof(char*); 143 idx = sizeof(char*);
144 144
145 /* Official name */ 145 /* Official name */
146 strcpy (buffer+idx, 146 strcpy(buffer + idx,
147 name); 147 name);
148 result->h_name = buffer+idx; 148 result->h_name = buffer + idx;
149 idx += strlen (name)+1; 149 idx += strlen(name) + 1;
150 150
151 ALIGN(idx); 151 ALIGN(idx);
152 152
@@ -154,29 +154,29 @@ _nss_gns_gethostbyname2_r(const char *name,
154 result->h_length = address_length; 154 result->h_length = address_length;
155 155
156 /* Check if there's enough space for the addresses */ 156 /* Check if there's enough space for the addresses */
157 if (buflen < idx+u.data_len+sizeof(char*)*(u.count+1)) 157 if (buflen < idx + u.data_len + sizeof(char*) * (u.count + 1))
158 { 158 {
159 *errnop = ERANGE; 159 *errnop = ERANGE;
160 *h_errnop = NO_RECOVERY; 160 *h_errnop = NO_RECOVERY;
161 status = NSS_STATUS_TRYAGAIN; 161 status = NSS_STATUS_TRYAGAIN;
162 goto finish; 162 goto finish;
163 } 163 }
164 /* Addresses */ 164 /* Addresses */
165 astart = idx; 165 astart = idx;
166 l = u.count*address_length; 166 l = u.count * address_length;
167 if (0 != l) 167 if (0 != l)
168 memcpy (buffer+astart, 168 memcpy(buffer + astart,
169 &u.data, 169 &u.data,
170 l); 170 l);
171 /* address_length is a multiple of 32bits, so idx is still aligned 171 /* address_length is a multiple of 32bits, so idx is still aligned
172 * correctly */ 172 * correctly */
173 idx += l; 173 idx += l;
174 174
175 /* Address array address_length is always a multiple of 32bits */ 175 /* Address array address_length is always a multiple of 32bits */
176 for (i = 0; i < u.count; i++) 176 for (i = 0; i < u.count; i++)
177 ((char**) (buffer+idx))[i] = buffer+astart+address_length*i; 177 ((char**)(buffer + idx))[i] = buffer + astart + address_length * i;
178 ((char**) (buffer+idx))[i] = NULL; 178 ((char**)(buffer + idx))[i] = NULL;
179 result->h_addr_list = (char**) (buffer+idx); 179 result->h_addr_list = (char**)(buffer + idx);
180 180
181 status = NSS_STATUS_SUCCESS; 181 status = NSS_STATUS_SUCCESS;
182 182
@@ -197,20 +197,20 @@ finish:
197 * @return a nss_status code 197 * @return a nss_status code
198 */ 198 */
199enum nss_status 199enum nss_status
200_nss_gns_gethostbyname_r (const char *name, 200_nss_gns_gethostbyname_r(const char *name,
201 struct hostent *result, 201 struct hostent *result,
202 char *buffer, 202 char *buffer,
203 size_t buflen, 203 size_t buflen,
204 int *errnop, 204 int *errnop,
205 int *h_errnop) 205 int *h_errnop)
206{ 206{
207 return _nss_gns_gethostbyname2_r (name, 207 return _nss_gns_gethostbyname2_r(name,
208 AF_UNSPEC, 208 AF_UNSPEC,
209 result, 209 result,
210 buffer, 210 buffer,
211 buflen, 211 buflen,
212 errnop, 212 errnop,
213 h_errnop); 213 h_errnop);
214} 214}
215 215
216 216
@@ -229,21 +229,21 @@ _nss_gns_gethostbyname_r (const char *name,
229 * @return NSS_STATUS_UNAVAIL 229 * @return NSS_STATUS_UNAVAIL
230 */ 230 */
231enum nss_status 231enum nss_status
232_nss_gns_gethostbyaddr_r (const void* addr, 232_nss_gns_gethostbyaddr_r(const void* addr,
233 int len, 233 int len,
234 int af, 234 int af,
235 struct hostent *result, 235 struct hostent *result,
236 char *buffer, 236 char *buffer,
237 size_t buflen, 237 size_t buflen,
238 int *errnop, 238 int *errnop,
239 int *h_errnop) 239 int *h_errnop)
240{ 240{
241 (void) addr; 241 (void)addr;
242 (void) len; 242 (void)len;
243 (void) af; 243 (void)af;
244 (void) result; 244 (void)result;
245 (void) buffer; 245 (void)buffer;
246 (void) buflen; 246 (void)buflen;
247 *errnop = EINVAL; 247 *errnop = EINVAL;
248 *h_errnop = NO_RECOVERY; 248 *h_errnop = NO_RECOVERY;
249 /* NOTE we allow to leak this into DNS so no NOTFOUND */ 249 /* NOTE we allow to leak this into DNS so no NOTFOUND */