]> git.tdb.fi Git - netvis.git/blobdiff - source/port.cpp
Resolve port names
[netvis.git] / source / port.cpp
diff --git a/source/port.cpp b/source/port.cpp
new file mode 100644 (file)
index 0000000..11ccfe0
--- /dev/null
@@ -0,0 +1,27 @@
+/* $Id$
+
+This file is part of NetVis
+Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
+Distributed unter the GPL
+*/
+
+#include <netinet/in.h>
+#include <netdb.h>
+#include <msp/strings/lexicalcast.h>
+#include "port.h"
+
+Port::Port(unsigned n, const Msp::GL::Color &c):
+       number(n),
+       color(c)
+{
+       char buf[128];
+       sockaddr_in addr;
+       addr.sin_family = AF_INET;
+       addr.sin_port = ntohs(number);
+       addr.sin_addr.s_addr = 0;
+       int err = getnameinfo(reinterpret_cast<sockaddr *>(&addr), sizeof(sockaddr_in), 0, 0, buf, sizeof(buf), 0);
+       if(err==0)
+               name = buf;
+       else
+               name = Msp::lexical_cast(number);
+}