Rewrote network stack, started working on porting to 64-bit

This commit is contained in:
2022-03-12 11:39:41 +02:00
parent 64596d344c
commit a056345a7b
167 changed files with 1388 additions and 3085 deletions

View File

@ -25,7 +25,7 @@
char * mem_data;
int mem_size;
long flag;
int flag;
};
extern LPBUFFER buffer_new(int size); // <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>

View File

@ -11,6 +11,7 @@
#include <cassert>
#include <cctype>
#include <climits>
#include <string>
#include <dirent.h>
#include <sys/time.h>

View File

@ -1,10 +1,6 @@
#ifndef __INC_LIBTHECORE_UTILS_H__
#define __INC_LIBTHECORE_UTILS_H__
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#define SAFE_FREE(p) { if (p) { free( (void *) p); (p) = NULL; } }
#define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } }
@ -62,6 +58,9 @@ extern "C"
extern char * time_str(time_t ct);
std::string GetSocketHost(const sockaddr * address);
in_port_t GetSocketPort(const sockaddr * address);
#define CREATE(result, type, number) do { \
if (!((result) = (type *) calloc ((number), sizeof(type)))) { \
sys_err("calloc failed [%d] %s", errno, strerror(errno)); \
@ -127,9 +126,6 @@ extern "C"
((DWORD)(BYTE) (ch2) << 16) | ((DWORD)(BYTE) (ch3) << 24))
#endif // defined(MAKEFOURCC)
#ifdef __cplusplus
}
#endif // __cplusplus
// _countof for gcc/g++
#if !defined(_countof)

View File

@ -126,7 +126,7 @@ void _sys_err(const char *func, int line, const char *format, ...)
return;
time_s[strlen(time_s) - 1] = '\0';
len = snprintf(buf, 1024, "SYSERR: %-15.15s.%d :: %s: ", time_s + 4, tv.tv_usec, func);
len = snprintf(buf, 1024, "SYSERR: %-15.15s.%ld :: %s: ", time_s + 4, tv.tv_usec, func);
buf[1025] = '\0';
if (len < 1024)
@ -211,7 +211,7 @@ void sys_log(unsigned int bit, const char *format, ...)
fprintf(log_file_sys->fp, sys_log_header_string);
time_s[strlen(time_s) - 1] = '\0';
fprintf(log_file_sys->fp, "%-15.15s.%d :: ", time_s + 4, tv.tv_usec );
fprintf(log_file_sys->fp, "%-15.15s.%ld :: ", time_s + 4, tv.tv_usec );
va_start(args, format);
vfprintf(log_file_sys->fp, format, args);
@ -403,8 +403,8 @@ void log_file_rotate(LPLOGFILE logfile)
{
struct tm curr_tm;
time_t time_s;
char dir[128];
char system_cmd[128];
char dir[256];
char system_cmd[256];
time_s = time(0);
curr_tm = *localtime(&time_s);
@ -429,7 +429,7 @@ void log_file_rotate(LPLOGFILE logfile)
if (curr_tm.tm_hour != logfile->last_hour)
{
struct stat stat_buf;
snprintf(dir, 128, "%s/%04d%02d%02d", log_dir, curr_tm.tm_year + 1900, curr_tm.tm_mon + 1, curr_tm.tm_mday);
snprintf(dir, sizeof(dir), "%s/%04d%02d%02d", log_dir, curr_tm.tm_year + 1900, curr_tm.tm_mon + 1, curr_tm.tm_mday);
if (stat(dir, &stat_buf) != 0 || S_ISDIR(stat_buf.st_mode))
{
@ -448,9 +448,9 @@ void log_file_rotate(LPLOGFILE logfile)
// <20>ű<EFBFBD><C5B1><EFBFBD>.
#ifndef __WIN32__
snprintf(system_cmd, 128, "mv %s %s/%s.%02d", logfile->filename, dir, logfile->filename, logfile->last_hour);
snprintf(system_cmd, sizeof(system_cmd), "mv %s %s/%s.%02d", logfile->filename, dir, logfile->filename, logfile->last_hour);
#else
snprintf(system_cmd, 128, "move %s %s\\%s.%02d", logfile->filename, dir, logfile->filename, logfile->last_hour);
snprintf(system_cmd, sizeof(system_cmd), "move %s %s\\%s.%02d", logfile->filename, dir, logfile->filename, logfile->last_hour);
#endif
system(system_cmd);

View File

@ -6,6 +6,7 @@
*/
#define __LIBTHECORE__
#include "stdafx.h"
#include <common/length.h>
static struct timeval null_time = { 0, 0 };
@ -473,3 +474,44 @@ DWORD get_dword_time()
tv.tv_sec -= get_boot_sec();
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
}
std::string GetSocketHost(const sockaddr * address) {
sockaddr_in* peer;
sockaddr_in6* peer6;
char host[MAX_HOST_LENGTH + 1];
switch (address->sa_family) {
case AF_INET:
peer = (sockaddr_in*) address;
return inet_ntop(AF_INET, &(peer->sin_addr), host, INET_ADDRSTRLEN);
case AF_INET6:
peer6 = (sockaddr_in6*) address;
return inet_ntop(AF_INET, &(peer6->sin6_addr), host, INET6_ADDRSTRLEN);
default:
break;
}
return "";
}
in_port_t GetSocketPort(const sockaddr * address) {
sockaddr_in* peer;
sockaddr_in6* peer6;
switch (address->sa_family) {
case AF_INET:
peer = (sockaddr_in*) address;
return peer->sin_port;
case AF_INET6:
peer6 = (sockaddr_in6*) address;
return peer6->sin6_port;
default:
break;
}
return 0;
}