Skip to content

Commit

Permalink
Revert "Merge branch 'fix_dns_name' into main"
Browse files Browse the repository at this point in the history
This reverts commit 5ecd9d6, reversing
changes made to 6b93f45.
  • Loading branch information
Pixailz committed Aug 13, 2024
1 parent 5ecd9d6 commit d3f514f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 192 deletions.
2 changes: 1 addition & 1 deletion inc/libft_network/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# endif // NI_MAXHOST

# define HTOI4_USE_SOCKET 1
# define I4TOH_USE_SOCKET 1
# define I4TOH_USE_SOCKET 0

# define DNS_TYPE_A 1
// # define DNS_TYPE_NS 2
Expand Down
28 changes: 1 addition & 27 deletions inc/libft_network/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: brda-sil <brda-sil@students.42angouleme +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/09 00:48:48 by brda-sil #+# #+# */
/* Updated: 2024/06/03 13:12:21 by brda-sil ### ########.fr */
/* Updated: 2024/05/28 22:04:49 by brda-sil ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -217,22 +217,6 @@ typedef struct s_dnsq
t_uint16 class;
} t_dnsq;

// DNS RECORD

typedef struct s_dnsr_name
{
t_uint16 offset;
char *name;
struct s_dnsr_name *next;
} t_dnsr_name;

typedef struct s_dnsr_struct
{
unsigned char *data;
t_dnsr_name *names;
t_uint16 offset;
} t_dnsr_struct;

typedef struct s_dnsr
{
t_uint16 type;
Expand Down Expand Up @@ -295,16 +279,6 @@ char *ft_dns_get_domain_fmt(char *domain);
// network/packet/dns/get_ptr_record.c
char *ft_dns_get_ptr_record(t_packet *pkt);

// network/packet/dns/get_record/main.c
void append_name(t_dnsr_name *name, t_dnsr_struct **dnsr);
char *get_name_by_offset(t_uint16 offset, t_dnsr_struct *dnsr);
t_uint32 get_dnsr_name(t_dnsr_struct *dnsr);
t_uint16 get_dnsr_type(t_dnsr_struct *dnsr, t_uint16 name_len);
t_uint16 get_dnsr_class(t_dnsr_struct *dnsr, t_uint16 name_len);
char *get_last_name(t_dnsr_struct *dnsr);
t_bool get_dnsr_record(t_dnsr_struct *dnsr, t_uint16 type);
char *ft_dns_get_record(t_packet *pkt, t_uint16 type);

// network/packet/dns/ip_to_domain.c
char *ft_dns_ip_to_domain(t_int4 ip);

Expand Down
1 change: 0 additions & 1 deletion mk/srcs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ SRC_NET_PACK := network/packet/checksum.c \
network/packet/dns/get_a_record.c \
network/packet/dns/get_domain_fmt.c \
network/packet/dns/get_ptr_record.c \
network/packet/dns/get_record/main.c \
network/packet/dns/ip_to_domain.c \
network/packet/dns/name_get.c \
network/packet/dns/print.c \
Expand Down
4 changes: 2 additions & 2 deletions src/network/ipv4/i4toh_socket/recv_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: brda-sil <brda-sil@students.42angouleme +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/26 00:22:20 by brda-sil #+# #+# */
/* Updated: 2024/06/03 13:40:25 by brda-sil ### ########.fr */
/* Updated: 2024/05/28 16:03:34 by brda-sil ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -57,5 +57,5 @@ char *ft_i4toh_recv_packet(int sock)
if (check_reply(&pkt))
break;
}
return (ft_dns_get_record(&pkt, DNS_TYPE_PTR));
return (ft_dns_get_ptr_record(&pkt));
}
150 changes: 0 additions & 150 deletions src/network/packet/dns/get_record/main.c

This file was deleted.

60 changes: 49 additions & 11 deletions test/src/i4toh.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: brda-sil <brda-sil@students.42angouleme +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/31 22:56:30 by brda-sil #+# #+# */
/* Updated: 2024/06/03 13:57:46 by brda-sil ### ########.fr */
/* Updated: 2024/05/28 23:35:13 by brda-sil ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -18,6 +18,8 @@
# define CI_TEST FALSE
#endif

# define TARGET_IP 0xacd914ce

void test_getnameinfo(char *ip);

int test_i4toh(t_int4 ip)
Expand All @@ -26,11 +28,11 @@ int test_i4toh(t_int4 ip)
char *ip_str;

ip_str = ft_getip_str(ft_htonl(ip));
name = ft_i4toh(ip);
name = ft_i4toh_socket(ip);
// test_getnameinfo(ip_str);
free(ip_str);
ft_putip_fd(ip, 1);
ft_printf("%s -> ", CSI "20G");
ft_putstr_fd(" -> ", 1);
if (!name)
{
ft_putstr_fd("error\n", 1);
Expand All @@ -47,14 +49,9 @@ int ci_test(void)
int ret;

ret = 0;
for (int i = 0; i < 1; i++)
{
// ret += test_i4toh(0xd83ad6ae);
// ret += test_i4toh(0x4d9aed79);
// ret += test_i4toh(0xd5f50030);
ret += test_i4toh(0xc0b251f9);
// ret += test_i4toh(0xc0b26915);
}
ret += test_i4toh(0xd83ad6ae);
ret += test_i4toh(0x4d9aed79);
ret += test_i4toh(0xd5f50030);
// ret += test_i4toh(0xc0a80001); // not working for local ip
// ret += test_i4toh(0xc0a8000c);
return (ret);
Expand All @@ -74,3 +71,44 @@ int main(void)
return (interactive());
return (0);
}


#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static int convert4(struct sockaddr_in *sa, const char *name)
{
return inet_pton(sa->sin_family = AF_INET, name, &sa->sin_addr);
}

static int convert6(struct sockaddr_in6 *sa, const char *name)
{
return inet_pton(sa->sin6_family = AF_INET6, name, &sa->sin6_addr);
}


void test_getnameinfo(char *ip)
{
union {
struct sockaddr sa;
struct sockaddr_in s4;
struct sockaddr_in6 s6;
struct sockaddr_storage ss;
} addr;

if (convert4(&addr.s4, ip) != 1 && convert6(&addr.s6, ip) != 1) {
ft_printf("%s: not a valid IP address.\n", ip);
return ;
}

char node[NI_MAXHOST];
int res = getnameinfo(&addr.sa, sizeof addr, node, sizeof node, NULL, 0, NI_NAMEREQD);
if (res) {
ft_printf("%s: %s\n", ip, gai_strerror(res));
return ;
}
ft_printf("REAL: %s\n", node);
return ;
}

0 comments on commit d3f514f

Please sign in to comment.