# IPv4StringToUnsignedLong

```
typedef NTSTATUS(NTAPI* RTLIPV4STRINGTOADDRESSW)(PCWSTR, BOOL, LPCWSTR*, PIN_ADDR);

ULONG ConvertIPv4StringToUnsignedLongW(_In_ PWCHAR IpAddress)
{
	RTLIPV4STRINGTOADDRESSW RtlIpv4StringToAddressW = NULL;
	HMODULE hModule = NULL;
	IN_ADDR IpAddressObject = { 0 };
	LPCWSTR TerminatorObject = NULL;

	hModule = GetModuleHandleW(L"ntdll.dll");
	if (hModule == NULL)
		return 0;

	RtlIpv4StringToAddressW = (RTLIPV4STRINGTOADDRESSW)GetProcAddress(hModule, "RtlIpv4StringToAddressW");
	if (!RtlIpv4StringToAddressW)
		return 0;

	if (RtlIpv4StringToAddressW(IpAddress, FALSE, &TerminatorObject, &IpAddressObject) != ERROR_SUCCESS)
		return FALSE;

	RtlIpv4StringToAddressW = NULL;

	return IpAddressObject.S_un.S_addr;
}

ULONG ConvertIPv4StringToUnsignedLongA(_In_ PCHAR IpAddress)
{
	RTLIPV4STRINGTOADDRESSA RtlIpv4StringToAddressA = NULL;
	HMODULE hModule = NULL;
	IN_ADDR IpAddressObject = { 0 };
	LPCSTR TerminatorObject = NULL;

	hModule = GetModuleHandleW(L"ntdll.dll");
	if (hModule == NULL)
		return 0;

	RtlIpv4StringToAddressA = (RTLIPV4STRINGTOADDRESSA)GetProcAddress(hModule, "RtlIpv4StringToAddressA");
	if (!RtlIpv4StringToAddressA)
		return 0;

	if (RtlIpv4StringToAddressA(IpAddress, FALSE, &TerminatorObject, &IpAddressObject) != ERROR_SUCCESS)
		return FALSE;

	RtlIpv4StringToAddressA = NULL;

	return IpAddressObject.S_un.S_addr;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://malwaresourcecode.com/home/networking/ipv4stringtounsignedlong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
