RN/Blatt02/A203/util.c

47 lines
1.5 KiB
C
Raw Permalink Normal View History

2024-11-23 18:09:49 +01:00
#include "util.h"
void print_hex(uint8_t * array, size_t size){
for (size_t i = 0 ; i < size; i++){
uint8_t high = (array[i] >> 4) & 0x0F;
uint8_t low = array[i] & 0x0F;
printf("%X", high);
printf("%X ", low);
}
printf("\n");
}
void print_u16_hex(uint16_t number){
uint8_t tmp_a[2];
tmp_a[0] = (number >> 8) & 0x00FF;
tmp_a[1] = number & 0x00FF;
print_hex(tmp_a, 2);
return;
}
void print_u8_hex(uint8_t number){
printf("%X", (number >> 4) & 0x0F);
printf("%X", number & 0x0F);
printf("\n");
}
// void print_packet_info(arp_packet_t * packet){
// printf("destination: "); print_hex(packet->destination, DST_S);
// printf("source: "); print_hex(packet->source, SRC_S);
//
// printf("hardware type: "); print_u16_hex(packet->hrd_t);
// printf("protocal type: "); print_u16_hex(packet->pro_t);
// printf("hardware size: "); print_u8_hex(packet->hrd_s);
// printf("protocal size: "); print_u8_hex(packet->pro_s);
// printf("op type: "); print_u16_hex(packet->op);
//
// printf("sender mac address: "); print_hex(packet->sender_mac_a, SENDER_MAC_A_S);
// printf("sender ip address: "); print_hex(packet->sender_ip_a, SENDER_IP_A_S);
// printf("target mac address: "); print_hex(packet->target_mac_a, TARGET_MAC_A_S);
// printf("target ip address: "); print_hex(packet->target_ip_a, TARGET_IP_A_S);
// }
uint16_t combine_uint8(uint8_t high, uint8_t low){
return (high << 8 ) | low;
}
uint32_t combine_uint8_32(uint8_t * arr){
return (arr[0] << 24 ) | (arr[1] << 16) | (arr[2] << 8) | (arr[3]);
}