]> git.saurik.com Git - apple/libinfo.git/commitdiff
Libinfo-222.4.9.tar.gz mac-os-x-1048x86 v222.4.9
authorApple <opensource@apple.com>
Wed, 16 Aug 2006 16:39:44 +0000 (16:39 +0000)
committerApple <opensource@apple.com>
Wed, 16 Aug 2006 16:39:44 +0000 (16:39 +0000)
lookup.subproj/getaddrinfo.c
lookup.subproj/lu_alias.c
lookup.subproj/lu_bootparam.c
lookup.subproj/lu_fstab.c
lookup.subproj/lu_network.c
lookup.subproj/lu_printer.c
lookup.subproj/lu_protocol.c
lookup.subproj/lu_rpc.c

index ce51a5e784dbeb14cbf2a57fd855e6ab38b23077..6f9bc5d9cf5d6146b56daadddc9b5ba5a4527eef 100644 (file)
@@ -59,54 +59,57 @@ extern mach_port_t _lookupd_port();
 static int gai_proc = -1;
 static int gni_proc = -1;
 
-static int32_t supported_family[] =
+static const int32_t supported_family[] =
 {
        PF_UNSPEC,
        PF_INET,
        PF_INET6
 };
-static int32_t supported_family_count = 3;
+static const int32_t supported_family_count = (sizeof(supported_family) / sizeof(supported_family[0]));
 
-static int32_t supported_socket[] =
+static const int32_t supported_socket[] =
 {
        SOCK_RAW,
        SOCK_UNSPEC,
        SOCK_DGRAM,
        SOCK_STREAM
 };
-static int32_t supported_socket_count = 4;
+static const int32_t supported_socket_count = (sizeof(supported_socket) / sizeof(supported_socket[0]));
 
-static int32_t supported_protocol[] =
+static const int32_t supported_protocol[] =
 {
        IPPROTO_UNSPEC,
+       IPPROTO_ICMP,
        IPPROTO_ICMPV6,
        IPPROTO_UDP,
        IPPROTO_TCP
 };
-static int32_t supported_protocol_count = 4;
+static const int32_t supported_protocol_count = (sizeof(supported_protocol) / sizeof(supported_protocol[0]));
 
-static int32_t supported_socket_protocol_pair[] =
+static const int32_t supported_socket_protocol_pair[] =
 {
        SOCK_RAW,    IPPROTO_UNSPEC,
        SOCK_RAW,    IPPROTO_UDP,
        SOCK_RAW,    IPPROTO_TCP,
+       SOCK_RAW,    IPPROTO_ICMP,
        SOCK_RAW,    IPPROTO_ICMPV6,
        SOCK_UNSPEC, IPPROTO_UNSPEC,
        SOCK_UNSPEC, IPPROTO_UDP,
        SOCK_UNSPEC, IPPROTO_TCP,
+       SOCK_UNSPEC, IPPROTO_ICMP,
        SOCK_UNSPEC, IPPROTO_ICMPV6,
        SOCK_DGRAM,  IPPROTO_UNSPEC,
        SOCK_DGRAM,  IPPROTO_UDP,
        SOCK_STREAM, IPPROTO_UNSPEC,
        SOCK_STREAM, IPPROTO_TCP
 };
