first commit

This commit is contained in:
Lorenzo Torres 2023-04-12 01:24:28 +02:00
commit 3d07f7beaf
10 changed files with 473 additions and 0 deletions

35
utils.c Normal file
View file

@ -0,0 +1,35 @@
#include "utils.h"
#include <netinet/in.h>
#include <sys/socket.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <arpa/inet.h>
int create_connection(struct sockaddr_in *endpoint)
{
int fd, status;
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
return -1;
}
if ((status = connect(fd, (struct sockaddr*)endpoint, sizeof(*endpoint))) < 0) {
printf("Failed to connect!\n");
return -1;
}
return fd;
}
void close_connection(int socket)
{
close(socket);
}
char *get_token(char *s)
{
const char sep[4] = " ";
return strtok(s, sep);
}