initial version of hashmap works

This commit is contained in:
2024-11-09 20:43:12 +01:00
parent 51a309e55f
commit 5e5d25cd75
9 changed files with 51 additions and 28 deletions

View File

@@ -1,9 +1,10 @@
#ifndef __HASHMAP_C__
#define __HASHMAP_C__
#include <string.h>
#include <sys/socket.h>
#define HASHMAP_MAX_ITEMS 10000
#define HASHMAP_MAX_CLIENTS 10000
struct hashmap {
int sockfd;
@@ -11,6 +12,8 @@ struct hashmap {
};
int hash(int sockfd);
void hm_init(struct hashmap *map);
void hm_insert(struct hashmap *map, int sockfd, struct sockaddr_storage *sas);
struct hashmap *hm_lookup(struct hashmap *map, int sockfd);
#endif

View File

@@ -26,6 +26,5 @@ void epoll_ctl_add(int epfd, int sockfd, uint32_t events);
void epoll_ctl_del(int epfd, int sockfd);
void setnonblocking(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

@@ -12,5 +12,6 @@
// print every IPs of a hostname
void print_ips(const char *hostname, const char *port);
void get_client_ip(struct sockaddr_storage *sa, char *ip);
#endif