-static int32_t supported_socket_protocol_pair_count = 12;
+static const int32_t supported_socket_protocol_pair_count = (sizeof(supported_socket_protocol_pair) / (sizeof(supported_socket_protocol_pair[0]) * 2));
 
 static int
 gai_family_type_check(int32_t f)
 {
        int32_t i;
-       
+
        for (i = 0; i < supported_family_count; i++)
        {
                if (f == supported_family[i]) return 0;
@@ -119,7 +122,7 @@ static int
 gai_socket_type_check(int32_t s)
 {
        int32_t i;
-       
+
        for (i = 0; i < supported_socket_count; i++)
        {
                if (s == supported_socket[i]) return 0;
@@ -132,7 +135,7 @@ static int
 gai_protocol_type_check(int32_t p)
 {
        int32_t i;
-       
+
        for (i = 0; i < supported_protocol_count; i++)
        {
                if (p == supported_protocol[i]) return 0;
@@ -145,7 +148,7 @@ static int
 gai_socket_protocol_type_check(int32_t s, int32_t p)
 {
        int32_t i, j, ss, sp;
-       
+
        for (i = 0, j = 0; i < supported_socket_protocol_pair_count; i++, j+=2)
        {
                ss = supported_socket_protocol_pair[j];
@@ -547,7 +550,7 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo
                        return EAI_SYSTEM;
                }
        }
-       
+
        if (socktype != SOCK_UNSPEC)
        {
                snprintf(str, 64, "%u", socktype);
@@ -557,7 +560,7 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo
                        return EAI_SYSTEM;
                }
        }
-       
+
        if (family != PF_UNSPEC)
        {
                snprintf(str, 64, "%u", family);
@@ -567,7 +570,7 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo
                        return EAI_SYSTEM;
                }
        }
-       
+
        if (canonname != 0)
        {
                if (encode_kv(&outxdr, "canonname", "1") != 0)
@@ -576,7 +579,7 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo
                        return EAI_SYSTEM;
                }
        }
-       
+
        if (passive != 0)
        {
                if (encode_kv(&outxdr, "passive", "1") != 0)
@@ -585,7 +588,7 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo
                        return EAI_SYSTEM;
                }
        }
-       
+
        if (parallel != 0)
        {
                if (encode_kv(&outxdr, "parallel", "1") != 0)
@@ -594,7 +597,7 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo
                        return EAI_SYSTEM;
                }
        }
-       
+
        if (numerichost != 0)
        {
                if (encode_kv(&outxdr, "numerichost", "1") != 0)
@@ -607,7 +610,7 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo
        *len = xdr_getpos(&outxdr);
 
        xdr_destroy(&outxdr);
-       
+
        return 0;
 }
 
@@ -627,10 +630,128 @@ is_a_number(const char *s)
        return 1;
 }
 
