How-To parse IP headers
A slightly more esoteric topic when it comes to IPv4 and IPv6 networking is to parse respective address types from IP packet headers. However, it may come in handy when e.g. using UDP sockets that are not bound to any particular corresponding peer address.
Parse an IPv4 or IPv6 packet header
1#include <liberate/net/ip.h>
2
3using namespace liberate::net;
4socket_address src;
5socket_address dest;
6
7auto res = parse_addresses(src, dest, ip_buffer, ip_buffer_size);
The function returns false if parsing failed, true otherwise. As a side
effect of the function, the type()
of the returned addresses also tells you
the type of IP packet/header.
See also