Created
March 5, 2014 14:06
-
-
Save kotaroito/9367801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <string.h> | |
| #include <unistd.h> | |
| #include <stddef.h> | |
| #include <sys/socket.h> | |
| #include <sys/un.h> | |
| #include "error.h" | |
| #define UNIX_DOMAIN_SOCK_NAME "foo.socket" | |
| int main(void) | |
| { | |
| int fd, size; | |
| struct sockaddr_un un; | |
| un.sun_family = AF_UNIX; | |
| strcpy(un.sun_path, UNIX_DOMAIN_SOCK_NAME); | |
| if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) | |
| err_sys("socket"); | |
| size = offsetof(struct sockaddr_un, sun_path) + strlen(un.sun_path); | |
| if (bind(fd, (struct sockaddr*)&un, size) < 0) | |
| err_sys("bind"); | |
| unlink(UNIX_DOMAIN_SOCK_NAME); | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment