]> granicus.if.org Git - strace/commitdiff
tests/net-sockaddr: use ifindex_lo and IFINDEX_LO_STR
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 14 Aug 2017 18:53:17 +0000 (18:53 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 15 Aug 2017 20:08:39 +0000 (20:08 +0000)
* tests/net-sockaddr.c (if_nametoindex): Remove declaration.
(check_in6_linklocal, check_ll): Remove HAVE_IF_INDEXTONAME checks,
Use ifindex_lo instead of if_nametoindex, use IFINDEX_LO_STR instead
of hardcoded string.

tests/net-sockaddr.c

index 1d9bac3956e2b5abe3b2febda2be693f1e0ad66a..fe933d49a76c8e647c53772e2536780363503a64 100644 (file)
 # include <bluetooth/sco.h>
 #endif
 
-#ifdef HAVE_IF_INDEXTONAME
-/* <linux/if.h> used to conflict with <net/if.h> */
-extern unsigned int if_nametoindex(const char *);
-#endif
-
 static void
 check_un(void)
 {
@@ -186,19 +181,17 @@ check_in6_linklocal(struct sockaddr_in6 *const in6, const char *const h_addr)
               ntohs(in6->sin6_port), h_addr,
               ntohl(in6->sin6_flowinfo), in6->sin6_scope_id, len, ret);
 
-#ifdef HAVE_IF_INDEXTONAME
-       in6->sin6_scope_id = if_nametoindex("lo");
+       in6->sin6_scope_id = ifindex_lo();
        if (in6->sin6_scope_id) {
                ret = connect(-1, (void *) in6, len);
                printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
                       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
                       ", sin6_flowinfo=htonl(%u)"
-                      ", sin6_scope_id=if_nametoindex(\"lo\")}, %u)"
+                      ", sin6_scope_id=%s}, %u)"
                       " = %d EBADF (%m)\n",
-                      ntohs(in6->sin6_port), h_addr,
-                      ntohl(in6->sin6_flowinfo), len, ret);
+                      ntohs(in6->sin6_port), h_addr, ntohl(in6->sin6_flowinfo),
+                      IFINDEX_LO_STR, len, ret);
        }
-#endif
 }
 
 static void
@@ -371,19 +364,16 @@ check_ll(void)
               ", sll_pkttype=PACKET_HOST, sll_halen=0}, %u)"
               " = %d EBADF (%m)\n", c_ll.sll_ifindex, len, ret);
 
-#ifdef HAVE_IF_INDEXTONAME
-       const int id = if_nametoindex("lo");
-       if (id) {
-               ((struct sockaddr_ll *) ll)->sll_ifindex = id;
+       ((struct sockaddr_ll *) ll)->sll_ifindex = ifindex_lo();
+       if (((struct sockaddr_ll *) ll)->sll_ifindex) {
                ret = connect(-1, ll, len);
                printf("connect(-1, {sa_family=AF_PACKET"
                       ", sll_protocol=htons(ETH_P_ALL)"
-                      ", sll_ifindex=if_nametoindex(\"lo\")"
+                      ", sll_ifindex=%s"
                       ", sll_hatype=ARPHRD_ETHER"
                       ", sll_pkttype=PACKET_HOST, sll_halen=0}, %u)"
-                      " = %d EBADF (%m)\n", len, ret);
+                      " = %d EBADF (%m)\n", IFINDEX_LO_STR, len, ret);
        }
-#endif
 }
 
 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H