+static int
+gai_trivial(struct in_addr *in4, struct in6_addr *in6, int16_t port, const struct addrinfo *hints, struct addrinfo **res)
+{
+       int32_t family, wantv4, wantv6, proto;
+       char *loopv4, *loopv6;
+       struct in_addr a4;
+       struct in6_addr a6;
+       struct addrinfo *a;
+
+       family = PF_UNSPEC;
+       if (hints != NULL) family = hints->ai_family;
+
+       wantv4 = 1;
+       wantv6 = 1;
+
+       if (family == PF_INET6) wantv4 = 0;
+       if (family == PF_INET) wantv6 = 0;
+
+       memset(&a4, 0, sizeof(struct in_addr));
+       memset(&a6, 0, sizeof(struct in6_addr));
+
+       if ((in4 == NULL) && (in6 == NULL))
+       {
+               loopv4 = "127.0.0.1";
+               loopv6 = "0:0:0:0:0:0:0:1";
+
+               if ((hints != NULL) && ((hints->ai_flags & AI_PASSIVE) == 1))
+               {
+                       loopv4 = "0.0.0.0";
+                       loopv6 = "0:0:0:0:0:0:0:0";
+               }
+
+               if ((family == PF_UNSPEC) || (family == PF_INET))
+               {
+                       inet_pton(AF_INET, loopv4, &a4);
+               }
+
+               if ((family == PF_UNSPEC) || (family == PF_INET6))
+               {
+                       inet_pton(AF_INET6, loopv6, &a6);
+               }
+       }
+       else if (in4 == NULL)
+       {
+               if (family == PF_INET) return EAI_BADHINTS;
+
+               wantv4 = 0;
+               memcpy(&a6, in6, sizeof(struct in6_addr));
+       }
+       else if (in6 == NULL)
+       {
+               if (family == PF_INET6) return EAI_BADHINTS;
+
+               wantv6 = 0;
+               memcpy(&a4, in4, sizeof(struct in_addr));
+       }
+       else
+       {
+               return EAI_NODATA;
+       }
+
+       proto = IPPROTO_UNSPEC;
+
+       if (hints != NULL)
+       {
+               proto = hints->ai_protocol;
+               if (proto == IPPROTO_UNSPEC)
+               {
+                       if (hints->ai_socktype == SOCK_DGRAM) proto = IPPROTO_UDP;
+                       else if (hints->ai_socktype == SOCK_STREAM) proto = IPPROTO_TCP;
+               }
+       }
+
+       if (wantv4 == 1)
+       {
+               if ((proto == IPPROTO_UNSPEC) || (proto == IPPROTO_UDP))
+               {
+                       a = new_addrinfo_v4(0, SOCK_DGRAM, IPPROTO_UDP, port, a4, 0, NULL);
+                       append_addrinfo(res, a);
+               }
+
+               if ((proto == IPPROTO_UNSPEC) || (proto == IPPROTO_TCP))
+               {
+                       a = new_addrinfo_v4(0, SOCK_STREAM, IPPROTO_TCP, port, a4, 0, NULL);
+                       append_addrinfo(res, a);
+               }
+
+               if (proto == IPPROTO_ICMP)
+               {
+                       a = new_addrinfo_v4(0, SOCK_RAW, IPPROTO_ICMP, port, a4, 0, NULL);
+                       append_addrinfo(res, a);
+               }
+       }
+
+       if (wantv6 == 1)
+       {
+               if ((proto == IPPROTO_UNSPEC) || (proto == IPPROTO_UDP))
+               {
+                       a = new_addrinfo_v6(0, SOCK_DGRAM, IPPROTO_UDP, port, a6, 0, NULL);
+                       append_addrinfo(res, a);
+               }
+
+               if ((proto == IPPROTO_UNSPEC) || (proto == IPPROTO_TCP))
+               {
+                       a = new_addrinfo_v6(0, SOCK_STREAM, IPPROTO_TCP, port, a6, 0, NULL);
+                       append_addrinfo(res, a);
+               }
+
+               if (proto == IPPROTO_ICMPV6)
+               {
+                       a = new_addrinfo_v6(0, SOCK_RAW, IPPROTO_ICMPV6, port, a6, 0, NULL);
+                       append_addrinfo(res, a);
+               }
+       }
+
+       return 0;
+}
+
 int
 gai_files(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
 {
-       int32_t i, numericserv, numerichost, family, proto, wantv4, wantv6;
+       int32_t i, status, numericserv, numerichost, family, proto, wantv4, wantv6;
        int16_t port;
        struct servent *s;
        struct hostent *h;
@@ -674,14 +795,22 @@ gai_files(const char *nodename, const char *servname, const struct addrinfo *hin
        {
                if ((family == PF_UNSPEC) || (family == PF_INET))
                {
-                       numerichost = inet_pton(AF_INET, nodename, &a4);
-                       if ((numerichost == 1) && (family == PF_UNSPEC)) family = PF_INET;
+                       status = inet_pton(AF_INET, nodename, &a4);
+                       if (status == 1)
+                       {
+                               numerichost = 1;
+                               if (family == PF_UNSPEC) family = PF_INET;
+                       }
                }
 
                if ((family == PF_UNSPEC) || (family == PF_INET6))
                {
-                       numerichost = inet_pton(AF_INET6, nodename, &a6);
-                       if ((numerichost == 1) && (family == PF_UNSPEC)) family = PF_INET6;
+                       status = inet_pton(AF_INET6, nodename, &a6);
+                       if (status == 1)
+                       {
+                               numerichost = 1;
+                               if (family == PF_UNSPEC) family = PF_INET6;
+                       }
                }
        }
 
@@ -737,6 +866,12 @@ gai_files(const char *nodename, const char *servname, const struct addrinfo *hin
                                a = new_addrinfo_v4(0, SOCK_STREAM, IPPROTO_TCP, port, a4, 0, NULL);
                                append_addrinfo(res, a);
                        }
+
+                       if (proto == IPPROTO_ICMP)
+                       {
+                               a = new_addrinfo_v4(0, SOCK_RAW, IPPROTO_ICMP, port, a4, 0, NULL);
+                               append_addrinfo(res, a);
+                       }
                }
 
                if (wantv6 == 1)
@@ -752,6 +887,12 @@ gai_files(const char *nodename, const char *servname, const struct addrinfo *hin
                                a = new_addrinfo_v6(0, SOCK_STREAM, IPPROTO_TCP, port, a6, 0, NULL);
                                append_addrinfo(res, a);
                        }
+
+                       if (proto == IPPROTO_ICMPV6)
+                       {
+                               a = new_addrinfo_v6(0, SOCK_RAW, IPPROTO_ICMPV6, port, a6, 0, NULL);
+                               append_addrinfo(res, a);
+                       }
                }
 
                return 0;
@@ -877,6 +1018,10 @@ int
 getaddrinfo(const char * __restrict nodename, const char * __restrict servname, const struct addrinfo * __restrict hints, struct addrinfo ** __restrict res)
 {
        int32_t status, nodenull, servnull;
+       int32_t numericserv, numerichost, family;
+       int16_t port;
+       struct in_addr a4, *p4;
+       struct in6_addr a6, *p6;
 
        if (res == NULL) return 0;
        *res = NULL;
@@ -887,11 +1032,60 @@ getaddrinfo(const char * __restrict nodename, const char * __restrict servname,
 
        servnull = 0;
        if ((servname == NULL) || (servname[0] == '\0')) servnull = 1;
-       
+
        if ((nodenull == 1) && (servnull == 1)) return EAI_NONAME;
+
        status = gai_checkhints(hints);
        if (status != 0) return status;
 
+       /*
+        * Trap the "trivial" cases that can be answered without a query.
+        * (nodename == numeric) && (servname == NULL)
+        * (nodename == numeric) && (servname == numeric)
+        * (nodename == NULL) && (servname == numeric)
+        */
+       p4 = NULL;
+       p6 = NULL;
+
+       memset(&a4, 0, sizeof(struct in_addr));
+       memset(&a6, 0, sizeof(struct in6_addr));
+
+       numericserv = 0;
+       port = 0;
+       if (servnull == 0) numericserv = is_a_number(servname);
+       if (numericserv == 1) port = atoi(servname);
+
+       family = PF_UNSPEC;
+       if (hints != NULL) family = hints->ai_family;
+
+       numerichost = 0;
+       if (nodenull == 0)
+       {
+               if ((family == PF_UNSPEC) || (family == PF_INET))
+               {
+                       status = inet_pton(AF_INET, nodename, &a4);
+                       if (status == 1)
+                       {
+                               p4 = &a4;
+                               numerichost = 1;
+                       }
+               }
+
+               if ((family == PF_UNSPEC) || (family == PF_INET6))
+               {
+                       status = inet_pton(AF_INET6, nodename, &a6);
+                       if (status == 1)
+                       {
+                               p6 = &a6;
+                               numerichost = 1;
+                       }
+               }
+       }
+
+       if ((nodenull == 1) && (numericserv == 1)) return gai_trivial(NULL, NULL, port, hints, res);
+       if ((numerichost == 1) && (numericserv == 1)) return gai_trivial(p4, p6, port, hints, res);
+       if ((numerichost == 1) && (servnull == 1)) return gai_trivial(p4, p6, 0, hints, res);
+
        if (nodenull == 1) status = gai_lookupd(NULL, servname, hints, res);
        else if (servnull == 1) status = gai_lookupd(nodename, NULL, hints, res);
        else status = gai_lookupd(nodename, servname, hints, res);
@@ -1092,7 +1286,7 @@ gni_lookupd_process_dictionary(XDR *inxdr, char **host, char **serv)
                key = NULL;
                vals = NULL;
                nvals = 0;
-               
+
                status = _lu_xdr_attribute(inxdr, &key, &vals, (uint32_t *)&nvals);
                if (status < 0) return EAI_SYSTEM;
 
@@ -1192,7 +1386,7 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse
                        ifnum = s6->sin6_addr.__u6_addr.__u6_addr16[1];
                        if (ifnum == 0) ifnum = s6->sin6_scope_id;
                        else if ((s6->sin6_scope_id != 0) && (ifnum != s6->sin6_scope_id)) return EAI_FAIL;
-                       
+
                        s6->sin6_addr.__u6_addr.__u6_addr16[1] = 0;
                        s6->sin6_scope_id = ifnum;
                        if ((ifnum != 0) && (flags & NI_NUMERICHOST)) flags |= NI_WITHSCOPEID;
@@ -1329,7 +1523,7 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse
        *len = xdr_getpos(&outxdr);
 
        xdr_destroy(&outxdr);
-       
+
        return 0;
 }
 
@@ -1391,7 +1585,7 @@ getnameinfo(const struct sockaddr * __restrict sa, socklen_t salen, char * __res
                        return i;
                }
        }
-               
+
        wanth = 0;
        if ((host != NULL) && (hostlen != 0)) wanth = 1;
 
index 7d22d9196d01a361aa31d48a4d6d615e8f095d47..cb62a7c636886b32f8e2fdeb10f1b0a03ecc2497 100644 (file)
@@ -305,7 +305,7 @@ lu_alias_getent(void)
                tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info));
                _lu_data_set_key(_lu_data_key_alias, tdata);
        }
