Search code examples
ipv4poco-libraries

IPaddress in bytes


I have this:

    Poco::Net::IPAddress RequestingIP = request.clientAddress().host();
    std::cout << RequestingIP.toString();

but how can I read the native IPV4 address in its native Hex ?


Solution

  • IPAddress::addr() will give you the underlying structure, eg. (this is for windows, look at your platform for details on what in_addr and accompanying defines look like):

    IPAddress ia("127.0.0.1");
    const in_addr* inaddr = reinterpret_cast<const in_addr*>(ia.addr());
    std::cout << std::hex << inaddr->s_addr;