if sock socket AF_UNIX SOCK_DGRAM perror client socket exit bzero clnt

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
perror("client: socket");
exit(2);
}
bzero(&clntaddr, sizeof(clntaddr));
clntaddr.sun_family = AF_UNIX;
int path_len = 0;
path_len = strlen (SOCKET_PATHCLNT); // abstract namespace
clntaddr.sun_path[0] = '\0';
path_len++;
strncpy (&clntaddr.sun_path[1], SOCKET_PATHCLNT, path_len);
if (bind(sock, &clntaddr, sizeof(clntaddr)) < 0) {
close(sock);
perror("client: bind");
exit(3);
}
bzero(&servaddr, sizeof(servaddr));
servaddr.sun_family = AF_UNIX;
strcpy(servaddr.sun_path, SOCKET_PATH);
// data