change sockaddr generation to pass around correct types.
[trinity.git] / net / ax25.c
blobf0badf271ed53074fdef0a031882c4c669cd5958
1 #include <stdlib.h>
2 #include <sys/types.h>
3 #include <sys/socket.h>
4 #include <sys/un.h>
5 #include <netinet/in.h>
6 #include <netax25/ax25.h>
7 #include "maps.h" // page_rand
8 #include "net.h"
9 #include "random.h"
10 #include "utils.h" // ARRAY_SIZE
11 #include "compat.h"
13 void ax25_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
15 struct sockaddr_ax25 *ax25;
17 ax25 = malloc(sizeof(struct sockaddr_ax25));
18 if (ax25 == NULL)
19 return;
21 ax25->sax25_family = PF_AX25;
22 memcpy(ax25->sax25_call.ax25_call, page_rand, 7);
23 ax25->sax25_ndigis = rand();
24 *addr = (struct sockaddr *) ax25;
25 *addrlen = sizeof(struct sockaddr_ax25);
28 #define NR_AX25_PROTOS 13
29 static int ax25_protocols[NR_AX25_PROTOS] = {
30 0x01, /* ROSE */
31 0x06, /* Compressed TCP/IP packet *//* Van Jacobsen (RFC 1144) */
32 0x07, /* Uncompressed TCP/IP packet *//* Van Jacobsen (RFC 1144) */
33 0x08, /* Segmentation fragment */
34 0xc3, /* TEXTNET datagram protocol */
35 0xc4, /* Link Quality Protocol */
36 0xca, /* Appletalk */
37 0xcb, /* Appletalk ARP */
38 0xcc, /* ARPA Internet Protocol */
39 0xcd, /* ARPA Address Resolution */
40 0xce, /* FlexNet */
41 0xcf, /* NET/ROM */
42 0xF0 /* No layer 3 protocol impl. */
45 void ax25_rand_socket(struct socket_triplet *st)
47 switch (rand() % 3) {
48 case 0: st->type = SOCK_DGRAM;
49 st->protocol = 0;
50 break;
51 case 1: st->type = SOCK_SEQPACKET;
52 st->protocol = ax25_protocols[rand() % NR_AX25_PROTOS];
53 break;
54 case 2: st->type = SOCK_RAW;
55 break;
56 default:break;
60 #define NR_SOL_AX25_OPTS ARRAY_SIZE(ax25_opts)
61 static const unsigned int ax25_opts[] = {
62 AX25_WINDOW, AX25_T1, AX25_N2, AX25_T3,
63 AX25_T2, AX25_BACKOFF, AX25_EXTSEQ, AX25_PIDINCL,
64 AX25_IDLE, AX25_PACLEN, AX25_IAMDIGI,
65 SO_BINDTODEVICE };
67 void ax25_setsockopt(struct sockopt *so)
69 unsigned char val;
71 so->level = SOL_AX25;
73 val = rand() % NR_SOL_AX25_OPTS;
74 so->optname = ax25_opts[val];