54 lines
1.1 KiB
C
54 lines
1.1 KiB
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "dns.h"
|
|
#include "port_utils.h"
|
|
#include "utils.h"
|
|
|
|
// SUGGESTION: Use this file for any network-related functionality, such as
|
|
// sending or receiving messages.
|
|
|
|
void
|
|
ptr_ip (char *dst, size_t dst_size, const char *ip)
|
|
{
|
|
char tmp[64];
|
|
strncpy (tmp, ip, sizeof (tmp));
|
|
tmp[sizeof (tmp) - 1] = '\0';
|
|
|
|
char *octets[4];
|
|
char *token = strtok (tmp, ".");
|
|
int count = 0;
|
|
while (token && count < 4)
|
|
{
|
|
octets[count++] = token;
|
|
token = strtok (NULL, ".");
|
|
}
|
|
|
|
if (count != 4)
|
|
{
|
|
fprintf (stderr, "Invalid PTR IP");
|
|
exit (EXIT_FAILURE);
|
|
}
|
|
|
|
snprintf (dst, dst_size, "%s.%s.%s.%s.in-addr.arpa.", octets[3], octets[2],
|
|
octets[1], octets[0]);
|
|
}
|
|
|
|
void
|
|
print_byte_block (uint8_t *bytes, size_t length)
|
|
{
|
|
printf (" ");
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
printf ("%02x", bytes[i]);
|
|
if (i == length - 1)
|
|
printf ("\n");
|
|
else if ((i + 1) % 16 == 0)
|
|
printf ("\n ");
|
|
else if ((i % 2) != 0)
|
|
printf (" ");
|
|
}
|
|
}
|