#define ASSERT_LOCKED(lock) assert(pthread_mutex_trylock(&lock))
+/*
+ * Get an aligned pointer to a value. This is meant
+ * as a helper to pass an aligned pointer to a member in a packed structure
+ * to a function.
+ */
+#define ALIGNED_CONST_PTR(value) (((const typeof(value) []) { value }))
+
/*
* lttng_strncpy returns 0 on success, or nonzero on failure.
* It checks that the @src string fits into @dst_len before performing
int lttcomm_bind_inet_sock(struct lttcomm_sock *sock)
{
return bind(sock->fd,
- (const struct sockaddr *) &sock->sockaddr.addr.sin,
+ (const struct sockaddr *) ALIGNED_CONST_PTR(
+ sock->sockaddr.addr.sin),
sizeof(sock->sockaddr.addr.sin));
}
static
int connect_no_timeout(struct lttcomm_sock *sock)
{
- return connect(sock->fd, (struct sockaddr *) &sock->sockaddr.addr.sin,
+ return connect(sock->fd,
+ (const struct sockaddr *) ALIGNED_CONST_PTR(
+ sock->sockaddr.addr.sin),
sizeof(sock->sockaddr.addr.sin));
}
}
connect_ret = connect(sock->fd,
- (struct sockaddr *) &sock->sockaddr.addr.sin,
- sizeof(sock->sockaddr.addr.sin));
- if (connect_ret == -1 && errno != EAGAIN
- && errno != EWOULDBLOCK
- && errno != EINPROGRESS) {
+ (const struct sockaddr *) ALIGNED_CONST_PTR(
+ sock->sockaddr.addr.sin),
+ sizeof(sock->sockaddr.addr.sin));
+ if (connect_ret == -1 && errno != EAGAIN && errno != EWOULDBLOCK &&
+ errno != EINPROGRESS) {
goto error;
} else if (!connect_ret) {
/* Connect succeeded */
socklen_t len;
struct lttcomm_sock *new_sock;
unsigned long timeout;
+ struct sockaddr_in new_addr = {};
if (sock->proto == LTTCOMM_SOCK_UDP) {
/*
goto error;
}
- len = sizeof(new_sock->sockaddr.addr.sin);
+ len = sizeof(new_addr);
/* Blocking call */
- new_fd = accept(sock->fd, (struct sockaddr *) &new_sock->sockaddr.addr.sin,
- &len);
+ new_fd = accept(sock->fd, (struct sockaddr *) &new_addr, &len);
if (new_fd < 0) {
PERROR("accept inet");
goto error;
}
+ new_sock->sockaddr.addr.sin = new_addr;
timeout = lttcomm_get_network_timeout();
if (timeout) {
int ret;
struct iovec iov[1];
ssize_t ret = -1;
size_t len_last;
+ struct sockaddr_in addr = sock->sockaddr.addr.sin;
memset(&msg, 0, sizeof(msg));
msg.msg_iov = iov;
msg.msg_iovlen = 1;
- msg.msg_name = (struct sockaddr *) &sock->sockaddr.addr.sin;
+ msg.msg_name = (struct sockaddr *) &addr;
msg.msg_namelen = sizeof(sock->sockaddr.addr.sin);
do {
switch (sock->proto) {
case LTTCOMM_SOCK_UDP:
- msg.msg_name = (struct sockaddr *) &sock->sockaddr.addr.sin;
+ {
+ struct sockaddr_in addr = sock->sockaddr.addr.sin;
+
+ msg.msg_name = (struct sockaddr *) &addr;
msg.msg_namelen = sizeof(sock->sockaddr.addr.sin);
break;
+ }
default:
break;
}
int lttcomm_bind_inet6_sock(struct lttcomm_sock *sock)
{
return bind(sock->fd,
- (const struct sockaddr *) &sock->sockaddr.addr.sin6,
+ (const struct sockaddr *) ALIGNED_CONST_PTR(
+ sock->sockaddr.addr.sin6),
sizeof(sock->sockaddr.addr.sin6));
}
static
int connect_no_timeout(struct lttcomm_sock *sock)
{
- return connect(sock->fd, (struct sockaddr *) &sock->sockaddr.addr.sin6,
+ return connect(sock->fd,
+ (const struct sockaddr *) ALIGNED_CONST_PTR(
+ sock->sockaddr.addr.sin6),
sizeof(sock->sockaddr.addr.sin6));
}
}
connect_ret = connect(sock->fd,
- (struct sockaddr *) &sock->sockaddr.addr.sin6,
- sizeof(sock->sockaddr.addr.sin6));
- if (connect_ret == -1 && errno != EAGAIN
- && errno != EWOULDBLOCK
- && errno != EINPROGRESS) {
+ (const struct sockaddr *) ALIGNED_CONST_PTR(
+ sock->sockaddr.addr.sin6),
+ sizeof(sock->sockaddr.addr.sin6));
+ if (connect_ret == -1 && errno != EAGAIN && errno != EWOULDBLOCK &&
+ errno != EINPROGRESS) {
goto error;
} else if (!connect_ret) {
/* Connect succeeded */
int new_fd;
socklen_t len;
struct lttcomm_sock *new_sock;
+ struct sockaddr_in6 new_addr = {};
if (sock->proto == LTTCOMM_SOCK_UDP) {
/*
goto error;
}
- len = sizeof(new_sock->sockaddr.addr.sin6);
+ len = sizeof(new_addr);
/* Blocking call */
- new_fd = accept(sock->fd,
- (struct sockaddr *) &new_sock->sockaddr.addr.sin6, &len);
+ new_fd = accept(sock->fd, (struct sockaddr *) &new_addr, &len);
if (new_fd < 0) {
PERROR("accept inet6");
goto error;
}
-
+ new_sock->sockaddr.addr.sin6 = new_addr;
new_sock->fd = new_fd;
new_sock->ops = &inet6_ops;
struct iovec iov[1];
ssize_t ret = -1;
size_t len_last;
+ struct sockaddr_in6 addr = sock->sockaddr.addr.sin6;
memset(&msg, 0, sizeof(msg));
msg.msg_iov = iov;
msg.msg_iovlen = 1;
- msg.msg_name = (struct sockaddr *) &sock->sockaddr.addr.sin6;
+ msg.msg_name = (struct sockaddr *) &addr;
msg.msg_namelen = sizeof(sock->sockaddr.addr.sin6);
do {
switch (sock->proto) {
case LTTCOMM_SOCK_UDP:
- msg.msg_name = (struct sockaddr *) &sock->sockaddr.addr.sin6;
+ {
+ struct sockaddr_in6 addr = sock->sockaddr.addr.sin6;
+
+ msg.msg_name = (struct sockaddr *) &addr;
msg.msg_namelen = sizeof(sock->sockaddr.addr.sin6);
break;
+ }
default:
break;
}