-\r
+
        if (tdata->lu_vm == NULL)
        {
                if (proc < 0)
index 9594b7421829647d04b173c02f8ef7896886a9d1..9fe1b8472ff638df2bd2fb8eebf4203f1abbecc8 100644 (file)
@@ -266,7 +266,7 @@ lu_bootparams_getent(void)
                tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info));
                _lu_data_set_key(_lu_data_key_bootparams, tdata);
        }
-\r
+
        if (tdata->lu_vm == NULL)
        {
                if (proc < 0)
index be1d53220295b6cbdb9a2eaf246034d57e66ac6c..725255b4e7739c5866985caf07ba173c6ac446ad 100644 (file)
@@ -297,7 +297,7 @@ lu_endfsent(void)
        struct lu_thread_info *tdata;
 
        tdata = _lu_data_create_key(_lu_data_key_fstab, free_lu_thread_info_fstab);
-       _lu_data_free_vm_xdr(tdata);\r
+       _lu_data_free_vm_xdr(tdata);
 }
 
 static int
@@ -320,7 +320,7 @@ lu_getfsent()
                tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info));
                _lu_data_set_key(_lu_data_key_fstab, tdata);
        }
-\r
+
        if (tdata->lu_vm == NULL)
        {
                if (proc < 0)
index db1ba65a2f747e48ced9509531430acb71b65e11..8f9a5519d1198127b51d86b20abd3271049e0f8d 100644 (file)
@@ -357,7 +357,7 @@ lu_endnetent()
        struct lu_thread_info *tdata;
 
        tdata = _lu_data_create_key(_lu_data_key_network, free_lu_thread_info_network);
-       _lu_data_free_vm_xdr(tdata);\r
+       _lu_data_free_vm_xdr(tdata);
 }
 
 static void
