/*
- * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
*
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _LGPL_SOURCE
-#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#include <errno.h>
#include <fcntl.h>
#include <common/compat/time.h>
#include <poll.h>
#include <common/common.h>
#include <common/time.h>
+#include <common/compat/errno.h>
#include "inet6.h"
/*
* Creates an PF_INET socket.
*/
-LTTNG_HIDDEN
int lttcomm_create_inet6_sock(struct lttcomm_sock *sock, int type, int proto)
{
int val = 1, ret;
/*
* Bind socket and return.
*/
-LTTNG_HIDDEN
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 */
/*
* Connect PF_INET socket.
*/
-LTTNG_HIDDEN
int lttcomm_connect_inet6_sock(struct lttcomm_sock *sock)
{
int ret, closeret;
* Do an accept(2) on the sock and return the new lttcomm socket. The socket
* MUST be bind(2) before.
*/
-LTTNG_HIDDEN
struct lttcomm_sock *lttcomm_accept_inet6_sock(struct lttcomm_sock *sock)
{
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;
/*
* Make the socket listen using LTTNG_SESSIOND_COMM_MAX_LISTEN.
*/
-LTTNG_HIDDEN
int lttcomm_listen_inet6_sock(struct lttcomm_sock *sock, int backlog)
{
int ret;
*
* Return the size of received data.
*/
-LTTNG_HIDDEN
ssize_t lttcomm_recvmsg_inet6_sock(struct lttcomm_sock *sock, void *buf,
size_t len, int flags)
{
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 {
}
iov[0].iov_base += ret;
iov[0].iov_len -= ret;
- assert(ret <= len_last);
+ LTTNG_ASSERT(ret <= len_last);
}
} while ((ret > 0 && ret < len_last) || (ret < 0 && errno == EINTR));
if (ret < 0) {
*
* Return the size of sent data.
*/
-LTTNG_HIDDEN
ssize_t lttcomm_sendmsg_inet6_sock(struct lttcomm_sock *sock, const void *buf,
size_t len, int flags)
{
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;
}
/*
* Shutdown cleanly and close.
*/
-LTTNG_HIDDEN
int lttcomm_close_inet6_sock(struct lttcomm_sock *sock)
{
int ret;