Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <string.h>
- #include <limits.h>
- #include <unistd.h>
- #include <inttypes.h>
- #include <stdlib.h>
- int main(int argc, char* argv[]) {
- char* host_name = argv[1];
- char* server_name = argv[2];
- char* key = argv[3];
- struct addrinfo hints = {};
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
- int error;
- struct addrinfo* result;
- error = getaddrinfo(host_name, server_name, &hints, &result);
- if (error) {
- printf("%s\n", gai_strerror(error));
- }
- int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (sock < 0) {
- return 0;
- }
- if(connect(sock, result->ai_addr, result->ai_addrlen) != 0){
- return 0;
- }
- if (send(sock, key, strlen(key), 0) <= 0) {
- return 0;
- }
- //char num[128];
- int k = 0;
- if (recv(sock, &k, sizeof(int), 0) <= 0) {
- return 0;
- }
- //int k = atoi(num);
- for (int i = 0; i < k; i++) {
- /*char cur[128];
- sprintf(cur, "%d", i);*/
- if (send(sock, &i, sizeof(int), 0) <= 0) {
- return 0;
- }
- }
- uint64_t res;
- //char s_res[128];
- if (recv(sock, &res, sizeof(uint64_t), 0) <= 0) {
- return 0;
- }
- //res = strtoll(s_res, NULL, 10);
- printf("%"PRIu64"\n", res);
- freeaddrinfo(result);
- close(sock);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement