-
Notifications
You must be signed in to change notification settings - Fork 80
/
main.cpp
157 lines (112 loc) · 3.22 KB
/
main.cpp
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <syslog.h>
#include <pthread.h>
#include <iostream>
#include "facebook.h"
#include "tun.h"
#include "utils.h"
/* tcp/ip */
#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
typedef ip IpHeader;
typedef tcphdr TcpHeader;
using namespace std;
#define VERSION_NUMBER "1.0"
#define SERVER_MODE 0
#define CLIENT_MODE 1
static int verboseFlag;
static int mode;
void help() {
cout << "facebook-tunnel " << VERSION_NUMBER << endl << endl;
cout << "This program allows you to send TCP packets over Facebook chat. Login credentials can be specified as arguments." << endl;
cout << "Also when running in client mode, your friend's nickname (your \"server\") is needed." << endl << endl;
cout << "Running as client (example):" << endl << endl;
cout << "$ facebook-tunnel --login [email protected] --password theforce --friend r2d2" << endl << endl;
cout << "Running as server:" << endl << endl;
cout << "$ facebook-tunnel --login [email protected] --password droidpower" << endl;
cout << endl;
};
int main( int argc, char **argv ) {
const char* login = NULL;
const char* password = NULL;
const char* friendName = NULL;
int c;
if( argc < 4 ) {
help();
exit(1);
};
while (1) {
static struct option long_options[] = {
{"verbose", no_argument, &verboseFlag, 1},
{"quiet", no_argument, &verboseFlag, 0},
{"login", required_argument, 0, 'l'},
{"password", required_argument, 0, 'p'},
{"friend", required_argument, 0, 'f'},
{0, 0, 0, 0}
};
int option_index = 0;
c = getopt_long (argc, argv, "f:p:l:", long_options, &option_index);
if (c == -1 ) {
break;
};
switch (c) {
case 0:
if (long_options[option_index].flag != 0)
break;
if (optarg)
break;
case 'l':
login = optarg;
break;
case 'p':
password = optarg;
break;
case 'f':
friendName = optarg;
break;
case '?':
break;
default:
abort ();
};
};
openlog(argv[0], LOG_PERROR, LOG_DAEMON);
if (!verboseFlag)
setlogmask(LOG_UPTO(LOG_INFO));
if( login == NULL || password == NULL ) {
cout << "Credentials are required!\n" << endl;
exit(1);
};
FacebookClient* facebook = new FacebookClient();
// fb auth!
bool authSuccess = facebook->authenticate( login, password );
if( !authSuccess ) {
cout << "Authentication error!" << endl;
exit(1);
};
syslog( LOG_DEBUG, "Setting mode: %d", mode );
if( friendName == NULL ) {
mode = SERVER_MODE;
} else {
mode = CLIENT_MODE;
syslog( LOG_DEBUG, "Looking up friend's ID..." );
int friendID = facebook->getFriendID( friendName );
if( friendID == 0 ) {
syslog( LOG_ERR, "Invalid friend" );
exit(1);
};
};
printf("friend ID => %.20g\n", facebook->friendID );
int alive = true;
int mtu = 1500;
char device[ 8 ];
strcpy( device, "tun0" );
Tun* tunnel = new Tun( device, mtu, mode, (FacebookClient*)facebook );
tunnel->run();
return 0;
};