2.cpp
1
#include <iostream>                 //    ____                _                  _        _      __                  ___  
2
#include <sys/socket.h>             //   |  _ \ ___  __ _  __| |  ___  ___   ___| | _____| |_   / / __ ___  __ _  __| \ \. 
3
#include <netinet/in.h>             //   | |_) / _ \/ _` |/ _` | / __|/ _ \ / __| |/ / _ \ __| | | '__/ _ \/ _` |/ _` || |
4
#include <arpa/inet.h>              //   |  _ <  __/ (_| | (_| | \__ \ (_) | (__|   <  __/ |_  | | | |  __/ (_| | (_| || |
5
#include <unistd.h>                 //   |_| \_\___|\__,_|\__,_| |___/\___/ \___|_|\_\___|\__| | |_|  \___|\__,_|\__,_|| |
6
                                    //                                                          \_\                   /_/ 
7
int main(int argc, char **argv) {
8
	
9
	int fd = socket(PF_INET, SOCK_STREAM, 0);
10
	
11
	sockaddr_in address { .sin_family = AF_INET,
12
	                      .sin_port = htons(13),
13
	                      .sin_addr = {.s_addr = inet_addr("127.0.0.1") }
14
	                    };
15
	
16
	connect(fd, (sockaddr*) &address, sizeof(address));
17
	
18
	char buffer[255];
19
	
20
	ssize_t readSize = read(fd, buffer, 254);
21
	
22
	buffer[readSize] = 0;
23
	
24
	close(fd);
25
	
26
	std::cout << buffer << std::endl;
27
	
28
	return 0;
29
}
Loading...