initial hashmap code

This commit is contained in:
2024-11-09 19:58:58 +01:00
parent 2f39ca6fc1
commit 51a309e55f
16 changed files with 172 additions and 87 deletions

View File

@@ -2,16 +2,16 @@
#define __CLIENT_H__
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
int test_client_connection(const char *hostname, const char *port);
int test_client_connection(const char *hostname, const char *service);
#endif

16
include/hashmap.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef __HASHMAP_C__
#define __HASHMAP_C__
#include <sys/socket.h>
#define HASHMAP_MAX_ITEMS 10000
struct hashmap {
int sockfd;
struct sockaddr_storage sas;
};
int hash(int sockfd);
void hm_insert(struct hashmap *map, int sockfd, struct sockaddr_storage *sas);
#endif

View File

@@ -2,18 +2,17 @@
#define __SERVER_H__
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/epoll.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#define PORT 3030
#define BACKLOG 10
@@ -24,7 +23,9 @@ int start_server(const char *hostname, const char *service);
void setup_hints(struct addrinfo *hints, size_t len, const char *hostname);
void handle_clients(int sockfd);
void epoll_ctl_add(int epfd, int sockfd, uint32_t events);
void epoll_ctl_del(int epfd, int sockfd);
void setnonblocking(int sockfd);
void handle_new_client(int sockfd);
int handle_new_client(int sockfd, struct sockaddr_storage *their_sa, socklen_t *theirsa_size);
void print_client_ip(struct sockaddr_in *sin);
#endif

View File

@@ -4,12 +4,11 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
// print every IPs of a hostname
void print_ips(const char *hostname, const char *port);