2021-03-04 14:30:38 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
2024-04-20 20:59:45 +03:00
|
|
|
#include <stdint.h>
|
2023-11-15 19:36:34 +03:00
|
|
|
#include <stdio.h>
|
2024-04-20 20:59:45 +03:00
|
|
|
#include <time.h>
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
void hexdump_limited_dlog(const uint8_t *data, size_t size, size_t limit);
|
|
|
|
char *strncasestr(const char *s,const char *find, size_t slen);
|
|
|
|
bool load_file(const char *filename,void *buffer,size_t *buffer_size);
|
|
|
|
bool load_file_nonempty(const char *filename,void *buffer,size_t *buffer_size);
|
2022-03-25 16:59:58 +03:00
|
|
|
bool save_file(const char *filename, const void *buffer, size_t buffer_size);
|
2023-10-26 15:12:32 +03:00
|
|
|
bool append_to_list_file(const char *filename, const char *s);
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
void print_sockaddr(const struct sockaddr *sa);
|
2021-03-05 20:15:56 +03:00
|
|
|
void ntop46(const struct sockaddr *sa, char *str, size_t len);
|
|
|
|
void ntop46_port(const struct sockaddr *sa, char *str, size_t len);
|
2024-04-30 15:35:20 +03:00
|
|
|
bool pton4_port(const char *s, struct sockaddr_in *sa);
|
|
|
|
bool pton6_port(const char *s, struct sockaddr_in6 *sa);
|
2021-03-05 20:15:56 +03:00
|
|
|
|
2023-11-15 19:36:34 +03:00
|
|
|
bool seq_within(uint32_t s, uint32_t s1, uint32_t s2);
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
void dbgprint_socket_buffers(int fd);
|
|
|
|
bool set_socket_buffers(int fd, int rcvbuf, int sndbuf);
|
2022-03-25 16:59:58 +03:00
|
|
|
|
|
|
|
uint64_t pntoh64(const void *p);
|
|
|
|
void phton64(uint8_t *p, uint64_t v);
|
2022-05-03 10:20:42 +03:00
|
|
|
|
2023-11-09 12:08:09 +03:00
|
|
|
bool ipv6_addr_is_zero(const struct in6_addr *a);
|
|
|
|
|
2022-05-03 10:20:42 +03:00
|
|
|
static inline uint16_t pntoh16(const uint8_t *p) {
|
|
|
|
return ((uint16_t)p[0] << 8) | (uint16_t)p[1];
|
|
|
|
}
|
|
|
|
static inline void phton16(uint8_t *p, uint16_t v) {
|
2022-05-03 12:32:14 +03:00
|
|
|
p[0] = (uint8_t)(v >> 8);
|
|
|
|
p[1] = v & 0xFF;
|
2022-05-03 10:20:42 +03:00
|
|
|
}
|
|
|
|
static inline uint32_t pntoh32(const uint8_t *p) {
|
|
|
|
return ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) | ((uint32_t)p[2] << 8) | (uint32_t)p[3];
|
|
|
|
}
|
2023-09-07 13:41:25 +03:00
|
|
|
|
|
|
|
bool parse_hex_str(const char *s, uint8_t *pbuf, size_t *size);
|
|
|
|
void fill_pattern(uint8_t *buf,size_t bufsize,const void *pattern,size_t patsize);
|
2023-11-09 12:08:09 +03:00
|
|
|
|
|
|
|
int fprint_localtime(FILE *F);
|
2024-03-23 22:57:05 +03:00
|
|
|
|
|
|
|
time_t file_mod_time(const char *filename);
|
2024-04-26 21:36:27 +03:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint16_t from,to;
|
|
|
|
bool neg;
|
|
|
|
} port_filter;
|
|
|
|
bool pf_in_range(uint16_t port, const port_filter *pf);
|
|
|
|
bool pf_parse(const char *s, port_filter *pf);
|
2024-09-14 22:07:46 +03:00
|
|
|
|
|
|
|
void fill_random_bytes(uint8_t *p,size_t sz);
|
|
|
|
void fill_random_az(uint8_t *p,size_t sz);
|
|
|
|
void fill_random_az09(uint8_t *p,size_t sz);
|