1 /* Tests for ioctl wrappers.
2 More complicated ones than just trivial ones in scalar_ioctl. */
9 #include <sys/socket.h>
10 #include <sys/sockio.h>
13 __attribute__((noinline
))
14 static int test_SIOCGIFCONF(void)
16 int fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
21 if (ioctl(fd
, SIOCGIFNUM
, &n_ifs
) < 0)
22 perror("ioctl(SIOCGIFNUM)");
25 ifc
.ifc_len
= (n_ifs
+ 1) * sizeof(struct ifreq
);
26 ifc
.ifc_buf
= malloc((n_ifs
+ 1) * sizeof(struct ifreq
));
27 if (ifc
.ifc_buf
== NULL
)
30 if (ioctl(fd
, SIOCGIFCONF
, &ifc
) < 0)
31 perror("ioctl(SIOCGIFCONF)");
33 /* Check definedness of ifc attributes ... */
35 if (ifc
.ifc_len
!= 0) x
= -1; else x
= -2;
36 if (ifc
.ifc_req
!= NULL
) x
= -3; else x
= -4;
37 if (strcmp(ifc
.ifc_req
[0].ifr_name
, "") != 0) x
= -5; else x
= -6;
38 /* ... and now one which is not defined. */
39 if (strcmp(ifc
.ifc_req
[n_ifs
].ifr_name
, "") != 0) x
= -7; else x
= -8;
46 __attribute__((noinline
))
47 static int test_SIOCGLIFCONF(void)
49 int fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
54 lifn
.lifn_family
= AF_INET
;
56 if (ioctl(fd
, SIOCGLIFNUM
, &lifn
) < 0)
57 perror("ioctl(SIOCGLIFNUM)");
60 lifc
.lifc_family
= AF_INET
;
62 lifc
.lifc_len
= (lifn
.lifn_count
+ 1) * sizeof(struct lifreq
);
63 lifc
.lifc_buf
= malloc((lifn
.lifn_count
+ 1) * sizeof(struct lifreq
));
64 if (lifc
.lifc_buf
== NULL
)
67 if (ioctl(fd
, SIOCGLIFCONF
, &lifc
) < 0)
68 perror("ioctl(SIOCGLIFCONF)");
70 /* Check definedness of lifc attributes ... */
72 if (lifc
.lifc_len
!= 0) x
= -1; else x
= -2;
73 if (lifc
.lifc_req
!= NULL
) x
= -3; else x
= -4;
74 if (strcmp(lifc
.lifc_req
[0].lifr_name
, "") != 0) x
= -5; else x
= -6;
75 /* ... and now one which is not defined. */
76 if (strcmp(lifc
.lifc_req
[lifn
.lifn_count
].lifr_name
, "") != 0)