summaryrefslogtreecommitdiffhomepage
path: root/NetEx
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-03-30 19:57:43 +0200
committerAki <please@ignore.pl>2022-03-30 19:57:43 +0200
commit98432be171dee1a1ad4774b5600c4f91bfa1f810 (patch)
treec2a034fb1b650f8d10846b334d5b9b2ec2e11198 /NetEx
parent5f77e4b3626cf624351023eaa223620233f82526 (diff)
downloadstarshatter-98432be171dee1a1ad4774b5600c4f91bfa1f810.zip
starshatter-98432be171dee1a1ad4774b5600c4f91bfa1f810.tar.gz
starshatter-98432be171dee1a1ad4774b5600c4f91bfa1f810.tar.bz2
Brought NetHost closer to standard
Diffstat (limited to 'NetEx')
-rw-r--r--NetEx/NetHost.cpp43
-rw-r--r--NetEx/NetHost.h18
2 files changed, 37 insertions, 24 deletions
diff --git a/NetEx/NetHost.cpp b/NetEx/NetHost.cpp
index 1c24ff0..4c8c89f 100644
--- a/NetEx/NetHost.cpp
+++ b/NetEx/NetHost.cpp
@@ -3,40 +3,52 @@
Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
Copyright (c) 1997-2006, Destroyer Studios LLC.
- AUTHOR: John DiCamillo
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- Network Host
+ OVERVIEW
+ ========
+ Network Host
*/
#include "NetHost.h"
-#include "NetLayer.h"
-#include <ctype.h>
+
+#ifdef _WIN32
+#include <winsock2.h>
+#else
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
+
+#include <cstdint>
NetHost::NetHost()
{
char host_name[256];
- gethostname(host_name, sizeof(host_name));
+ ::gethostname(host_name, sizeof(host_name));
Init(host_name);
}
+
NetHost::NetHost(const char* host_name)
{
Init(host_name);
}
-void NetHost::Init(const char* host_name)
+
+void
+NetHost::Init(const char* host_name)
{
if (host_name && *host_name) {
- HOSTENT* h = 0;
+ struct hostent* h = nullptr;
- if (isdigit(*host_name)) {
- DWORD addr = inet_addr(host_name);
- h = gethostbyaddr((const char*) &addr, 4, AF_INET);
+ if (std::isdigit(*host_name)) {
+ auto a = inet_addr(host_name);
+ h = gethostbyaddr((const char*) &a, 4, AF_INET);
}
else {
h = gethostbyname(host_name);
@@ -53,7 +65,7 @@ void NetHost::Init(const char* host_name)
char** addr = h->h_addr_list;
while (*addr) {
- NetAddr* pna = new NetAddr(**(DWORD**) addr);
+ NetAddr* pna = new NetAddr(**(std::uint32_t**) addr);
if (pna)
addresses.append(pna);
addr++;
@@ -62,6 +74,7 @@ void NetHost::Init(const char* host_name)
}
}
+
NetHost::NetHost(const NetHost& n)
{
if (&n != this) {
@@ -79,6 +92,7 @@ NetHost::NetHost(const NetHost& n)
}
}
+
NetHost::~NetHost()
{
aliases.destroy();
@@ -91,11 +105,12 @@ NetHost::Name()
return name;
}
+
NetAddr
NetHost::Address()
{
if (addresses.size())
return *(addresses[0]);
- return NetAddr((DWORD) 0);
+ return NetAddr((std::uint32_t) 0);
} \ No newline at end of file
diff --git a/NetEx/NetHost.h b/NetEx/NetHost.h
index a5a4bd0..c45f04c 100644
--- a/NetEx/NetHost.h
+++ b/NetEx/NetHost.h
@@ -3,23 +3,21 @@
Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
Copyright (c) 1997-2006, Destroyer Studios LLC.
- AUTHOR: John DiCamillo
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- Network Host
+ OVERVIEW
+ ========
+ Network Host
*/
-#ifndef NET_HOST_H
-#define NET_HOST_H
+#ifndef NetHost_h
+#define NetHost_h
-#include <windows.h>
+#include "List.h"
#include "NetAddr.h"
#include "Text.h"
-#include "List.h"
-// +-------------------------------------------------------------------+
class NetHost
{
@@ -46,4 +44,4 @@ private:
};
-#endif // NET_HOST_H
+#endif // NetHost_h