예제 #1
0
void
pktgen_page_seq(uint32_t pid)
{
    uint32_t    i, row, col;
    port_info_t * info;
    pkt_seq_t   * pkt;
    char buff[64];

    display_topline("** Sequence Page **");

    info = &pktgen.info[pid];

    row = PORT_STATE_ROW;
    col = 1;
    wr_scrn_printf(row++, col, "Port: %2d, Sequence Count: %2d of %2d  ", pid, info->seqCnt, NUM_SEQ_PKTS);
    wr_scrn_printf(row++, col, "%*s %*s%*s%*s%*s%*s%*s%*s",
            6, "Seq:",
            COLUMN_WIDTH_0, "Dst MAC",
            COLUMN_WIDTH_0, "Src MAC",
            COLUMN_WIDTH_0, "Dst IP",
            COLUMN_WIDTH_0+2, "Src IP",
            12, "Port S/D",
            15, "Protocol:VLAN",
            5, "Size");
    for(i = 0; i < NUM_SEQ_PKTS; i++) {
        col = 1;
        pkt = &info->seq_pkt[i];

        if ( i >= info->seqCnt ) {
        	wr_scrn_eol_pos(row++, col);
        	continue;
        }

        wr_scrn_printf(row, col, "%5d:", i);
        col += 7;
        wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_mtoa(buff, sizeof(buff), &pkt->eth_dst_addr));
        col += COLUMN_WIDTH_1;
        wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_mtoa(buff, sizeof(buff), &pkt->eth_src_addr));
        col += COLUMN_WIDTH_1;
        wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_dst_addr), 0xFFFFFFFF));
        col += COLUMN_WIDTH_1;
        wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1+2, inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_src_addr), pkt->ip_mask));
        col += COLUMN_WIDTH_1+2;

        snprintf(buff, sizeof(buff), "%d/%d", pkt->sport, pkt->dport);
        wr_scrn_printf(row, col, "%*s", 12, buff);
        col += 12;
        snprintf(buff, sizeof(buff), "%s/%s:%04x", (pkt->ethType == ETHER_TYPE_IPv4)? "IPv4" :
                                                      (pkt->ethType == ETHER_TYPE_IPv6)? "IPv6" : "Other",
                                                      (pkt->ipProto == PG_IPPROTO_TCP)? "TCP" :
                                                      (pkt->ipProto == PG_IPPROTO_ICMP)? "ICMP" : "UDP",
                                                    		  pkt->vlanid);
        wr_scrn_printf(row, col, "%*s", 15, buff);
        col += 15;
        wr_scrn_printf(row, col, "%5d", pkt->pktSize+FCS_SIZE);
        row++;
    }

    display_dashline(row+2);
}
예제 #2
0
static void
pktgen_print_pcap(uint16_t pid)
{
	uint32_t i, row, col, max_pkts, len;
	uint16_t type, vlan, skip;
	uint8_t proto;
	port_info_t *info;
	pkt_hdr_t   *hdr;
	pcap_info_t *pcap;
	pcaprec_hdr_t pcap_hdr;
	char buff[64];
	char pkt_buff[2048];

	display_topline("<PCAP Page>");
	wr_scrn_printf(1, 3, "Port %d of %d", pid, pktgen.nb_ports);

	info = &pktgen.info[pid];
	pcap = info->pcap;

	row = PORT_STATE_ROW;
	col = 1;
	if (pcap == NULL) {
		wr_scrn_center(10, pktgen.scrn->ncols, "** Port does not have a PCAP file assigned **");
		row = 28;
		goto leave;
	}

	wr_scrn_eol_pos(row, col);
	wr_scrn_printf(row++, col, "Port: %d, PCAP Count: %d of %d",
	               pid, pcap->pkt_idx, pcap->pkt_count);
	wr_scrn_printf(row++, col, "%*s %*s%*s%*s%*s%*s%*s%*s",
	               5, "Seq",
	               COLUMN_WIDTH_0, "Dst MAC",
	               COLUMN_WIDTH_0, "Src MAC",
	               COLUMN_WIDTH_0, "Dst IP",
	               COLUMN_WIDTH_0 + 2, "Src IP",
	               12, "Port S/D",
	               15, "Protocol:VLAN",
	               9, "Size-FCS");

	max_pkts = pcap->pkt_idx + PCAP_PAGE_SIZE;
	if (max_pkts > pcap->pkt_count)
		max_pkts = pcap->pkt_count;

	wr_pcap_skip(pcap, pcap->pkt_idx);

	for (i = pcap->pkt_idx; i < max_pkts; i++) {
		col = 1;
		skip = 0;

		len = wr_pcap_read(pcap, &pcap_hdr, pkt_buff, sizeof(pkt_buff));
		if (len == 0)
			break;

		/* Skip any jumbo packets larger then buffer. */
		if (pcap_hdr.incl_len > sizeof(pkt_buff) ) {
			i--;
			skip++;
		}
		/* Skip packets that are not normal IP packets. */
		type = ntohs( ((uint16_t *)pkt_buff)[6]);
		if (unlikely(type == ETHER_TYPE_VLAN) )
			type = ntohs( ((uint16_t *)pkt_buff)[8]);

		if (unlikely(type < MAX_ETHER_TYPE_SIZE) )
			skip++;

		hdr = (pkt_hdr_t *)&pkt_buff[0];

		wr_scrn_eol_pos(row, col);

		wr_scrn_printf(row, col, "%5d:", i);
		col += 7;
		wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_mtoa(buff, sizeof(buff), &hdr->eth.d_addr));
		col += COLUMN_WIDTH_1;
		wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_mtoa(buff, sizeof(buff), &hdr->eth.s_addr));
		col += COLUMN_WIDTH_1;

		type = ntohs(hdr->eth.ether_type);
		proto = hdr->u.ipv4.proto;
		vlan = 0;
		if (type == ETHER_TYPE_VLAN) {
			vlan = ntohs( ((uint16_t *)&hdr->eth.ether_type)[1]);
			type = ntohs( ((uint16_t *)&hdr->eth.ether_type)[2]);
			proto = ((ipHdr_t *)((char *)&hdr->u.ipv4 + 4))->proto;
		}

		if (type == ETHER_TYPE_IPv4) {
			wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_ntop4(buff, sizeof(buff), hdr->u.ipv4.dst, 0xFFFFFFFF));
			col += COLUMN_WIDTH_1;
			wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1 + 2, inet_ntop4(buff, sizeof(buff), hdr->u.ipv4.src, 0xFFFFFFFF));
			col += COLUMN_WIDTH_1 + 2;

			snprintf(buff, sizeof(buff), "%d/%d", ntohs(hdr->u.uip.udp.sport), ntohs(hdr->u.uip.udp.dport));
			wr_scrn_printf(row, col, "%*s", 12, buff);
			col += 12;
		} else {
			skip++;
			col += ((2 * COLUMN_WIDTH_1) + 2 + 12);
		}
		snprintf(buff, sizeof(buff), "%s/%s:%4d", (type == ETHER_TYPE_IPv4) ? "IPv4" :
		         (type == ETHER_TYPE_IPv6) ? "IPv6" : "Other",
		         (type == PG_IPPROTO_TCP) ? "TCP" :
		         (proto == PG_IPPROTO_ICMP) ? "ICMP" : "UDP",
		         (vlan & 0xFFF));
		wr_scrn_printf(row, col, "%*s", 15, buff);
		col += 15;
		wr_scrn_printf(row, col, "%5d", len);

		if (skip && (type < ETHER_TYPE_IPv4) )
			wr_scrn_printf(row, col + 7, "<<< Skip %04x", type);
		else if (skip && (type != ETHER_TYPE_IPv4) )
			wr_scrn_printf(row, col + 7, " EthType %04x", type);
		row++;
	}
leave:
	display_dashline(row + 2);

	pktgen.flags &= ~PRINT_LABELS_FLAG;
}