create a set_rand_bitmask function and use instead of open-coding.
[trinity.git] / net / proto-unix.c
blobfad1d7e585b2ef4d40e48ae6565d65aeee71000e
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <sys/un.h>
4 #include <netinet/in.h>
5 #include <linux/dn.h>
6 #include <stdlib.h>
7 #include "maps.h"
8 #include "net.h"
10 void unix_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
12 struct sockaddr_un *unixsock;
13 unsigned int len;
15 unixsock = malloc(sizeof(struct sockaddr_un));
16 if (unixsock == NULL)
17 return;
19 unixsock->sun_family = PF_UNIX;
20 len = rand() % 20;
21 memset(&page_rand[len], 0, 1);
22 strncpy(unixsock->sun_path, page_rand, len);
23 *addr = (struct sockaddr *) unixsock;
24 *addrlen = sizeof(struct sockaddr_un);
27 void unix_rand_socket(struct socket_triplet *st)
29 st->protocol = PF_UNIX;
31 switch (rand() % 3) {
32 case 0: st->type = SOCK_STREAM;
33 break;
34 case 1: st->type = SOCK_DGRAM;
35 break;
36 case 2: st->type = SOCK_SEQPACKET;
37 break;
38 default:break;