merge pipe variants
[trinity.git] / net / proto-ipv6.c
blob7705fad6222282420115af50559b326c7433b650
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <sys/un.h>
4 #include <netinet/in.h>
5 #include <linux/if.h>
6 #include <linux/if_arp.h>
7 #include <linux/if_packet.h>
8 #include <stdlib.h>
9 #include "maps.h" // page_rand
10 #include "net.h"
11 #include "random.h"
12 #include "utils.h" // ARRAY_SIZE
13 #include "compat.h"
15 void ipv6_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
17 struct sockaddr_in6 *ipv6;
19 ipv6 = malloc(sizeof(struct sockaddr_in6));
20 if (ipv6 == NULL)
21 return;
23 ipv6->sin6_family = PF_INET6;
24 ipv6->sin6_addr.s6_addr32[0] = 0;
25 ipv6->sin6_addr.s6_addr32[1] = 0;
26 ipv6->sin6_addr.s6_addr32[2] = 0;
27 ipv6->sin6_addr.s6_addr32[3] = htonl(1);
28 ipv6->sin6_port = htons(rand() % 65535);
29 *addr = (struct sockaddr *) ipv6;
30 *addrlen = sizeof(struct sockaddr_in6);
33 void inet6_rand_socket(struct socket_triplet *st)
35 switch (rand() % 3) {
36 case 0: st->type = SOCK_STREAM; // TCP
37 st->protocol = 0;
38 break;
40 case 1: st->type = SOCK_DGRAM; // UDP
41 if (rand_bool())
42 st->protocol = 0;
43 else
44 st->protocol = IPPROTO_UDP;
45 break;
47 case 2: st->type = SOCK_RAW;
48 st->protocol = rand() % PROTO_MAX;
49 break;
51 default:break;
55 #define NR_SOL_INET6_OPTS ARRAY_SIZE(inet6_opts)
56 static const unsigned int inet6_opts[] = {
57 IPV6_ADDRFORM, IPV6_2292PKTINFO, IPV6_2292HOPOPTS, IPV6_2292DSTOPTS,
58 IPV6_2292RTHDR, IPV6_2292PKTOPTIONS, IPV6_CHECKSUM, IPV6_2292HOPLIMIT,
59 IPV6_NEXTHOP, IPV6_AUTHHDR, IPV6_FLOWINFO, IPV6_UNICAST_HOPS,
60 IPV6_MULTICAST_IF, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_LOOP, IPV6_ADD_MEMBERSHIP,
61 IPV6_DROP_MEMBERSHIP, IPV6_ROUTER_ALERT, IPV6_MTU_DISCOVER, IPV6_MTU,
62 IPV6_RECVERR, IPV6_V6ONLY, IPV6_JOIN_ANYCAST, IPV6_LEAVE_ANYCAST };
64 void inet6_setsockopt(struct sockopt *so)
66 unsigned char val;
68 so->level = SOL_IPV6;
70 val = rand() % NR_SOL_INET6_OPTS;
71 so->optname = inet6_opts[val];