Utilitaries for payload manipulation and display.
More...
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <arpa/inet.h>
#include "sha256.h"
Go to the source code of this file.
|
#define | MAC_ADDR_LENGTH 6 |
|
#define | MAC_ADDR_STRLEN 18 |
|
#define | IPV4_ADDR_LENGTH 4 |
|
#define | IPV6_ADDR_LENGTH 16 |
|
Utilitaries for payload manipulation and display.
- Date
- 2022-09-09
- Copyright
- Copyright (c) 2022
◆ compare_ip()
Compare two IP (v4 or v6) addresses.
- Parameters
-
ip_1 | first IP address |
ip_2 | second IP address |
- Returns
- true if the two addresses are equal, false otherwise
◆ compare_ipv6()
bool compare_ipv6 |
( |
uint8_t * |
ipv6_1, |
|
|
uint8_t * |
ipv6_2 |
|
) |
| |
Compare two IPv6 addresses.
- Parameters
-
ipv6_1 | first IPv6 address |
ipv6_2 | second IPv6 address |
- Returns
- true if the two addresses are equal, false otherwise
◆ compute_hash()
uint8_t* compute_hash |
( |
uint8_t * |
payload, |
|
|
int |
payload_len |
|
) |
| |
Compute SHA256 hash of a given payload.
- Parameters
-
payload | Payload to hash |
payload_len | Payload length, including padding (in bytes) |
- Returns
- uint8_t* SHA256 hash of the payload
◆ hexstr_to_payload()
size_t hexstr_to_payload |
( |
char * |
hexstring, |
|
|
uint8_t ** |
payload |
|
) |
| |
Converts a hexstring payload to a data buffer.
- Parameters
-
hexstring | the hexstring to convert |
payload | a double pointer to the payload, which will be set to the start of the payload |
- Returns
- the length of the payload in bytes
◆ ip_net_to_str()
Converts an IP (v4 or v6) address to its string representation.
- Parameters
-
ip_addr | the IP address, as an ip_addr_t struct |
- Returns
- the same IP address in string representation
Converts an IP (v4 or v6) address to its string representation. If it is an IPv6 address, it must be freed after use.
- Parameters
-
ip_addr | the IP address, as an ip_addr_t struct |
- Returns
- the same IP address in string representation
◆ ip_str_to_net()
ip_addr_t ip_str_to_net |
( |
char * |
ip_str, |
|
|
uint8_t |
version |
|
) |
| |
Converts an IP (v4 or v6) address from its string representation to an ip_addr_t struct.
- Parameters
-
ip_str | IP (v4 or v6) address in string representation |
- Returns
- the same IP address as a ip_addr_t struct
◆ ipv4_hex_to_str()
char* ipv4_hex_to_str |
( |
char * |
ipv4_hex | ) |
|
Converts an IPv4 addres from its hexadecimal representation to its string representation.
- Parameters
-
ipv4_hex | IPv4 address in hexadecimal representation |
- Returns
- the same IPv4 address in string representation
◆ ipv4_net_to_str()
char* ipv4_net_to_str |
( |
uint32_t |
ipv4_net | ) |
|
Converts an IPv4 address from its network order numerical representation to its string representation. (Wrapper arount inet_ntoa)
- Parameters
-
ipv4_net | IPv4 address in hexadecimal representation |
- Returns
- the same IPv4 address in string representation
◆ ipv4_str_to_hex()
char* ipv4_str_to_hex |
( |
char * |
ipv4_str | ) |
|
Converts an IPv4 address from its string representation to its hexadecimal representation.
- Parameters
-
ipv4_str | IPv4 address in string representation |
- Returns
- the same IPv4 address in hexadecimal representation
◆ ipv4_str_to_net()
uint32_t ipv4_str_to_net |
( |
char * |
ipv4_str | ) |
|
Converts an IPv4 address from its string representation to its network order numerical representation. (Wrapper arount inet_aton)
- Parameters
-
ipv4_str | IPv4 address in string representation |
- Returns
- the same IPv4 address in network order numerical representation
◆ ipv6_net_to_str()
char* ipv6_net_to_str |
( |
uint8_t |
ipv6[] | ) |
|
Converts an IPv6 address to its string representation.
- Parameters
-
- Returns
- the same IPv6 address in string representation
Converts an IPv6 address to its string representation.
- Parameters
-
- Returns
- the same IPv6 address in string representation
◆ ipv6_str_to_net()
uint8_t* ipv6_str_to_net |
( |
char * |
ipv6_str | ) |
|
Converts an IPv6 address from its string representation to its network representation (a 16-byte array).
- Parameters
-
ipv6_str | IPv6 address in string representation |
- Returns
- the same IPv6 address as a 16-byte array
◆ mac_hex_to_str()
char* mac_hex_to_str |
( |
uint8_t |
mac_hex[] | ) |
|
Converts a MAC address from its hexadecimal representation to its string representation.
- Parameters
-
mac_hex | MAC address in hexadecimal representation |
- Returns
- the same MAC address in string representation
◆ mac_str_to_hex()
uint8_t* mac_str_to_hex |
( |
char * |
mac_str | ) |
|
Converts a MAC address from its string representation to its hexadecimal representation.
- Parameters
-
mac_str | MAC address in string representation |
- Returns
- the same MAC address in hexadecimal representation
◆ print_hash()
void print_hash |
( |
uint8_t * |
hash | ) |
|
Print a SHA256 hash.
- Parameters
-
◆ print_payload()
void print_payload |
( |
int |
length, |
|
|
uint8_t * |
data |
|
) |
| |
Print a packet payload.
- Parameters
-
length | length of the payload in bytes |
data | pointer to the start of the payload |