-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add new socket manager - add some function to set option on socket - add atexit for parsing and socket
- Loading branch information
Showing
26 changed files
with
415 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* socket.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: brda-sil <brda-sil@students.42angouleme +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/11/09 00:48:48 by brda-sil #+# #+# */ | ||
/* Updated: 2024/08/13 21:27:15 by brda-sil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef LIBFT_NETWORK_SOCKET_H | ||
# define LIBFT_NETWORK_SOCKET_H | ||
|
||
/* ########################################################################## */ | ||
/* REQUIREMENTS */ | ||
/* ############ */ | ||
|
||
# include "libft_define.h" | ||
|
||
/* ########################################################################## */ | ||
|
||
/* ########################################################################## */ | ||
/* CONFIG */ | ||
/* ###### */ | ||
|
||
# define FT_SOCKET_MAX 0x80 | ||
|
||
/* ########################################################################## */ | ||
|
||
/* ########################################################################## */ | ||
/* STRUCT */ | ||
/* ###### */ | ||
typedef t_int32 t_socket_id; | ||
|
||
/* ########################################################################## */ | ||
|
||
|
||
/* ########################################################################## */ | ||
/* FILES */ | ||
/* ##### */ | ||
|
||
// network/socket/ft_socket.c | ||
int ft_socket(int domain, int type, int protocol); | ||
|
||
// network/socket/ft_socket_get.c | ||
int ft_socket_get(t_socket_id index); | ||
int *ft_socket_get_new(); | ||
t_socket_id ft_socket_get_index(int sock); | ||
|
||
// network/socket/ft_socket_singletone.c | ||
int *ft_socket_sing_get(); | ||
void ft_socket_sing_free(); | ||
|
||
// network/socket/setsockopt/bind_interface.c | ||
t_bool ft_setsockopt_bind_interface(int sock, char *interface); | ||
|
||
// network/socket/setsockopt/ipheader.c | ||
t_bool ft_setsockopt_ipheader(int sock); | ||
|
||
// network/socket/setsockopt/timeout.c | ||
t_bool ft_setsockopt_timeout(int sock, int timeout); | ||
|
||
/* ########################################################################## */ | ||
|
||
#endif /* LIBFT_NETWORK_SOCKET_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* get_nameserver.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: brda-sil <brda-sil@students.42angouleme +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/12 15:06:04 by brda-sil #+# #+# */ | ||
/* Updated: 2024/08/13 10:10:19 by brda-sil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft_network.h" | ||
#include "libft_input.h" | ||
#include <fcntl.h> | ||
|
||
t_int4 get_dns_nameserver(void) | ||
{ | ||
int fd; | ||
char* line; | ||
char** splitted; | ||
t_int4 ip; | ||
|
||
fd = open("/etc/resolv.conf", O_RDONLY); | ||
if (fd < 0) | ||
return (0); | ||
while (TRUE) | ||
{ | ||
line = ft_get_next_line(fd); | ||
if (!line) | ||
{ | ||
free(line); | ||
break ; | ||
} | ||
else if (ft_strncmp(line, "nameserver", 10)) | ||
{ | ||
free(line); | ||
continue ; | ||
} | ||
break; | ||
} | ||
ft_get_next_line(-2); | ||
close(fd); | ||
splitted = ft_split(line, ' '); | ||
free(line); | ||
splitted[1][ft_strlen(splitted[1]) - 1] = '\0'; | ||
ip = ft_ipstr(splitted[1]); | ||
ft_free_char_pp(splitted); | ||
ip = ip? ip: DNS_DEFAULT_ADDR; | ||
return (ft_htonl(ip)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.