unlock and close cachefile if we bail out of socket creation.
[trinity.git] / net / proto-x25.c
blob94584cfd77f55b7f8099da579026b1ff3adfc1ae
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <sys/un.h>
4 #include <netinet/in.h>
5 #include <linux/x25.h>
6 #include <stdlib.h>
7 #include "net.h"
8 #include "maps.h" // page_rand
9 #include "random.h"
11 void x25_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
13 struct sockaddr_x25 *x25;
14 unsigned int len;
16 x25 = malloc(sizeof(struct sockaddr_x25));
17 if (x25 == NULL)
18 return;
20 x25->sx25_family = PF_X25;
21 len = rand() % 15;
22 memset(&page_rand[len], 0, 1);
23 strncpy(x25->sx25_addr.x25_addr, page_rand, len);
24 *addr = (struct sockaddr *) x25;
25 *addrlen = sizeof(struct sockaddr_x25);
28 void x25_rand_socket(struct socket_triplet *st)
30 st->type = SOCK_SEQPACKET;
31 st->protocol = 0;
34 void x25_setsockopt(struct sockopt *so)
36 so->level = SOL_X25;
38 page_rand[0] = rand_bool();
39 so->optval = sizeof(int);