#include <getopt.h>
#include <termios.h>
#include <limits.h>
+#include <stddef.h>
#include "log.h"
#include "macro.h"
sa.un.sun_family = AF_UNIX;
snprintf(sa.un.sun_path+1, sizeof(sa.un.sun_path)-1, "/org/freedesktop/systemd1/ask-password/%llu", random_ull());
- if (bind(fd, &sa.sa, sizeof(sa_family_t) + 1 + strlen(sa.un.sun_path+1)) < 0) {
+ if (bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
r = -errno;
log_error("bind() failed: %m");
goto fail;
sa.sa.sa_family = AF_UNIX;
strncpy(sa.un.sun_path+1, LOGGER_SOCKET, sizeof(sa.un.sun_path)-1);
- if (connect(fd, &sa.sa, sizeof(sa_family_t) + 1 + sizeof(LOGGER_SOCKET) - 1) < 0) {
+ if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + sizeof(LOGGER_SOCKET) - 1) < 0) {
close_nointr_nofail(fd);
return -errno;
}
else
strncpy(sa.un.sun_path+1, NOTIFY_SOCKET, sizeof(sa.un.sun_path)-1);
- if (bind(m->notify_watch.fd, &sa.sa, sizeof(sa_family_t) + 1 + strlen(sa.un.sun_path+1)) < 0) {
+ if (bind(m->notify_watch.fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
log_error("bind() failed: %m");
return -errno;
}
#include <sys/stat.h>
#include <sys/signalfd.h>
#include <getopt.h>
+#include <stddef.h>
#include "log.h"
#include "macro.h"
sa.un.sun_family = AF_UNIX;
strncpy(sa.un.sun_path+1, socket_name, sizeof(sa.un.sun_path)-1);
- if (sendto(fd, packet, size, MSG_NOSIGNAL, &sa.sa, sizeof(sa_family_t) + 1 + strlen(socket_name)) < 0) {
+ if (sendto(fd, packet, size, MSG_NOSIGNAL, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(socket_name)) < 0) {
log_error("Failed to send: %m");
return -1;
}
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
+#include <stddef.h>
#include "sd-daemon.h"
if (getsockname(fd, &sockaddr.sa, &l) < 0)
return -errno;
- if (l < sizeof(sa_family_t))
+ if (l < offsetof(struct sockaddr_un, sun_path))
return -EINVAL;
return sockaddr.sa.sa_family == family;
if (getsockname(fd, &sockaddr.sa, &l) < 0)
return -errno;
- if (l < sizeof(sa_family_t))
+ if (l < offsetof(struct sockaddr_un, sun_path))
return -EINVAL;
if (sockaddr.sa.sa_family != AF_INET &&
if (getsockname(fd, &sockaddr.sa, &l) < 0)
return -errno;
- if (l < sizeof(sa_family_t))
+ if (l < offsetof(struct sockaddr_un, sun_path))
return -EINVAL;
if (sockaddr.sa.sa_family != AF_UNIX)
if (length <= 0)
/* Unnamed socket */
- return l == sizeof(sa_family_t);
+ return l == offsetof(struct sockaddr_un, sun_path);
if (path[0])
/* Normal path socket */
return
- (l >= sizeof(sa_family_t) + length + 1) &&
+ (l >= offsetof(struct sockaddr_un, sun_path) + length + 1) &&
memcmp(path, sockaddr.un.sun_path, length+1) == 0;
else
/* Abstract namespace socket */
return
- (l == sizeof(sa_family_t) + length) &&
+ (l == offsetof(struct sockaddr_un, sun_path) + length) &&
memcmp(path, sockaddr.un.sun_path, length) == 0;
}
memset(&msghdr, 0, sizeof(msghdr));
msghdr.msg_name = &sockaddr;
- msghdr.msg_namelen = sizeof(sa_family_t) + strlen(e);
+ msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e);
if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
msghdr.msg_namelen = sizeof(struct sockaddr_un);
#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;
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <stddef.h>
#include <dbus/dbus.h>
zero(msghdr);
msghdr.msg_name = &sockaddr;
- msghdr.msg_namelen = sizeof(sa_family_t) + 1 + sizeof("/org/freedesktop/systemd1/shutdownd") - 1;
+ msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + 1 + sizeof("/org/freedesktop/systemd1/shutdownd") - 1;
msghdr.msg_iov = &iovec;
msghdr.msg_iovlen = 1;