SHARE
TWEET

Untitled

a guest Jun 19th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #include <netdb.h>
  4. #include <string>
  5. #include <iostream>
  6. int main()
  7. {
  8.     int status;//hold getaddrinfo results
  9.     struct addrinfo hints;
  10.     struct addrinfo *res;
  11.     const char *ip= "127.0.0.1";
  12.     const char *port = "1337";
  13.     hints.ai_family = AF_UNSPEC;//socket ipv4, or ipv6, unspec == both
  14.     hints.ai_socktype = SOCK_STREAM;//user datagram socket
  15.     hints.ai_flags = AI_PASSIVE;//non hardcoded ip value
  16.     getaddrinfo(ip, port, &hints, &res);//fill struct res with socket info
  17.     int sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);//create socket
  18.     bind(sock, res->ai_addr, res->ai_addrlen);//bind to an address
  19.     connect(sock, res->ai_addr, res->ai_addrlen);
  20.     freeaddrinfo(res);
  21.     char* buf[11];
  22.         int data = recv(sock, (void*)buf, 11, 0); //(void*)buf == (void*)(char*) basically, you are typecasting char* to void*
  23.         std::cout << data;
  24.         return 0;
  25. }
RAW Paste Data
Pastebin PRO Autumn Special!
Get 40% OFF on Pastebin PRO accounts!
Top