Skip to content

Instantly share code, notes, and snippets.

@tevino
Last active November 6, 2017 13:11
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 tevino/bfb49384c54e7a41ee16a6a9864210f7 to your computer and use it in GitHub Desktop.
Save tevino/bfb49384c54e7a41ee16a6a9864210f7 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
int main(){
int fds[2];
int ret;
ssize_t size;
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
if (ret != 0) {
printf("Error %d", ret);
return ret;
}
printf("Sending 'Hello'\n");
size = send(fds[0], "Hello", 5, 0);
printf("sent: %zd\n", size);
char* buffer = malloc(sizeof(char) * 10);
size = recv(fds[1], buffer, sizeof(buffer), 0);
printf("recv[%zd]: %s\n", size, buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment