Commit 6ef1826c authored by Manni's avatar Manni

fix

added standard parameter format.
parent c4ee0fee
......@@ -44,30 +44,57 @@ void outbound(int raw, int tun) {
perror("outbound read");
}
int main(int argc, char *argv[]) {
ifreq ifr{};
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
void show_usage() {
printf("Usage Help:\n\n");
printf("-i <IP>: IP to connect\n");
printf("-h: show this usage help");
return;
}
auto raw = socket(AF_INET, SOCK_RAW, IPPROTO_IPIP);
if(raw < 0){
perror("socket init error");
int main(int argc, char *argv[]) {
if(argc <= 1){
printf("Wrong usage! Type -h to see usage help.");
return 0;
}
auto tun = open("/dev/net/tun", O_RDWR);
if(tun < 0){
perror("tun init error");
if(argv[1] == "-h"){
show_usage();
return 0;
}
if(argv[1] == "-i"){
ifreq ifr{};
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
auto raw = socket(AF_INET, SOCK_RAW, IPPROTO_IPIP);
if(raw < 0){
perror("socket init error");
return -1;
}
auto tun = open("/dev/net/tun", O_RDWR);
if(tun < 0){
perror("tun init error");
return -1;
}
if(ioctl(tun, TUNSETIFF, &ifr) < 0){
perror("ioctl error");
}
if(ioctl(tun, TUNSETIFF, &ifr) < 0){
perror("ioctl error");
return -1;
}
remote = inet_addr(argv[1]);
remote = inet_addr(argv[2]);
std::cout << raw << std::endl;
std::cout << tun << std::endl;
std::cout << raw << std::endl;
std::cout << tun << std::endl;
std::thread t1(inbound, raw, tun);
std::thread t2(outbound, raw, tun);
t1.join();
t2.join();
std::thread t1(inbound, raw, tun);
std::thread t2(outbound, raw, tun);
t1.join();
t2.join();
return 0;
}
else {
printf("Wrong usage! Type -h to see usage help.");
return 0;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment