15#include <netinet/in.h>
19 time_t now = time(NULL);
22 strftime(buffer, buffer_size,
"%Y%m%d%H%M%S", &tm_now);
27 time_t now = time(NULL);
30 strftime(buffer, buffer_size,
"%Y-%m-%d %H:%M:%S", &tm_now);
40 const char* home = getenv(
"HOME");
43 const char* suffix =
"/.bitlab";
44 char* init_dir = malloc(strlen(home) + strlen(suffix) + 1);
47 strcpy(init_dir, home);
48 strcat(init_dir, suffix);
50 mkdir(init_dir, 0700);
59 va_start(args, format);
60 vprintf(format, args);
69 va_start(args, format);
70 vprintf(format, args);
78 if (__BYTE_ORDER == __LITTLE_ENDIAN)
80 return ((uint64_t)ntohl(value & 0xFFFFFFFF) << 32) | ntohl(value >> 32);
91 unsigned char first_byte = data[*offset];
94 if (first_byte < 0xfd)
98 else if (first_byte == 0xfd)
100 result = *(uint16_t*)(data + *offset);
103 else if (first_byte == 0xfe)
105 result = *(uint32_t*)(data + *offset);
108 else if (first_byte == 0xff)
110 result = *(uint64_t*)(data + *offset);
118 struct sockaddr_in sa;
119 return inet_pton(AF_INET, ip_str, &(sa.sin_addr)) == 1;
uint64_t ntohll(uint64_t value)
Convert a 64-bit integer from host byte order to network byte order.
void get_formatted_timestamp(char *buffer, size_t buffer_size)
Get the formatted timestamp.
void clear_cli()
Clear the CLI window.
int is_valid_ipv4(const char *ip_str)
Check if the IP address is valid.
void get_timestamp(char *buffer, size_t buffer_size)
Get the timestamp.
uint64_t read_var_int(const unsigned char *data, size_t *offset)
void guarded_print_line(const char *format,...)
Guarded print line function.
void guarded_print(const char *format,...)
Guarded print function.
int init_config_dir()
Initialize the configuration directory.
struct tm * localtime_r(const time_t *timer, struct tm *buf)
void flockfile(FILE *filehandle)
void funlockfile(FILE *file)