summaryrefslogtreecommitdiff
path: root/misc/ioctltst.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1993-07-22 22:38:00 +0000
committerRoland McGrath <roland@gnu.org>1993-07-22 22:38:00 +0000
commit4e801773c9b442a0157086ced11ea377ba7062e1 (patch)
tree03e65b51b822b1d4b08b388b613e80e096e63bf4 /misc/ioctltst.c
parentfe33b9f088a89136869ac1c1e4996ad5135e25cd (diff)
Initial revision
Diffstat (limited to 'misc/ioctltst.c')
-rw-r--r--misc/ioctltst.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/misc/ioctltst.c b/misc/ioctltst.c
new file mode 100644
index 0000000000..aebaf4091e
--- /dev/null
+++ b/misc/ioctltst.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <netinet/in.h>
+
+/*
+ * open a socket, get the process group information of the socket, and use the
+ * socket to get the network interface configuration list
+ */
+main()
+{
+ int sock;
+ int ioctl_result;
+
+ /* get a socket */
+ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (sock < 0)
+ {
+ perror("Cannot create socket");
+ exit(1);
+ }
+
+ /* use ioctl() to get the process group information */
+ {
+ int get_process_group;
+
+ ioctl_result = ioctl(sock, SIOCGPGRP, (char *) &get_process_group);
+
+ if (ioctl_result < 0)
+ {
+ int my_errno = errno;
+
+ fprintf(stderr, "errno %d ", my_errno);
+ perror("ioctl(get process group)");
+ }
+ }
+
+ /* use ioctl() to get the interface configuration list */
+ {
+ struct ifconf ifc;
+
+ ioctl_result = ioctl(sock, SIOCGIFCONF, (char *) &ifc);
+
+ if (ioctl_result < 0)
+ {
+ int my_errno = errno;
+
+ fprintf(stderr, "errno %d ", my_errno);
+ perror("ioctl(get interface configuration list)");
+ }
+ }
+}