1/*- 2 * Copyright (c) 1985, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 48 unchanged lines hidden (view full) --- 57 * purpose with or without fee is hereby granted, provided that the above 58 * copyright notice and this permission notice appear in all copies. 59 */ 60 61#if defined(LIBC_SCCS) && !defined(lint) 62static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; 63#endif /* LIBC_SCCS and not lint */ 64#include <sys/cdefs.h> |
65__FBSDID("$FreeBSD: head/lib/libc/net/getnetbydns.c 146244 2005-05-15 20:15:15Z ume $"); |
66 67#include <sys/param.h> 68#include <sys/socket.h> 69#include <netinet/in.h> 70#include <arpa/inet.h> 71#include <arpa/nameser.h> 72 73#include <errno.h> --- 180 unchanged lines hidden (view full) --- 254 errno = ENOBUFS; 255 return -1; 256 } 257 ipreverse(in, aux); 258 ne->n_net = inet_network(aux); 259 break; 260 } 261 ne->n_aliases++; |
262#if __LONG_BIT == 64 263 ne->__n_pad0 = 0; /* ABI compatibility */ 264#endif |
265 return 0; 266 } 267 h_errno = TRY_AGAIN; 268 return -1; 269} 270 271int 272_dns_getnetbyaddr(void *rval, void *cb_data, va_list ap) 273{ |
274 uint32_t net; |
275 int net_type; 276 struct netent *ne; 277 struct netent_data *ned; 278 unsigned int netbr[4]; 279 int nn, anslen, error; 280 querybuf *buf; 281 char qbuf[MAXDNAME]; |
282 uint32_t net2; |
283 |
284 net = va_arg(ap, uint32_t); |
285 net_type = va_arg(ap, int); 286 ne = va_arg(ap, struct netent *); 287 ned = va_arg(ap, struct netent_data *); 288 289 if (net_type != AF_INET) 290 return NS_UNAVAIL; 291 292 for (nn = 4, net2 = net; net2; net2 >>= 8) --- 32 unchanged lines hidden (view full) --- 325 if (_res.options & RES_DEBUG) 326 printf("res_search static buffer too small\n"); 327#endif 328 return NS_UNAVAIL; 329 } 330 error = getnetanswer(buf, anslen, BYADDR, ne, ned); 331 free(buf); 332 if (error == 0) { |
333 /* Strip trailing zeros */ |
334 while ((net & 0xff) == 0 && net != 0) 335 net >>= 8; 336 ne->n_net = net; 337#if __LONG_BIT == 64 338 ne->__n_pad0 = 0; /* ABI compatibility */ 339#endif |
340 return NS_SUCCESS; 341 } 342 return NS_NOTFOUND; 343} 344 345int 346_dns_getnetbyname(void *rval, void *cb_data, va_list ap) 347{ --- 56 unchanged lines hidden --- |