22 #include "goby/acomms/ip_codecs.h" 24 #include <arpa/inet.h> 25 #include <netinet/in.h> 30 void ip_test(
const std::string& hex, dccl::Codec& dccl_1)
33 std::string header_data(goby::util::hex_decode(hex));
34 dccl_1.decode(header_data, &iphdr);
35 glog.is(VERBOSE) &&
glog <<
"Header is: " << goby::util::hex_encode(header_data) <<
"\n" 36 << iphdr.DebugString() << std::endl;
39 dccl_1.encode(&test, iphdr);
40 glog.is(VERBOSE) &&
glog <<
"Re-encoded as: " << goby::util::hex_encode(test) << std::endl;
41 assert(test == header_data);
43 unsigned orig_cs = iphdr.header_checksum();
44 iphdr.set_header_checksum(0);
45 dccl_1.encode(&test, iphdr);
47 assert(goby::acomms::net_checksum(header_data) == 0);
48 assert(goby::acomms::net_checksum(test) == orig_cs);
51 int main(
int argc,
char* argv[])
56 dccl::FieldCodecManager::add<goby::acomms::IPGatewayEmptyIdentifierCodec<0xF001> >(
57 "ip_gateway_id_codec_1");
58 dccl::FieldCodecManager::add<goby::acomms::NetShortCodec>(
"net.short");
59 dccl::FieldCodecManager::add<goby::acomms::IPv4AddressCodec>(
"ip.v4.address");
60 dccl::FieldCodecManager::add<goby::acomms::IPv4FlagsFragOffsetCodec>(
"ip.v4.flagsfragoffset");
62 dccl::Codec dccl_1(
"ip_gateway_id_codec_1");
66 ip_test(
"4500001c837e40004001360dc0a80001c0a80004", dccl_1);
68 ip_test(
"4500003e2fe8400040116d42c0a88e32c0a88e01", dccl_1);
70 ip_test(
"4500004cb803000038111b4d40712005c0a88e32", dccl_1);
72 std::cout <<
"all tests passed" << std::endl;
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
common::FlexOstream glog
Access the Goby logger through this object.
void add_stream(logger::Verbosity verbosity=logger::VERBOSE, std::ostream *os=0)
Attach a stream object (e.g. std::cout, std::ofstream, ...) to the logger with desired verbosity...