// Fill in IP header
iph->ip_v = 4; // IPv4
iph->ip_hl = IP_HEADER_SIZE / 4; // Header length in 32-bit words
iph->ip_tos = 0; // Default Type of Service
iph->ip_len = htons(IP_HEADER_SIZE + TCP_HEADER_SIZE); // Total length of the packet
iph->ip_id = 0; // Identification (random value or 0)
iph->ip_off = 0; // Fragment offset
iph->ip_ttl = 255; // Time to Live
iph->ip_p = IPPROTO_TCP; // Protocol (TCP)
iph->ip_src.s_addr = src.sin_addr.s_addr; // Source IP address
iph->ip_dst.s_addr = dst.sin_addr.s_addr; // Destination IP address
// Calculate IP header checksum
calculate_ip_checksum(iph);
that's how i build the IP headers.