Update.
[glibc.git] / misc / ioctltst.c
blobbf3286b650d31e9e415b7ece0eff5a1a085f5517
1 #include <stdio.h>
2 #include <errno.h>
3 #include <sys/types.h>
4 #include <sys/socket.h>
5 #include <sys/ioctl.h>
6 #include <net/if.h>
7 #include <netinet/in.h>
9 /*
10 * open a socket, get the process group information of the socket, and use the
11 * socket to get the network interface configuration list
13 main(int argc, char *argv[])
15 int sock;
16 int ioctl_result;
18 /* get a socket */
19 sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
20 if (sock < 0)
22 perror("Cannot create socket");
23 exit(1);
26 /* use ioctl() to get the process group information */
28 int get_process_group;
30 ioctl_result = ioctl(sock, SIOCGPGRP, (char *) &get_process_group);
32 if (ioctl_result < 0)
34 int my_errno = errno;
36 fprintf(stderr, "errno %d ", my_errno);
37 perror("ioctl(get process group)");
41 /* use ioctl() to get the interface configuration list */
43 static struct ifconf ifc; /* init to 0 */
45 ioctl_result = ioctl(sock, SIOCGIFCONF, (char *) &ifc);
47 if (ioctl_result < 0)
49 int my_errno = errno;
51 fprintf(stderr, "errno %d ", my_errno);
52 perror("ioctl(get interface configuration list)");