#include <net/if.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <stddef.h>
+#include <sys/ioctl.h>
#include "macro.h"
#include "util.h"
#include "socket-util.h"
#include "missing.h"
#include "label.h"
-#include <sys/ioctl.h>
int socket_address_parse(SocketAddress *a, const char *s) {
int r;
a->sockaddr.un.sun_family = AF_UNIX;
memcpy(a->sockaddr.un.sun_path, s, l);
- a->size = sizeof(sa_family_t) + l + 1;
+ a->size = offsetof(struct sockaddr_un, sun_path) + l + 1;
} else if (*s == '@') {
/* Abstract AF_UNIX socket */
a->sockaddr.un.sun_family = AF_UNIX;
memcpy(a->sockaddr.un.sun_path+1, s+1, l);
- a->size = sizeof(sa_family_t) + 1 + l;
+ a->size = offsetof(struct sockaddr_un, sun_path) + 1 + l;
} else {
return 0;
case AF_UNIX:
- if (a->size < sizeof(sa_family_t))
+ if (a->size < offsetof(struct sockaddr_un, sun_path))
return -EINVAL;
- if (a->size > sizeof(sa_family_t)) {
+ if (a->size > offsetof(struct sockaddr_un, sun_path)) {
if (a->sockaddr.un.sun_path[0] != 0) {
char *e;
if (!(e = memchr(a->sockaddr.un.sun_path, 0, sizeof(a->sockaddr.un.sun_path))))
return -EINVAL;
- if (a->size != sizeof(sa_family_t) + (e - a->sockaddr.un.sun_path) + 1)
+ if (a->size != offsetof(struct sockaddr_un, sun_path) + (e - a->sockaddr.un.sun_path) + 1)
return -EINVAL;
}
}
case AF_UNIX: {
char *ret;
- if (a->size <= sizeof(sa_family_t)) {
+ if (a->size <= offsetof(struct sockaddr_un, sun_path)) {
if (!(ret = strdup("<unamed>")))
return -ENOMEM;
}
bool socket_ipv6_is_supported(void) {
- return access("/sys/module/ipv6", F_OK) == 0;
+ char *l = 0;
+ bool enabled;
+
+ if (access("/sys/module/ipv6", F_OK) != 0)
+ return 0;
+
+ /* If we can't check "disable" parameter, assume enabled */
+ if (read_one_line_file("/sys/module/ipv6/parameters/disable", &l) < 0)
+ return 1;
+
+ /* If module was loaded with disable=1 no IPv6 available */
+ enabled = l[0] == '0';
+ free(l);
+
+ return enabled;
}
static const char* const socket_address_bind_ipv6_only_table[_SOCKET_ADDRESS_BIND_IPV6_ONLY_MAX] = {