22 #ifndef LELY_IO2_INTERN_LINUX_IOCTL_H_
23 #define LELY_IO2_INTERN_LINUX_IOCTL_H_
33 #include <sys/socket.h>
36 #include <sys/ioctl.h>
38 #ifndef LELY_IO_IFREQ_DOMAIN
39 #define LELY_IO_IFREQ_DOMAIN AF_UNIX
42 #ifndef LELY_IO_IFREQ_TYPE
43 #define LELY_IO_IFREQ_TYPE SOCK_DGRAM
46 #ifndef LELY_IO_IFREQ_PROTOCOL
47 #define LELY_IO_IFREQ_PROTOCOL 0
55 static int ifr_open(
struct ifr_handle *ifh,
const char *name);
58 static int ifr_get_flags(
const char *name);
59 static int ifr_set_flags(
const char *name,
int *flags,
int mask);
62 ifr_open(
struct ifr_handle *ifh,
const char *name)
67 ifh->fd = socket(LELY_IO_IFREQ_DOMAIN,
68 LELY_IO_IFREQ_TYPE | SOCK_CLOEXEC,
69 LELY_IO_IFREQ_PROTOCOL);
73 memset(&ifh->ifr, 0,
sizeof(ifh->ifr));
74 if (!memccpy(ifh->ifr.ifr_name, name,
'\0', IFNAMSIZ))
75 ifh->ifr.ifr_name[IFNAMSIZ - 1] =
'\0';
91 ifr_get_flags(
const char *name)
94 if (ifr_open(&ifh, name) == -1)
97 int result = ioctl(ifh.fd, SIOCGIFFLAGS, &ifh.ifr) == -1
105 ifr_set_flags(
const char *name,
int *flags,
int mask)
110 if (ifr_open(&ifh, name) == -1)
113 int result = ioctl(ifh.fd, SIOCGIFFLAGS, &ifh.ifr);
115 if ((ifh.ifr.ifr_flags ^ *flags) & mask) {
116 ifh.ifr.ifr_flags &= ~mask;
117 ifh.ifr.ifr_flags |= *flags & mask;
118 result = ioctl(ifh.fd, SIOCSIFFLAGS, &ifh.ifr);
121 *flags = ifh.ifr.ifr_flags;
This is the internal header file of the Windows-specific I/O declarations.
This header file is part of the C11 and POSIX compatibility library; it includes <string....
This header file is part of the C11 and POSIX compatibility library; it includes <unistd....