Skip to content

Commit

Permalink
Replaced A_IPAddressX with SysGetIPAddresses().
Browse files Browse the repository at this point in the history
  • Loading branch information
Lexikos committed Sep 11, 2018
1 parent df6b2e5 commit 47e9f12
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
5 changes: 1 addition & 4 deletions source/script.cpp
Expand Up @@ -245,6 +245,7 @@ FuncEntry g_BIF[] =
BIFn(StrUpper, 1, 2, BIF_StrCase),
BIF1(SubStr, 2, 3),
BIF1(SysGet, 1, 1),
BIF1(SysGetIPAddresses, 0, 0),
BIF1(Tan, 1, 1),
BIF1(TraySetIcon, 0, 3),
BIFn(Trim, 1, 2, BIF_Trim),
Expand Down Expand Up @@ -344,10 +345,6 @@ VarEntry g_BIV_A[] =
A_w(IconTip),
A_wx(Index, BIV_LoopIndex, BIV_LoopIndex_Set),
A_(InitialWorkingDir),
A_x(IPAddress1, BIV_IPAddress),
A_x(IPAddress2, BIV_IPAddress),
A_x(IPAddress3, BIV_IPAddress),
A_x(IPAddress4, BIV_IPAddress),
A_(Is64bitOS),
A_(IsAdmin),
A_(IsCompiled),
Expand Down
1 change: 1 addition & 0 deletions source/script.h
Expand Up @@ -3080,6 +3080,7 @@ BIF_DECL(BIF_DateAdd);
BIF_DECL(BIF_DateDiff);
BIF_DECL(BIF_Env);
BIF_DECL(BIF_SysGet);
BIF_DECL(BIF_SysGetIPAddresses);
BIF_DECL(BIF_PostSendMessage);
BIF_DECL(BIF_Hotkey);
BIF_DECL(BIF_SetTimer);
Expand Down
40 changes: 21 additions & 19 deletions source/script_autoit.cpp
Expand Up @@ -104,41 +104,43 @@ ResultType Script::DoRunAs(LPTSTR aCommandLine, LPTSTR aWorkingDir, bool aDispla



VarSizeType BIV_IPAddress(LPTSTR aBuf, LPTSTR aVarName)
BIF_DECL(BIF_SysGetIPAddresses)
{
// aaa.bbb.ccc.ddd = 15, but allow room for larger IP's in the future.
#define IP_ADDRESS_SIZE 32 // The maximum size of any of the strings we return, including terminator.
if (!aBuf)
return IP_ADDRESS_SIZE - 1; // -1 since we're returning the length of the var's contents, not the size.

Object *addresses = Object::Create();
if (!addresses)
_f_throw(ERR_OUTOFMEM);

WSADATA wsadata;
if (WSAStartup(MAKEWORD(1, 1), &wsadata)) // Failed (it returns 0 on success).
{
*aBuf = '\0';
return 0;
}
_f_return(addresses);

char host_name[256];
gethostname(host_name, _countof(host_name));
HOSTENT *lpHost = gethostbyname(host_name);

// au3: How many adapters have we?
int adapter_count = 0;
while (lpHost->h_addr_list[adapter_count])
++adapter_count;

int adapter_index = aVarName[11] - '1'; // A_IPAddress[1-4]
if (adapter_index >= adapter_count)
_tcscpy(aBuf, _T("0.0.0.0"));
else
for (int i = 0; lpHost->h_addr_list[i]; ++i)
{
IN_ADDR inaddr;
memcpy(&inaddr, lpHost->h_addr_list[adapter_index], 4);
tcslcpy(aBuf, CStringTCharFromCharIfNeeded(inet_ntoa(inaddr)), IP_ADDRESS_SIZE);
memcpy(&inaddr, lpHost->h_addr_list[i], 4);
#ifdef UNICODE
CStringTCharFromChar addr_buf(inet_ntoa(inaddr));
LPTSTR addr_str = const_cast<LPTSTR>(addr_buf.GetString());
#else
LPTSTR addr_str = inet_ntoa(inaddr);
#endif
if (!addresses->Append(addr_str))
{
addresses->Release();
WSACleanup();
_f_throw(ERR_OUTOFMEM);
}
}

WSACleanup();
return (VarSizeType)_tcslen(aBuf);
_f_return(addresses);
}


Expand Down

0 comments on commit 47e9f12

Please sign in to comment.