-
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.
- added i4toh from socket (but need some debugging) - refac dns part - refac ft_getip_str
- Loading branch information
Showing
22 changed files
with
591 additions
and
155 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
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,45 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_getip_str.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: brda-sil <brda-sil@students.42angouleme +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/05/28 14:53:53 by brda-sil #+# #+# */ | ||
/* Updated: 2024/05/28 14:54:06 by brda-sil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft_network.h" | ||
|
||
static t_size set_part(char *ptr, t_int4 n, t_size i) | ||
{ | ||
char *tmp_n; | ||
t_size len_tmp_n; | ||
|
||
tmp_n = ft_itoa(ft_int4_dcomp(n, i)); | ||
len_tmp_n = ft_strlen(tmp_n); | ||
ft_memcpy(ptr, tmp_n, len_tmp_n); | ||
if (i) | ||
{ | ||
ptr[len_tmp_n] = '.'; | ||
len_tmp_n++; | ||
} | ||
free(tmp_n); | ||
return (len_tmp_n); | ||
} | ||
|
||
char *ft_getip_str(t_int4 n) | ||
{ | ||
char *ptr; | ||
t_size index; | ||
|
||
ptr = (char *)ft_calloc(16, sizeof(char)); | ||
|
||
index = set_part(ptr, n, 3); | ||
index += set_part(ptr + index, n, 2); | ||
index += set_part(ptr + index, n, 1); | ||
index += set_part(ptr + index, n, 0); | ||
|
||
return ptr; | ||
} |
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,38 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_i4toh.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: brda-sil <brda-sil@students.42angouleme +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/14 05:54:10 by brda-sil #+# #+# */ | ||
/* Updated: 2024/05/28 21:12:27 by brda-sil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft_network.h" | ||
|
||
char *ft_i4toh_getnameinfo(t_int4 ip) | ||
{ | ||
struct sockaddr_in sa; | ||
char hostname[NI_MAXHOST]; | ||
|
||
ft_bzero(&sa, sizeof(struct sockaddr_in)); | ||
ft_bzero(&hostname, NI_MAXHOST); | ||
sa.sin_family = AF_INET; | ||
sa.sin_addr.s_addr = ip; | ||
if (getnameinfo((struct sockaddr *)&sa, sizeof(sa), hostname, NI_MAXHOST, NULL, 0, 0) != 0) | ||
return (NULL); | ||
return (ft_strdup(hostname)); | ||
} | ||
|
||
char *ft_i4toh(t_int4 ip) | ||
{ | ||
char *retv; | ||
|
||
if (I4TOH_USE_SOCKET) | ||
retv = ft_i4toh_socket(ip); | ||
else | ||
retv = ft_i4toh_getnameinfo(ip); | ||
return (retv); | ||
} |
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.