]> git.tdb.fi Git - netvis.git/blob - source/port.cpp
Resolve port names
[netvis.git] / source / port.cpp
1 /* $Id$
2
3 This file is part of NetVis
4 Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
5 Distributed unter the GPL
6 */
7
8 #include <netinet/in.h>
9 #include <netdb.h>
10 #include <msp/strings/lexicalcast.h>
11 #include "port.h"
12
13 Port::Port(unsigned n, const Msp::GL::Color &c):
14         number(n),
15         color(c)
16 {
17         char buf[128];
18         sockaddr_in addr;
19         addr.sin_family = AF_INET;
20         addr.sin_port = ntohs(number);
21         addr.sin_addr.s_addr = 0;
22         int err = getnameinfo(reinterpret_cast<sockaddr *>(&addr), sizeof(sockaddr_in), 0, 0, buf, sizeof(buf), 0);
23         if(err==0)
24                 name = buf;
25         else
26                 name = Msp::lexical_cast(number);
27 }