This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/src/packet/gtp_utils.h

52 lines
994 B
C
Raw Normal View History

2024-07-11 14:19:38 +08:00
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
#include "gtp1_utils.h"
#include "gtp2_utils.h"
// return GTP version 0 or 1
// return 255 if not GTP
static inline uint8_t peek_gtp_version(const char *data, uint16_t len)
{
if (data == NULL || len == 0)
{
return 255;
}
return ((*(uint8_t *)data) >> 5) & 0x07;
}
static inline uint16_t calc_gtp_hdr_len(const char *data, uint32_t len)
{
switch (peek_gtp_version(data, len))
{
case 1:
return calc_gtp1_hdr_len(data, len);
case 2:
return calc_gtp2_hdr_len(data, len);
default:
return 0;
}
}
static inline int gtp_hdr_to_str(const char *hdr, uint16_t len, char *buf, size_t size)
{
switch (peek_gtp_version(hdr, len))
{
case 1:
return gtp1_hdr_to_str((const struct gtp1_hdr *)hdr, buf, size);
case 2:
return gtp2_hdr_to_str((const struct gtp2_hdr *)hdr, buf, size);
default:
return 0;
}
}
#ifdef __cplusplus
}
#endif