def create_tcpdump_line_v4()

in tools/tcpdump_encap_helper/tcpdump_encap_helper.py [0:0]


def create_tcpdump_line_v4(args, offset, encap_v6=False):
    """
     @param object args cli arguments
     @param int offset of internal header compare to external one
     @param bool encap_v6 flag to indicate that outer packet is ipv6
     @return None

     IP header format:
     0                   1                   2                   3
     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |Version|  IHL  |Type of Service|          Total Length         |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |         Identification        |Flags|      Fragment Offset    |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |  Time to Live |    Protocol   |         Header Checksum       |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                       Source Address                          |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                    Destination Address                        |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                    Options                    |    Padding    |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    """
    tcpdump_filters = []
    if args.src:
        tcpdump_filters = modify_filter(
            tcpdump_filters,
            ipv4_in_hex(args.src),
            offset + V4_SRC_OFFSET,
            V4_ADDR_SIZE,
            encap_v6,
        )
    if args.dst:
        tcpdump_filters = modify_filter(
            tcpdump_filters,
            ipv4_in_hex(args.dst),
            offset + V4_DST_OFFSET,
            V4_ADDR_SIZE,
            encap_v6,
        )
    if args.proto:
        tcpdump_filters = modify_filter(
            tcpdump_filters,
            args.proto,
            offset + V4_PROTO_OFFSET,
            PROTO_SIZE,
            encap_v6,
        )
    if args.sport:
        tcpdump_filters = modify_filter(
            tcpdump_filters,
            args.sport,
            offset + V4_HDR_SIZE + SPORT_OFFSET,
            PORT_SIZE,
            encap_v6,
        )
    if args.dport:
        tcpdump_filters = modify_filter(
            tcpdump_filters,
            args.dport,
            offset + V4_HDR_SIZE + DPORT_OFFSET,
            PORT_SIZE,
            encap_v6,
        )
    print('"(' + " and ".join(tcpdump_filters) + ')"')