C and Python - communicating with sockets
Looking at an example I found, it seems that the length you pass bind
should not count the terminating or padding nulls in the sockaddr_un
.
Try:
size_t addrlen;const char* sockname = "/tmp/demo_socket";/* ... */address.sun_family = AF_UNIX;snprintf(address.sun_path, UNIX_PATH_MAX, sockname);addrlen = sizeof(address.sun_family) + strlen(sockname);if (bind(socket_fd, (struct sockaddr *) &address, addrlen) != 0) { printf("bind() failed\n"); return 1;}
P.S. Because of this, you don't need the memset
call.