23 #include "ip_codecs.h" 25 #include <arpa/inet.h> 26 #include <netinet/in.h> 28 dccl::uint32 goby::acomms::IPv4AddressCodec::pre_encode(
const std::string& field_value)
31 int ret = inet_aton(field_value.c_str(), &addr);
32 return (ret == 0) ? -1 : addr.s_addr;
34 std::string goby::acomms::IPv4AddressCodec::post_decode(
const dccl::uint32& wire_value)
37 addr.s_addr = wire_value;
38 return std::string(inet_ntoa(addr));
41 uint16_t goby::acomms::net_checksum(
const std::string& data)
44 int len = data.size();
45 uint16_t* p = (uint16_t*)&data[0];
55 sum += (*(uint8_t*)p << 8) & 0xFF00;
57 while (sum >> 16) sum = (sum & 0xFFFF) + (sum >> 16);