Exemple #1
0
void reply_payload(tw_rx_t * handle, tw_buf_t * buffer) {
    struct ether_addr * dst_eth_addr;
    struct ether_hdr * eth = buffer->data;
    struct arp_hdr * arp_pkt =buffer->data + sizeof(struct ether_hdr);

    switch (tw_be_to_cpu_16(eth->ether_type)) {
        case ETHER_TYPE_ARP:
            if (arp_flag == 1) {
                tw_arp_parser(buffer, "tw0");
                struct ether_addr * mac_addr = tw_search_arp_entry(ip);
                if (mac_addr != NULL) {
                    dst_eth_addr =  mac_addr;
                    printf("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
                            dst_eth_addr->addr_bytes[0],
                            dst_eth_addr->addr_bytes[1],
                            dst_eth_addr->addr_bytes[2],
                            dst_eth_addr->addr_bytes[3],
                            dst_eth_addr->addr_bytes[4],
                            dst_eth_addr->addr_bytes[5]);
                    arp_flag = -1;
                    exit(0);
                }
            }
    }
    tw_free_pkt(buffer);

}
Exemple #2
0
void reply_udp_payload(tw_rx_t * handle, tw_buf_t * buffer) {
    eth = buffer->data;
    eth_type = tw_be_to_cpu_16(eth->ether_type);
        switch (eth_type) {
            case ETHER_TYPE_ARP:
                tw_arp_parser(buffer, "tw0");
                break;
            case ETHER_TYPE_IPv4:
                ipHdr_d = buffer->data + sizeof(struct ether_hdr);
                dst_ip  = (ipHdr_d->dst_addr);
                src_ip = (ipHdr_d->src_addr);
                ipHdr_d->dst_addr = (src_ip);
                ipHdr_d->src_addr = (dst_ip);
                ipHdr_d->hdr_checksum = tw_ipv4_cksum(ipHdr_d);

                udp_hdr_d = (struct udp_hdr *)ipHdr_d + sizeof(struct ipv4_hdr);
                dst_port = (udp_hdr_d->dst_port);
                src_port = (udp_hdr_d->src_port);
                udp_hdr_d->dst_port = (src_port);
                udp_hdr_d->src_port = (dst_port);
                udp_hdr_d->dgram_cksum = 0;

                tw_copy_ether_addr(&(eth->s_addr), &(eth->d_addr));
                tw_copy_ether_addr(dst_eth, &(eth->s_addr));
                tw_send_pkt(buffer, "tw0");
                break;
                
        }
 
}
Exemple #3
0
void pkt_rx(tw_rx_t * handle, tw_buf_t * buffer) {
    eth = buffer->data;
    if(tw_be_to_cpu_16(eth->ether_type) == ETHER_TYPE_ARP) {
        global_stats_option.pkts_rx--;
        tw_arp_parser(buffer, "tw0");
    }
    tw_free_pkt(buffer);
    return;
}
Exemple #4
0
/* reply_udp_payload acts as udp server; switches the IP and ports, mac addresses and echoes back the packet to sender*/
void reply_udp_payload(tw_rx_t * handle, tw_buf_t * buffer)
{
    test_stats.datagrams_recv++;
    eth = buffer->data;
    eth_type = tw_be_to_cpu_16(eth->ether_type);
    ipHdr_d = buffer->data + sizeof(struct ether_hdr);
    dst_ip = (ipHdr_d->dst_addr);
    src_ip = (ipHdr_d->src_addr);
    ipHdr_d->dst_addr = (src_ip);
    ipHdr_d->src_addr = (dst_ip);
    ipHdr_d->hdr_checksum = tw_ipv4_cksum(ipHdr_d);
    udp_hdr_d = (struct udp_hdr *) ipHdr_d + sizeof(struct ipv4_hdr);
    dst_port = (udp_hdr_d->dst_port);
    src_port = (udp_hdr_d->src_port);
    udp_hdr_d->dst_port = (src_port);
    udp_hdr_d->src_port = (dst_port);
    udp_hdr_d->dgram_cksum = 0;
    tw_copy_ether_addr(&(eth->s_addr), &(eth->d_addr));
    tw_copy_ether_addr(test.server_mac, &(eth->s_addr));
    tw_send_pkt(buffer, "tw0");
    test_stats.datagrams_sent++;
}