Deleted Added
full compact
getaddrinfo.c (254700) getaddrinfo.c (255328)
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>
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 254700 2013-08-23 13:59:47Z jilles $");
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 */
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, ai.ai_protocol)) < 0)
834 if ((s = _socket(ai.ai_family, ai.ai_socktype | SOCK_CLOEXEC,
835 ai.ai_protocol)) < 0)
835 return; /* give up */
836 if (_connect(s, ai.ai_addr, ai.ai_addrlen) < 0)
837 goto cleanup;
838 srclen = ai.ai_addrlen;
839 if (_getsockname(s, &aio->aio_srcsa, &srclen) < 0) {
840 aio->aio_srcsa.sa_family = AF_UNSPEC;
841 goto cleanup;
842 }

--- 283 unchanged lines hidden (view full) ---

1126
1127 *res = NULL;
1128 ai = NULL;
1129
1130 /*
1131 * filter out AFs that are not supported by the kernel
1132 * XXX errno?
1133 */
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 */
1134 s = _socket(pai->ai_family, SOCK_DGRAM, 0);
1135 s = _socket(pai->ai_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1135 if (s < 0) {
1136 if (errno != EMFILE)
1137 return 0;
1138 } else
1139 _close(s);
1140
1141 afd = find_afd(pai->ai_family);
1142 if (afd == NULL)

--- 393 unchanged lines hidden (view full) ---

1536 * TODO:
1537 * Note that implementation dependent test for address
1538 * configuration should be done everytime called
1539 * (or apropriate interval),
1540 * because addresses will be dynamically assigned or deleted.
1541 */
1542 af = pai->ai_family;
1543 if (af == AF_UNSPEC) {
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) {
1544 if ((s = _socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
1545 if ((s = _socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0)
1545 af = AF_INET;
1546 else {
1547 _close(s);
1546 af = AF_INET;
1547 else {
1548 _close(s);
1548 if ((s = _socket(AF_INET, SOCK_DGRAM, 0)) < 0)
1549 if ((s = _socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC,
1550 0)) < 0)
1549 af = AF_INET6;
1550 else
1551 _close(s);
1552 }
1553 }
1554 if (af != AF_UNSPEC) {
1551 af = AF_INET6;
1552 else
1553 _close(s);
1554 }
1555 }
1556 if (af != AF_UNSPEC) {
1555 if ((s = _socket(af, SOCK_DGRAM, 0)) < 0)
1557 if ((s = _socket(af, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0)
1556 return 0;
1557 _close(s);
1558 }
1559 pai->ai_family = af;
1560 return 1;
1561}
1562
1563#ifdef INET6

--- 1285 unchanged lines hidden ---
1558 return 0;
1559 _close(s);
1560 }
1561 pai->ai_family = af;
1562 return 1;
1563}
1564
1565#ifdef INET6

--- 1285 unchanged lines hidden ---