int innitialize_generator_packet(struct pkt_details *state, struct traf_gen_det *det) { state->data = (void *)malloc(det->pkt_size); state->data_len = det->pkt_size; bzero((void *)state->data, state->data_len); if(state->data_len < sizeof(struct ether_vlan_header) + sizeof(struct iphdr) + sizeof(struct tcphdr)) { printf("packet size is too small\n"); return 0; } //ethernet header with default values state->eth_vlan = (struct ether_vlan_header *) state->data; state->eth = (struct ether_header *) state->data; read_mac_addr(state->eth_vlan->ether_dhost, det->mac_dst); read_mac_addr(state->eth_vlan->ether_shost, det->mac_src); if(det->vlan != 0 && det->vlan != 0xffff) { state->eth_vlan->tpid = htons(0x8100); state->eth_vlan->vid = htons(det->vlan) >>4; state->eth_vlan->ether_type = htons(ETHERTYPE_IP); state->ip = (struct iphdr *)(state->data + sizeof(struct ether_vlan_header)); state->ip->tot_len=htons(state->data_len - sizeof(struct ether_vlan_header)); state->udp = (struct udphdr *) (state->data + sizeof(struct ether_vlan_header) + sizeof(struct iphdr)); state->udp->len = htons(state->data_len - sizeof(struct ether_vlan_header) - sizeof(struct iphdr)); state->pktgen = (struct pktgen_hdr *) (state->data + sizeof(struct ether_vlan_header) + sizeof(struct iphdr) + sizeof(struct udphdr)); } else {
int zd_read_mac_addr(struct zd_chip *chip, u8 *mac_addr) { int r; dev_dbg_f(zd_chip_dev(chip), "\n"); mutex_lock(&chip->mutex); r = read_mac_addr(chip, mac_addr); mutex_unlock(&chip->mutex); return r; }