/*
 * Unix domain socket bind: trigger net/bind path
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
	char path[108];
	const char *dir = (argc > 1) ? argv[1] : ".";
	snprintf(path, sizeof(path), "%s/t064.sock", dir);

	int fd = socket(AF_UNIX, SOCK_STREAM, 0);
	if (fd < 0)
		return 1;

	struct sockaddr_un addr;
	memset(&addr, 0, sizeof(addr));
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
	unlink(path);
	bind(fd, (struct sockaddr *)&addr, sizeof(addr));
	close(fd);
	unlink(path);
	return 0;
}
