The following code
int tcp_seg_len_ipv4(packets *pkts, int pkt_idx) {
struct rte_ipv4_hdr *ip_hdr = (struct rte_ipv4_hdr *)pkts->data[pkt_idx];
struct rte_tcp_hdr *tcp_hdr = (struct rte_tcp_hdr *)(ip_hdr + 1);
int ipHdrLen = (ip_hdr->version_ihl & 0x0f) << 2;
int tcpHdrLen = (tcp_hdr->data_off & 0xf0) >> 2;
int totalLength = ntohs(ip_hdr->total_length);
return totalLength - ipHdrLen - tcpHdrLen;
}
calculates TCP segment length for ipv4 packets. Its result is right. I’m not sure whether there’s a better and more efficient way for this. But now I need to calculate it for ipv6. Would you give me the code in C?
Thanks