-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuptunnel.c
79 lines (67 loc) · 1.68 KB
/
uptunnel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* A program to manually add or remove tunnel routes. route(8)
* is not sufficiently expressive to do this.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "dat.h"
#include "fns.h"
int
main(int argc, char *argv[])
{
Tunnel tunnel;
struct in_addr local, remote, local44;
int ch, rdomain, tunneldomain;
uint32_t local44addr;
rdomain = 0;
tunneldomain = 0;
while ((ch = getopt(argc, argv, "D:T:?h")) != -1) {
switch (ch) {
case 'T':
tunneldomain = strnum(optarg);
break;
case 'D':
rdomain = strnum(optarg);
break;
break;
case '?':
case 'h':
default:
fatal("usage: uptunnel ifname local remote endpoint");
break;
}
}
argc -= optind;
argv += optind;
initlog();
initsys(rdomain);
if (argc != 4)
fatal("usage: uptunnel ifname local remote endpoint");
memset(&local, 0, sizeof(local));
if (inet_pton(AF_INET, argv[1], &local) <= 0)
fatal("cannot parse local: %s", argv[1]);
memset(&remote, 0, sizeof(remote));
if (inet_pton(AF_INET, argv[2], &remote) <= 0)
fatal("cannot parse remote: %s", argv[2]);
memset(&local44, 0, sizeof(local44));
if (inet_pton(AF_INET, argv[3], &local44) <= 0)
fatal("cannot parse local 44: %s", argv[3]);
local44addr = ntohl(local44.s_addr);
memset(&tunnel, 0, sizeof(tunnel));
strlcpy(tunnel.ifname, argv[0], sizeof(tunnel.ifname));
tunnel.local = ntohl(local.s_addr);
tunnel.remote = ntohl(remote.s_addr);
uptunnel(&tunnel, rdomain, tunneldomain, local44addr);
return 0;
}