]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/inet.cpp
Add a dynamic receiver class for more flexible packet handling
[libs/net.git] / source / net / inet.cpp
index f428492f04bb4e7817af30aa4230fb3e59a9e710..17546e88dfe62dc6ec2ba273d808c47653a5e1b8 100644 (file)
@@ -1,10 +1,6 @@
-#ifdef _WIN32
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#endif
-#include <msp/strings/format.h>
+#include "platform_api.h"
 #include "inet.h"
+#include <msp/strings/format.h>
 #include "sockaddr_private.h"
 
 using namespace std;
@@ -12,12 +8,6 @@ using namespace std;
 namespace Msp {
 namespace Net {
 
-InetAddr::InetAddr():
-       port(0)
-{
-       fill(addr, addr+4, 0);
-}
-
 InetAddr::InetAddr(const SysAddr &sa)
 {
        const sockaddr_in &sai = reinterpret_cast<const sockaddr_in &>(sa.addr);
@@ -26,6 +16,22 @@ InetAddr::InetAddr(const SysAddr &sa)
        port = ntohs(sai.sin_port);
 }
 
+InetAddr InetAddr::wildcard(unsigned port)
+{
+       InetAddr addr;
+       addr.port = port;
+       return addr;
+}
+
+InetAddr InetAddr::localhost(unsigned port)
+{
+       InetAddr addr;
+       addr.addr[0] = 127;
+       addr.addr[3] = 1;
+       addr.port = port;
+       return addr;
+}
+
 SockAddr::SysAddr InetAddr::to_sys() const
 {
        SysAddr sa;