Created
February 28, 2018 03:42
-
-
Save jld/00400eaeee4308642eae20107f91d4b8 to your computer and use it in GitHub Desktop.
This file contains 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 <sys/socket.h> | |
#include <sys/types.h> | |
#include <sys/un.h> | |
#include <stdio.h> | |
#include <string.h> | |
#define LEN_B 15 | |
#define LEN_C 16 | |
int main() { | |
struct sockaddr_un a; | |
int b, c; | |
size_t sb, sc; | |
b = socket(AF_UNIX, SOCK_STREAM, 0); | |
c = socket(AF_UNIX, SOCK_STREAM, 0); | |
sb = &a.sun_path[LEN_B] - (char*)&a; | |
sc = &a.sun_path[LEN_C] - (char*)&a; | |
memset(&a, 0, sizeof(a)); | |
a.sun_family = AF_UNIX; | |
if (0 != bind(b, (struct sockaddr*)&a, (socklen_t)sb)) { | |
perror("bind"); | |
return 1; | |
} | |
if (0 != listen(b, SOMAXCONN)) { | |
perror("listen"); | |
return 1; | |
} | |
if (0 != connect(c, (struct sockaddr*)&a, (socklen_t)sc)) { | |
perror("connect"); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment