This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Named AF_UNIX socket not working in cygwin1.dll of git HEAD.


Named AF_UNIX socket does not work in cygwin1.dll of git HEAD.

A simple test case is attched.

Expected result:
10: 1234567890

Result in cygwin1.dll of git HEAD:
bind: Bad address
unlink: Device or resource busy


It seems that this occures regarding the following commit.

commit 859d215b7e006e5fc60f686ec976e997e35d169b
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Feb 21 21:40:01 2018 +0100

    Cygwin: split out fhandler_socket into inet and local classes

    First cut, still incomplete

    * fhandler_socket is now base class for other socket classes
    * fhandler_socket_inet handles AF_INET and AF_INET6 sockets
    * fhandler_socket_local handles AF_LOCAL/AF_UNIX sockets
    * finally get rid of fdsock by using set_socket_handle in accept4
    * align file-related calls (fstat,  fstatvfs, fchown, fchmod, facl)
      to Linux.

    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>


-- 
Takashi Yano <takashi.yano@nifty.ne.jp>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <signal.h>

#define SOCKNAME "sock_unix"

int main()
{
	int fd;
	struct sockaddr_un sunx;
	pid_t pid;
	ssize_t len;
	char buf[BUFSIZ];
	
	memset(&sunx, 0, sizeof(sunx));
	sunx.sun_family = AF_UNIX;
	strncpy (sunx.sun_path, SOCKNAME, sizeof(sunx.sun_path) -1 );

	pid = fork();
	if (pid) {
		int fd1;
		fd = socket(AF_UNIX, SOCK_STREAM, 0);
		if (fd < 0) {
			perror("socket");
			goto end_server;
		}
		if (bind(fd, (struct sockaddr *)&sunx, sizeof(sunx)) < 0) {
			perror("bind");
			goto end_server;
		}
		if (listen(fd, 1) < 0) {
			perror("listen");
			goto end_server;
		}
		fd1 = accept(fd, 0, 0);
		if (fd1 < 0) {
			perror("accept");
			goto end_server;
		}
		while ((len = read(fd1, buf, sizeof(buf))) > 0) {
			buf[len] = '\0';
			printf("%d: %s\n", len, buf);
		}
		close(fd1);
end_server:
		close(fd);
		kill(pid, SIGTERM);
		wait(NULL);
		if (unlink(SOCKNAME) < 0) {
			perror("unlink");
		}
	} else {
		usleep(100000);
		fd = socket(AF_UNIX, SOCK_STREAM, 0);
		if (fd < 0) {
			perror("socket");
			goto end_client;
		}
		if (connect(fd, (struct sockaddr *)&sunx, sizeof(sunx)) < 0) {
			perror("connect");
			goto end_client;
		}
		write(fd, "1234567890", 10);
end_client:
		close(fd);
	}
	
	return 0;
}

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]