~ubuntu-branches/debian/sid/trinity/sid

« back to all changes in this revision

Viewing changes to net/proto-ipv6.c

  • Committer: Package Import Robot
  • Author(s): gustavo panizzo
  • Date: 2014-01-17 21:10:15 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140117211015-k2qbnpu0osa5mlil
Tags: 1.3-1
* New upstream version 1.3.
* Removed wrong dependency on linux-headers. (Closes: #733771).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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"
 
14
 
 
15
void ipv6_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
 
16
{
 
17
        struct sockaddr_in6 *ipv6;
 
18
 
 
19
        ipv6 = malloc(sizeof(struct sockaddr_in6));
 
20
        if (ipv6 == NULL)
 
21
                return;
 
22
 
 
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 = rand() % 65535;
 
29
        *addr = (struct sockaddr *) ipv6;
 
30
        *addrlen = sizeof(struct sockaddr_in6);
 
31
}
 
32
 
 
33
void inet6_rand_socket(struct socket_triplet *st)
 
34
{
 
35
        switch (rand() % 3) {
 
36
        case 0: st->type = SOCK_STREAM;     // TCP
 
37
                st->protocol = 0;
 
38
                break;
 
39
 
 
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;
 
46
 
 
47
        case 2: st->type = SOCK_RAW;
 
48
                st->protocol = rand() % PROTO_MAX;
 
49
                break;
 
50
 
 
51
        default:break;
 
52
        }
 
53
}
 
54
 
 
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 };
 
63
 
 
64
void inet6_setsockopt(struct sockopt *so)
 
65
{
 
66
        unsigned char val;
 
67
 
 
68
        so->level = SOL_IPV6;
 
69
 
 
70
        val = rand() % NR_SOL_INET6_OPTS;
 
71
        so->optname = inet6_opts[val];
 
72
}