Delete quic_util.c
This commit is contained in:
167
src/quic_util.c
167
src/quic_util.c
@@ -1,167 +0,0 @@
|
||||
/*
|
||||
* quic_util.c
|
||||
*
|
||||
* Created on: 2019<31><39>4<EFBFBD><34>4<EFBFBD><34>
|
||||
* Author: root
|
||||
*/
|
||||
#include "quic_analysis.h"
|
||||
#include<stdio.h>
|
||||
extern struct quic_param_t g_quic_param;
|
||||
|
||||
|
||||
bool a_readUInt64(UINT64* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset){
|
||||
return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset);
|
||||
}
|
||||
|
||||
bool a_readUInt32(UINT32* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset){
|
||||
return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset);
|
||||
}
|
||||
|
||||
bool a_readUInt8(UINT8* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset){
|
||||
return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset);
|
||||
}
|
||||
|
||||
bool a_readUInt16(UINT16* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset){
|
||||
return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset);
|
||||
}
|
||||
|
||||
bool a_readBytes(void* buf, UINT32 len, char * quic_data, UINT32 quic_data_len, UINT32* quic_offset) {
|
||||
UINT32 offset = *quic_offset;
|
||||
if (!a_canRead(len, quic_data_len, offset)) {
|
||||
return false;
|
||||
}
|
||||
memcpy(buf, quic_data + offset, len);
|
||||
offset += len;
|
||||
*quic_offset = offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool a_canRead(size_t bytes, UINT32 g_len_t, UINT32 g_pos_t) {
|
||||
if(g_pos_t >= g_len_t){
|
||||
return false;
|
||||
}
|
||||
return bytes <= (g_len_t - g_pos_t);
|
||||
}
|
||||
|
||||
UINT64 a_pletoh64(const void *p, UINT32 offset)
|
||||
{
|
||||
return (UINT64)*((const UINT8 *)(p)+7+offset)<<56|
|
||||
(UINT64)*((const UINT8 *)(p)+6+offset)<<48|
|
||||
(UINT64)*((const UINT8 *)(p)+5+offset)<<40|
|
||||
(UINT64)*((const UINT8 *)(p)+4+offset)<<32|
|
||||
(UINT64)*((const UINT8 *)(p)+3+offset)<<24|
|
||||
(UINT64)*((const UINT8 *)(p)+2+offset)<<16|
|
||||
(UINT64)*((const UINT8 *)(p)+1+offset)<<8|
|
||||
(UINT64)*((const UINT8 *)(p)+0+offset)<<0;
|
||||
}
|
||||
UINT64 a_pletoh48(const void *p, UINT32 offset)
|
||||
{
|
||||
return (UINT64)*((const UINT8 *)(p)+5+offset)<<40|
|
||||
(UINT64)*((const UINT8 *)(p)+4+offset)<<32|
|
||||
(UINT64)*((const UINT8 *)(p)+3+offset)<<24|
|
||||
(UINT64)*((const UINT8 *)(p)+2+offset)<<16|
|
||||
(UINT64)*((const UINT8 *)(p)+1+offset)<<8|
|
||||
(UINT64)*((const UINT8 *)(p)+0+offset)<<0;
|
||||
}
|
||||
|
||||
UINT32 a_pletoh32(const void *p, UINT32 offset)
|
||||
{
|
||||
return (UINT32)*((const UINT8 *)(p)+3+offset)<<24|
|
||||
(UINT32)*((const UINT8 *)(p)+2+offset)<<16|
|
||||
(UINT32)*((const UINT8 *)(p)+1+offset)<<8|
|
||||
(UINT32)*((const UINT8 *)(p)+0+offset)<<0;
|
||||
}
|
||||
|
||||
UINT32 a_pletoh24(const void *p, UINT32 offset)
|
||||
{
|
||||
return (UINT32)*((const UINT8 *)(p)+2+offset)<<16|
|
||||
(UINT32)*((const UINT8 *)(p)+1+offset)<<8|
|
||||
(UINT32)*((const UINT8 *)(p)+0+offset)<<0;
|
||||
}
|
||||
|
||||
//UINT16 a_pletoh16(const void *p)
|
||||
//{
|
||||
// UINT32 offset = g_pos_t;
|
||||
// return (UINT16)*((const UINT8 *)(p)+0+offset)<<0|
|
||||
// (UINT16)*((const UINT8 *)(p)+1+offset)<<8;
|
||||
//}
|
||||
|
||||
UINT16 a_pletoh16(const void *p, UINT32 offset){
|
||||
return (UINT16)*((const UINT8 *)(p)+0+offset)<<0|
|
||||
(UINT16)*((const UINT8 *)(p)+1+offset)<<8;
|
||||
}
|
||||
|
||||
UINT16 a_pntoh16(const void *p, UINT32 offset)
|
||||
{
|
||||
return (UINT16)*((const UINT8 *)(p)+1+offset)<<0|
|
||||
(UINT16)*((const UINT8 *)(p)+0+offset)<<8;
|
||||
}
|
||||
|
||||
|
||||
UINT32 a_pntoh24(const void *p, UINT32 offset)
|
||||
{
|
||||
return (UINT32)*((const UINT8 *)(p)+0+offset)<<16|
|
||||
(UINT32)*((const UINT8 *)(p)+1+offset)<<8|
|
||||
(UINT32)*((const UINT8 *)(p)+2+offset)<<0;
|
||||
}
|
||||
|
||||
UINT32 a_pntoh32(const void *p, UINT32 offset)
|
||||
{
|
||||
return (UINT32)*((const UINT8 *)(p)+0+offset)<<24|
|
||||
(UINT32)*((const UINT8 *)(p)+1+offset)<<16|
|
||||
(UINT32)*((const UINT8 *)(p)+2+offset)<<8|
|
||||
(UINT32)*((const UINT8 *)(p)+3+offset)<<0;
|
||||
}
|
||||
|
||||
UINT64 a_pntoh48(const void *p, UINT32 offset)
|
||||
{
|
||||
return (UINT64)*((const UINT8 *)(p)+0+offset)<<40|
|
||||
(UINT64)*((const UINT8 *)(p)+1+offset)<<32|
|
||||
(UINT64)*((const UINT8 *)(p)+2+offset)<<24|
|
||||
(UINT64)*((const UINT8 *)(p)+3+offset)<<16|
|
||||
(UINT64)*((const UINT8 *)(p)+4+offset)<<8|
|
||||
(UINT64)*((const UINT8 *)(p)+5+offset)<<0;
|
||||
}
|
||||
|
||||
UINT64 a_pntoh64(const void *p, UINT32 offset)
|
||||
{
|
||||
return (UINT64)*((const UINT8 *)(p)+0+offset)<<56|
|
||||
(UINT64)*((const UINT8 *)(p)+1+offset)<<48|
|
||||
(UINT64)*((const UINT8 *)(p)+2+offset)<<40|
|
||||
(UINT64)*((const UINT8 *)(p)+3+offset)<<32|
|
||||
(UINT64)*((const UINT8 *)(p)+4+offset)<<24|
|
||||
(UINT64)*((const UINT8 *)(p)+5+offset)<<16|
|
||||
(UINT64)*((const UINT8 *)(p)+6+offset)<<8|
|
||||
(UINT64)*((const UINT8 *)(p)+7+offset)<<0;
|
||||
}
|
||||
|
||||
void a_phton64(UINT8 *p, UINT64 v) {
|
||||
p[0] = (UINT8)(v >> 56);
|
||||
p[1] = (UINT8)(v >> 48);
|
||||
p[2] = (UINT8)(v >> 40);
|
||||
p[3] = (UINT8)(v >> 32);
|
||||
p[4] = (UINT8)(v >> 24);
|
||||
p[5] = (UINT8)(v >> 16);
|
||||
p[6] = (UINT8)(v >> 8);
|
||||
p[7] = (UINT8)(v >> 0);
|
||||
}
|
||||
|
||||
int get_remaining_len(UINT32 g_len_t, UINT32 offset){
|
||||
return g_len_t - offset;
|
||||
}
|
||||
|
||||
void a_ntoa( unsigned int in, char *buffer)
|
||||
{
|
||||
unsigned char *bytes = (unsigned char *) ∈
|
||||
snprintf( buffer, 15, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3] );
|
||||
}
|
||||
|
||||
//char* a_ntoa( unsigned int in, char * str)
|
||||
//{
|
||||
//
|
||||
// char buffer[64];
|
||||
// unsigned char *bytes = (unsigned char *) ∈
|
||||
// printf("%s %d.%d.%d.%d\t", str, bytes[0], bytes[1], bytes[2], bytes[3] );
|
||||
// snprintf( buffer, sizeof (buffer), "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3] );
|
||||
// return buffer;
|
||||
//}
|
||||
Reference in New Issue
Block a user