Skip to content

Commit 7fe9265

Browse files
author
Sparky
authored
Progress
1 parent 7f2e394 commit 7fe9265

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

source/whitelist.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@
22

33
#include "socket.h"
44
#include <vector>
5+
#include <fstream>
6+
#include <regex>
57

68
std::vector<std::pair<std::string, std::string> > whitelist;
79

810
void parseWhitelist()
911
{
12+
//Somewhere glua can't read?
13+
std::ifstream input("../../../gm_socket_whitelist.txt");
14+
if(input)
15+
{
16+
std::regex line_parser("([\\w\\.-]+)\\s+(\\d+)(?:(?:\r?\n)+|$)");
17+
for (std::sregex_iterator match = std::sregex_iterator(std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>(), line_parser), end = std::sregex_iterator(); match != end; ++match)
18+
{
19+
whitelist.push_back(std::pair<std::string, std::string>(match->operator[](1).str(), match->operator[](2).str());
20+
}
21+
}
1022
}
1123

1224
bool isSafe(unsigned char* pNodeName, unsigned char* pServiceName)
1325
{
1426
for(auto i = whitelist.begin(), end = whitelist.end(); i!=end; ++i)
1527
{
16-
if(i->first == NodeStr && i->second == pServiceName)
28+
if(i->first == pNodeName && i->second == pServiceName)
1729
{
1830
return true;
1931
}
@@ -23,12 +35,19 @@ bool isSafe(unsigned char* pNodeName, unsigned char* pServiceName)
2335

2436
extern "C" {
2537

38+
#ifdef WIN32_
2639
WINSOCK_API_LINKAGE INT WSAAPI __wrap_getaddrinfo(
2740
_In_opt_ PCSTR pNodeName,
2841
_In_opt_ PCSTR pServiceName,
2942
_In_opt_ const ADDRINFOA * pHints,
3043
_Outptr_ PADDRINFOA * ppResult
3144
)
45+
#else
46+
extern int __wrap_getaddrinfo (__const char *__restrict pNodeName,
47+
__const char *__restrict pServiceName,
48+
__const struct addrinfo *__restrict pHints,
49+
struct addrinfo **__restrict ppResult)
50+
#endif
3251
{
3352
if(isSafe(pNodeName, pServiceName))
3453
{
@@ -40,4 +59,4 @@ extern "C" {
4059
}
4160
}
4261

43-
}
62+
}

0 commit comments

Comments
 (0)