Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- client.cpp
- Tunnel client by oaktree & unh0lys0da
- compile with
- g++ -std=c++11 -Wall -Werror client.cpp -o client
- */
- #include <iostream>
- #include <string>
- #include <vector>
- #include <cstdlib>
- #include <cstdio>
- #include <cstring>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <unistd.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #define DEBUG(x) printf("%s\n", x);
- int start_connection(int& sockfd, const std::string& host, const int& port);
- int main(int argc, char** argv) {
- int sockfd;
- if (argc != 3) {
- std::cout << "[*] Usage: ./tunnel [host] [port]" << std::endl;
- }
- if (start_connection(sockfd, std::string(argv[1]), atoi(argv[2])) != 0) {
- std::cout << "[*] Something went wrong in connecting." << std::endl;
- exit(2);
- }
- }
- int start_connection(int& sockfd, const std::string& host, const int& port) {
- if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- std::cout << "[*] Socket could not be opened." << std::endl;
- return 1;
- }
- struct hostent *server;
- if ( (server = gethostbyname( host.c_str() ) ) == nullptr) {
- std::cout << "[*] Host not found." << std::endl;
- close(sockfd);
- return 2;
- }
- struct sockaddr_in serv_addr;
- memset(&serv_addr, 0, sizeof(serv_addr));
- bcopy(
- (char*)server->h_addr,
- (char*)&serv_addr.sin_addr.s_addr,
- server->h_length
- );
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_port = htons(port);
- // if ( connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
- // std::cout << "[*] Could not connect." << std::endl;
- // close(sockfd);
- // return 3;
- // }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement