Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <sys/socket.h>
  6. #include <sys/un.h>
  7.  
  8. int
  9. main(int argc, char **argv)
  10. {
  11. int s;
  12. struct sockaddr_un sun;
  13.  
  14. if (argc != 2 || strlen(argv[1]) + 1 > sizeof(sun.sun_path)) {
  15. fprintf(stderr, "usage: %s abstract-pathn", argv[0]);
  16. exit(1);
  17. }
  18.  
  19. s = socket(AF_UNIX, SOCK_STREAM, 0);
  20. if (s < 0) {
  21. perror("socket");
  22. exit(1);
  23. }
  24. memset(&sun, 0, sizeof(sun));
  25. sun.sun_family = AF_UNIX;
  26. strcpy(sun.sun_path + 1, argv[1]);
  27. if (bind(s, (struct sockaddr *) &sun, sizeof(sun))) {
  28. perror("bind");
  29. exit(1);
  30. }
  31. if (listen(s, 5)) {
  32. perror("listen");
  33. exit(1);
  34. }
  35. pause();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement