Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Created March 5, 2014 14:06
Show Gist options
  • Select an option

  • Save kotaroito/9367801 to your computer and use it in GitHub Desktop.

Select an option

Save kotaroito/9367801 to your computer and use it in GitHub Desktop.
#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