1/* $KAME: getaddrinfo.c,v 1.15 2000/07/09 04:37:24 itojun Exp $ */ 2 3/* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 40 unchanged lines hidden (view full) --- 49 * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready? 50 * non-loopback address configured? global address configured? 51 * 52 * OS specific notes for freebsd4: 53 * - FreeBSD supported $GAI. The code does not. 54 */ 55 56#include <sys/cdefs.h> |
57__FBSDID("$FreeBSD: head/lib/libc/net/getaddrinfo.c 255328 2013-09-06 21:02:06Z jilles $"); |
58 59#include "namespace.h" 60#include <sys/types.h> 61#include <sys/param.h> 62#include <sys/socket.h> 63#include <net/if.h> 64#include <netinet/in.h> 65#include <sys/queue.h> --- 760 unchanged lines hidden (view full) --- 826 ai.ai_protocol = IPPROTO_UDP; /* is UDP too specific? */ 827 ai.ai_next = NULL; 828 memset(&ss, 0, sizeof(ss)); 829 memcpy(&ss, ai.ai_addr, ai.ai_addrlen); 830 ai.ai_addr = (struct sockaddr *)&ss; 831 get_port(&ai, "1", 0); 832 833 /* open a socket to get the source address for the given dst */ |
834 if ((s = _socket(ai.ai_family, ai.ai_socktype | SOCK_CLOEXEC, 835 ai.ai_protocol)) < 0) |
836 return; /* give up */ 837 if (_connect(s, ai.ai_addr, ai.ai_addrlen) < 0) 838 goto cleanup; 839 srclen = ai.ai_addrlen; 840 if (_getsockname(s, &aio->aio_srcsa, &srclen) < 0) { 841 aio->aio_srcsa.sa_family = AF_UNSPEC; 842 goto cleanup; 843 } --- 283 unchanged lines hidden (view full) --- 1127 1128 *res = NULL; 1129 ai = NULL; 1130 1131 /* 1132 * filter out AFs that are not supported by the kernel 1133 * XXX errno? 1134 */ |
1135 s = _socket(pai->ai_family, SOCK_DGRAM | SOCK_CLOEXEC, 0); |
1136 if (s < 0) { 1137 if (errno != EMFILE) 1138 return 0; 1139 } else 1140 _close(s); 1141 1142 afd = find_afd(pai->ai_family); 1143 if (afd == NULL) --- 393 unchanged lines hidden (view full) --- 1537 * TODO: 1538 * Note that implementation dependent test for address 1539 * configuration should be done everytime called 1540 * (or apropriate interval), 1541 * because addresses will be dynamically assigned or deleted. 1542 */ 1543 af = pai->ai_family; 1544 if (af == AF_UNSPEC) { |
1545 if ((s = _socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) |
1546 af = AF_INET; 1547 else { 1548 _close(s); |
1549 if ((s = _socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 1550 0)) < 0) |
1551 af = AF_INET6; 1552 else 1553 _close(s); 1554 } 1555 } 1556 if (af != AF_UNSPEC) { |
1557 if ((s = _socket(af, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) |
1558 return 0; 1559 _close(s); 1560 } 1561 pai->ai_family = af; 1562 return 1; 1563} 1564 1565#ifdef INET6 --- 1285 unchanged lines hidden --- |