#include <string.h>
#include <errno.h>
#include <sstream>
+#include <iomanip>
#include "util/string.h"
#include "util/numeric.h"
// IP address -> textual representation
std::string Address::serializeString() const
{
+// windows XP doesnt have inet_ntop, maybe use better func
+#ifdef _WIN32
if(m_addr_family == AF_INET)
{
u8 a, b, c, d, addr;
for(int i = 0; i < 16; i += 2)
{
u16 section =
- (m_address.ipv6.sin6_addr.s6_addr[i] << 8) |
- (m_address.ipv6.sin6_addr.s6_addr[i + 1]);
+ (m_address.ipv6.sin6_addr.s6_addr[i] << 8) |
+ (m_address.ipv6.sin6_addr.s6_addr[i + 1]);
os << std::hex << section;
if(i < 14)
os << ":";
}
else
return std::string("");
+#else
+ char str[INET6_ADDRSTRLEN];
+ if (inet_ntop(m_addr_family, (m_addr_family == AF_INET) ? (void*)&(m_address.ipv4.sin_addr) : (void*)&(m_address.ipv6.sin6_addr), str, INET6_ADDRSTRLEN) == NULL) {
+ return std::string("");
+ }
+ return std::string(str);
+#endif
}
struct sockaddr_in Address::getAddress() const
for(int i = 0; i < size && i < 20; i++)
{
if(i % 2 == 0)
- DEBUGPRINT(" ");
+ dstream << " ";
unsigned int a = ((const unsigned char *) data)[i];
- DEBUGPRINT("%.2X", a);
+ dstream << std::hex << std::setw(2) << std::setfill('0')
+ << a;
}
if(size > 20)
for(int i = 0; i < received && i < 20; i++)
{
if(i % 2 == 0)
- DEBUGPRINT(" ");
+ dstream << " ";
unsigned int a = ((const unsigned char *) data)[i];
- DEBUGPRINT("%.2X", a);
+ dstream << std::hex << std::setw(2) << std::setfill('0')
+ << a;
}
if(received > 20)
dstream << "...";