rename
[trinity.git] / net / proto-tipc.c
blobad1b0290b8af9fde59c2d2a4ae1395570a697de1
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <sys/un.h>
4 #include <netinet/in.h>
5 #include <linux/tipc.h>
6 #include <stdlib.h>
7 #include "net.h"
8 #include "random.h"
9 #include "utils.h" // ARRAY_SIZE
10 #include "compat.h"
12 void tipc_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
14 struct sockaddr_tipc *tipc;
16 tipc = malloc(sizeof(struct sockaddr_tipc));
17 if (tipc == NULL)
18 return;
19 tipc->family = AF_TIPC;
20 tipc->addrtype = rand();
21 tipc->scope = rand();
22 tipc->addr.id.ref = rand();
23 tipc->addr.id.node = rand();
24 tipc->addr.nameseq.type = rand();
25 tipc->addr.nameseq.lower = rand();
26 tipc->addr.nameseq.upper = rand();
27 tipc->addr.name.name.type = rand();
28 tipc->addr.name.name.instance = rand();
29 tipc->addr.name.domain = rand();
30 *addr = (struct sockaddr *) tipc;
31 *addrlen = sizeof(struct sockaddr_tipc);
34 void tipc_rand_socket(struct socket_triplet *st)
36 st->protocol = 0;
38 switch (rand() % 3) {
39 case 0: st->type = SOCK_STREAM;
40 break;
41 case 1: st->type = SOCK_SEQPACKET;
42 break;
43 case 2: st->type = SOCK_DGRAM;
44 break;
45 default: break;
49 #define NR_SOL_TIPC_OPTS ARRAY_SIZE(tipc_opts)
50 static const unsigned int tipc_opts[] = {
51 TIPC_IMPORTANCE, TIPC_SRC_DROPPABLE, TIPC_DEST_DROPPABLE, TIPC_CONN_TIMEOUT,
52 TIPC_NODE_RECVQ_DEPTH, TIPC_SOCK_RECVQ_DEPTH };
54 void tipc_setsockopt(struct sockopt *so)
56 unsigned char val;
58 so->level = SOL_TIPC;
60 val = rand() % NR_SOL_TIPC_OPTS;
61 so->optname = tipc_opts[val];
63 so->optval = sizeof(__u32);