-/* $Id$
-
-This file is part of libmspnet
-Copyright © 2008 Mikkosoft Productions, Mikko Rasa
-Distributed under the LGPL
-*/
-
#include <msp/strings/formatter.h>
#include "inet.h"
port(0)
{ }
-InetAddr::InetAddr(sockaddr_in &sa):
+InetAddr::InetAddr(const sockaddr_in &sa):
addr(sa.sin_addr.s_addr),
port(sa.sin_port)
{ }
string InetAddr::str() const
{
const unsigned char *ptr=reinterpret_cast<const unsigned char *>(&addr);
- return format("%d.%d.%d.%d:%d", static_cast<int>(ptr[0]), static_cast<int>(ptr[1]), static_cast<int>(ptr[2]), static_cast<int>(ptr[3]), ntohs(port));
+ string result = format("%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]);
+ if(port)
+ result += format(":%d", ntohs(port));
+ return result;
}
unsigned InetAddr::fill_sockaddr(sockaddr &sa) const