diff --git a/src/main.c b/src/main.c index 31067f8..5397404 100644 --- a/src/main.c +++ b/src/main.c @@ -8,10 +8,23 @@ #include #include -#define VPN_LIST_PATH "/tmp/ipv4.txt" +#define VPN_DB_DIR "/tmp/vpndb" +#define VPN_LIST_PATH VPN_DB_DIR "/ipv4.txt" #define VPN_LIST_URL "https://raw.githubusercontent.com/X4BNet/lists_vpn/main/ipv4.txt" +int ensure_directory_exists(const char *dirPath) { + struct stat st = {0}; + + if (stat(dirPath, &st) == -1) { + if (mkdir(dirPath, 0755) == -1) { + fprintf(stderr, "Failed to create directory %s\n", dirPath); + return -1; + } + } + return 0; +} + unsigned long ip_to_ulong(const char *ip) { struct in_addr inVal; if (inet_aton(ip, &inVal)) { @@ -58,6 +71,7 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { } int download_vpn_list(const char *url, const char *output_path) { + printf("Downloading VPN lists...\n"); struct stat fileInfo; time_t now; @@ -117,6 +131,11 @@ int main(int argc, char *argv[]) { return 1; } + if (ensure_directory_exists(VPN_DB_DIR) != 0) { + fprintf(stderr, "Failed to create VPN database directory.\n"); + return 1; + } + if (download_vpn_list(VPN_LIST_URL, VPN_LIST_PATH) != 0) { fprintf(stderr, "Failed to download VPN list.\n"); return 1;