Skip to content

Commit

Permalink
remove wininet
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ive committed Aug 19, 2024
1 parent 8b8e05a commit fe89078
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
39 changes: 33 additions & 6 deletions libnw/iplookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <wininet.h>
#pragma comment(lib, "wininet.lib")

#include "libnw.h"
#include "utils.h"

static HINTERNET (WINAPI *OsInetOpen) (LPCWSTR, DWORD, LPCWSTR, LPCWSTR, DWORD);
static HINTERNET (WINAPI *OsInetOpenUrl) (HINTERNET, LPCWSTR, LPCWSTR, DWORD, DWORD, DWORD_PTR);
static BOOL (WINAPI *OsInetReadFile) (HINTERNET, LPVOID, DWORD, LPDWORD);
static BOOL (WINAPI *OsInetCloseHandle) (HINTERNET);

static LPSTR
GetYamlField(LPCSTR lpszBuffer, LPCSTR lpszField)
{
Expand Down Expand Up @@ -48,18 +52,18 @@ GetUrlData(LPCWSTR lpszUrl, void* lpBuffer, DWORD dwSize)
if (dwSize <= 1)
goto fail;
ZeroMemory(lpBuffer, dwSize);
net = InternetOpenW(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
net = OsInetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!net)
goto fail;
file = InternetOpenUrlW(net, lpszUrl, NULL, 0, INTERNET_FLAG_RELOAD, 0);
file = OsInetOpenUrl(net, lpszUrl, NULL, 0, INTERNET_FLAG_RELOAD, 0);
if (!file)
goto fail;
InternetReadFile(file, lpBuffer, dwSize - 1, &size);
OsInetReadFile(file, lpBuffer, dwSize - 1, &size);
fail:
if (file)
InternetCloseHandle(file);
OsInetCloseHandle(file);
if (net)
InternetCloseHandle(net);
OsInetCloseHandle(net);
return size;
}

Expand Down Expand Up @@ -97,10 +101,33 @@ static void PrintGeoInfo(PNODE node)

PNODE NW_PublicIp(VOID)
{
HMODULE inet = LoadLibraryW(L"wininet.dll");
PNODE node = NWL_NodeAlloc("PublicIP", 0);
if (NWLC->PublicIpInfo)
NWL_NodeAppendChild(NWLC->NwRoot, node);
if (inet == NULL)
goto out;
*(FARPROC*)&OsInetOpen = GetProcAddress(inet, "InternetOpenW");
if (OsInetOpen == NULL)
goto out;
*(FARPROC*)&OsInetOpenUrl = GetProcAddress(inet, "InternetOpenUrlW");
if (OsInetOpenUrl == NULL)
goto out;
*(FARPROC*)&OsInetReadFile = GetProcAddress(inet, "InternetReadFile");
if (OsInetReadFile == NULL)
goto out;
*(FARPROC*)&OsInetCloseHandle = GetProcAddress(inet, "InternetCloseHandle");
if (OsInetCloseHandle == NULL)
goto out;
PrintIpAddress(node);
PrintGeoInfo(node);

out:
if (inet)
FreeLibrary(inet);
OsInetOpen = NULL;
OsInetOpenUrl = NULL;
OsInetReadFile = NULL;
OsInetCloseHandle = NULL;
return node;
}
2 changes: 1 addition & 1 deletion libnw/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define NWINFO_MAJOR_VERSION 1
#define NWINFO_MINOR_VERSION 0
#define NWINFO_MICRO_VERSION 0
#define NWINFO_BUILD_VERSION 5
#define NWINFO_BUILD_VERSION 6

#define NWINFO_VERSION NWINFO_MAJOR_VERSION,NWINFO_MINOR_VERSION,NWINFO_MICRO_VERSION,NWINFO_BUILD_VERSION
#define NWINFO_VERSION_STR QUOTE(NWINFO_MAJOR_VERSION.NWINFO_MINOR_VERSION.NWINFO_MICRO_VERSION.NWINFO_BUILD_VERSION)
Expand Down

0 comments on commit fe89078

Please sign in to comment.