Skip to content

Instantly share code, notes, and snippets.

@jld
Created February 28, 2018 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jld/00400eaeee4308642eae20107f91d4b8 to your computer and use it in GitHub Desktop.
Save jld/00400eaeee4308642eae20107f91d4b8 to your computer and use it in GitHub Desktop.
#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