void *append_ipv4_frag2( void *buf, char *srcip, char *dstip, unsigned char protocol, unsigned short fragid, unsigned short payload_length ) { struct ip *iph = buf; append_ipv4( iph, srcip, dstip, protocol ); iph->ip_off = htons( 1 ); iph->ip_id = htons( fragid ); iph->ip_len = htons( SIZEOF_IPV4 + payload_length ); return (char *) iph + SIZEOF_IPV4; }
void *append_ipv4_short_frag1( void *buf, char *srcip, char *dstip, unsigned char protocol, unsigned short fragid ) { struct ip *iph = buf; append_ipv4( iph, srcip, dstip, protocol ); iph->ip_off = htons( 1 << IP_FLAGS_OFFSET ); /* Set More Fragments (MF) bit */ iph->ip_id = htons( fragid ); iph->ip_len = htons( SIZEOF_IPV4 + MINIMUM_FRAGMENT_SIZE ); return (char *)iph + SIZEOF_IPV4; }
void *append_ipv4_optioned_frag1( void *buf, char *srcip, char *dstip, unsigned char protocol, unsigned short fragid, unsigned short optlen ) { struct ip *iph = buf; append_ipv4( iph, srcip, dstip, protocol ); iph->ip_off = htons( 1 << IP_FLAGS_OFFSET ); /* Set More Fragments (MF) bit */ iph->ip_id = htons( fragid ); iph->ip_len = htons( SIZEOF_IPV4 + optlen + MINIMUM_FRAGMENT_SIZE ); if ( optlen % 4 != 0 ) errx( 1, "optlen must be a multiple of 4" ); iph->ip_hl = 5 + ( optlen / 4 ); /* Pad with NOP's and then end-of-padding option. */ memset( (char *) iph + SIZEOF_IPV4, 0x01, optlen ); *( (char *) iph + SIZEOF_IPV4 + optlen ) = 0; return (char *) iph + SIZEOF_IPV4 + optlen; }
bool test_embed_ipv4_in_ipv6( void ) { struct in_addr embeddable4; struct in6_addr embed6; struct in6_addr embedded6; bool success = true; if (pool6_init(NULL, 9) != 0) return false; success &= str_to_addr4_verbose(IPV4_EMBEDDABLE_ADDR, &embeddable4); success &= str_to_addr6_verbose(IPV6_EMBEDDED_ADDR, &embedded6); success &= assert_true(append_ipv4( &embeddable4, &embed6 ) , "Check that we can embed an IPv4 address inside of an IPv6 address correctly."); success &= assert_equals_ipv6( &embed6 , &embedded6 , "Verify that the IPv4 was embedded into a IPv6 address is correct."); return success; }