about summary refs log tree commit diff stats
path: root/src/io/bind_unix.c
blob: 02e86eed0f76f8a0e29a6697c407d20583e1de23 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stddef.h>
#include <sys/socket.h>
#include <sys/un.h>

int bind_unix_from_c(int socket, const char *path, int pathlen)
{
	struct sockaddr_un sa = {
		.sun_family = AF_UNIX
	};
	int len = offsetof(struct sockaddr_un, sun_path) + pathlen + 1;

	memcpy(sa.sun_path, path, pathlen + 1);
	return bind(socket, (struct sockaddr *)&sa, len);
}