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) { ...@@ -44,30 +44,57 @@ void outbound(int raw, int tun) {
perror("outbound read"); perror("outbound read");
} }
int main(int argc, char *argv[]) { void show_usage() {
ifreq ifr{}; printf("Usage Help:\n\n");
ifr.ifr_flags = IFF_TUN | IFF_NO_PI; printf("-i <IP>: IP to connect\n");
printf("-h: show this usage help");
return;
}
auto raw = socket(AF_INET, SOCK_RAW, IPPROTO_IPIP); int main(int argc, char *argv[]) {
if(raw < 0){
perror("socket init error"); if(argc <= 1){
printf("Wrong usage! Type -h to see usage help.");
return 0;
} }
auto tun = open("/dev/net/tun", O_RDWR); if(argv[1] == "-h"){
if(tun < 0){ show_usage();
perror("tun init error"); 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){ if(ioctl(tun, TUNSETIFF, &ifr) < 0){
perror("ioctl error"); perror("ioctl error");
} return -1;
}
remote = inet_addr(argv[1]); remote = inet_addr(argv[2]);
std::cout << raw << std::endl; std::cout << raw << std::endl;
std::cout << tun << std::endl; std::cout << tun << std::endl;
std::thread t1(inbound, raw, tun); std::thread t1(inbound, raw, tun);
std::thread t2(outbound, raw, tun); std::thread t2(outbound, raw, tun);
t1.join(); t1.join();
t2.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