2021-03-04 11:30:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
2023-11-09 09:08:09 +00:00
|
|
|
#include <stdio.h>
|
2024-03-23 19:57:05 +00:00
|
|
|
#include <time.h>
|
2021-03-04 11:30:38 +00:00
|
|
|
|
|
|
|
char *strncasestr(const char *s,const char *find, size_t slen);
|
|
|
|
|
2023-10-26 12:12:32 +00:00
|
|
|
bool append_to_list_file(const char *filename, const char *s);
|
|
|
|
|
2021-03-05 18:02:34 +00:00
|
|
|
void ntop46(const struct sockaddr *sa, char *str, size_t len);
|
|
|
|
void ntop46_port(const struct sockaddr *sa, char *str, size_t len);
|
2021-03-04 11:30:38 +00:00
|
|
|
void print_sockaddr(const struct sockaddr *sa);
|
|
|
|
void print_addrinfo(const struct addrinfo *ai);
|
|
|
|
bool check_local_ip(const struct sockaddr *saddr);
|
|
|
|
|
|
|
|
bool saismapped(const struct sockaddr_in6 *sa);
|
|
|
|
bool samappedcmp(const struct sockaddr_in *sa1,const struct sockaddr_in6 *sa2);
|
|
|
|
bool sacmp(const struct sockaddr *sa1,const struct sockaddr *sa2);
|
|
|
|
uint16_t saport(const struct sockaddr *sa);
|
|
|
|
// true = was converted
|
|
|
|
bool saconvmapped(struct sockaddr_storage *a);
|
|
|
|
|
2021-03-19 08:33:42 +00:00
|
|
|
bool is_localnet(const struct sockaddr *a);
|
2021-03-05 18:02:34 +00:00
|
|
|
bool is_linklocal(const struct sockaddr_in6* a);
|
|
|
|
bool is_private6(const struct sockaddr_in6* a);
|
|
|
|
|
2023-07-03 12:28:42 +00:00
|
|
|
bool set_keepalive(int fd);
|
|
|
|
bool set_ttl(int fd, int ttl);
|
|
|
|
bool set_hl(int fd, int hl);
|
|
|
|
bool set_ttl_hl(int fd, int ttl);
|
2021-03-04 11:30:38 +00:00
|
|
|
int get_so_error(int fd);
|
2022-05-03 07:20:42 +00:00
|
|
|
|
2023-10-12 09:35:06 +00:00
|
|
|
// alignment-safe functions
|
2022-05-03 07:20:42 +00:00
|
|
|
static inline uint16_t pntoh16(const uint8_t *p) {
|
|
|
|
return ((uint16_t)p[0] << 8) | (uint16_t)p[1];
|
|
|
|
}
|
2023-10-12 09:35:06 +00:00
|
|
|
static inline void phton16(uint8_t *p, uint16_t v) {
|
|
|
|
p[0] = (uint8_t)(v>>8);
|
|
|
|
p[1] = (uint8_t)v;
|
|
|
|
}
|
2023-11-09 09:08:09 +00:00
|
|
|
|
|
|
|
int fprint_localtime(FILE *F);
|
2024-03-23 19:57:05 +00:00
|
|
|
|
|
|
|
time_t file_mod_time(const char *filename);
|
2024-04-26 14:23:03 +00: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);
|