@@ -379,7 +379,7 @@ lu_getnetent()
                tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info));
                _lu_data_set_key(_lu_data_key_network, tdata);
        }
-\r
+
        if (tdata->lu_vm == NULL)
        {
                if (proc < 0)
index 86fd0b7d2a2f94943af8e076850a31a247847902..e455b4cc1ded4607f15da93f2c1b79ad901966d7 100644 (file)
@@ -334,7 +334,7 @@ lu_prdb_get()
                tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info));
                _lu_data_set_key(_lu_data_key_printer, tdata);
        }
-\r
+
        if (tdata->lu_vm == NULL)
        {
                if (proc < 0)
index a6a04519b77d6b1cda0b1f0da7933eba80f31893..e91932d9dce1ac2a40ed03812c4737ac8c91362f 100644 (file)
@@ -363,7 +363,7 @@ lu_getprotoent()
                tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info));
                _lu_data_set_key(_lu_data_key_protocol, tdata);
        }
-\r
+
        if (tdata->lu_vm == NULL)
        {
                if (proc < 0)
index 368908768b24ae557def536ed1787c5ec525ecde..53812017bf847b9d4951ef1cf33b75914c398d7a 100644 (file)
@@ -361,7 +361,7 @@ lu_getrpcent()
                tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info));
                _lu_data_set_key(_lu_data_key_rpc, tdata);
        }
-\r
+
        if (tdata->lu_vm == NULL)
        {
                if (proc < 0)