deprecate execfuse/autosshfs in favor of autosshfs-mount script
[hband-tools.git] / compiled-tools / mksock.c
blobf70ab39915c5295637b55e6ad0c55630fea388c2
2 #include <sys/socket.h>
3 #include <sys/types.h>
4 #include <sys/un.h>
5 #include <errno.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
10 void invmal()
12 fprintf(stderr, "Usage: mksock [-s | -d] PATH\n");
13 exit(1);
16 int main(int argc, char ** argv)
18 struct sockaddr_un sun;
19 int sockfd, r;
20 int type = SOCK_DGRAM;
21 char *sockname;
23 if(argc == 1) invmal();
24 sockname = argv[1];
25 if(argv[1][0]=='-') {
26 if(strcmp(argv[1],"-s")==0) type = SOCK_STREAM;
27 else if(strcmp(argv[1],"-d")==0) type = SOCK_DGRAM;
28 else invmal();
29 if(argc == 2) invmal();
30 sockname = argv[2];
33 memset(&sun, 0, sizeof(sun));
34 sun.sun_family = AF_UNIX;
35 snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", sockname);
37 sockfd = socket(PF_UNIX, type, 0);
39 r = bind(sockfd, (struct sockaddr*)&sun, sizeof(sun));
40 if(r != 0) {
41 fprintf(stderr, "mksock: error making %s: %s\n", sun.sun_path, strerror(errno));
42 exit(r);
45 return 0;