#include #include #include #include #include #include #include #include int main() { const char file[] = "/tmp/.afunix"; umask(0077); int status = unlink(file); if (status < 0 && errno != ENOENT) { printf("unlink() failed with %d\n", errno); return 1; } int fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { printf("socket() failed with %d\n", errno); return 1; } struct sockaddr_un address; memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; strcpy(address.sun_path, file); int len = sizeof(address); status = bind(fd, (sockaddr*) &address, len); if (status < 0) { printf("bind() failed with %d\n", errno); return 1; } status = chmod(file, 0777); if (status < 0) { printf("chmod() failed with %d\n", errno); return 1; } return 0; }