#include #include #include #define PKTBUFSRX 4 #define PKTSIZE_ALIGN 1536 #define PKTALIGN 16 #define ETH_HDR_SIZE 14 #define IP_HDR_SIZE 20 #define IP_FLAGS_DFRAG 0x4000 static uint8_t net_pkt_buf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN]; static unsigned net_ip_id; /* * Internet Protocol (IP) + UDP header. */ struct ip_udp_hdr { uint8_t ip_hl_v; /* header length and version */ uint8_t ip_tos; /* type of service */ uint16_t ip_len; /* total length */ uint16_t ip_id; /* identification */ uint16_t ip_off; /* fragment offset field */ uint8_t ip_ttl; /* time to live */ uint8_t ip_p; /* protocol */ uint16_t ip_sum; /* checksum */ struct in_addr ip_src; /* Source IP address */ struct in_addr ip_dst; /* Destination IP address */ }; void net_set_ip_header(uint8_t *pkt, struct in_addr dest, struct in_addr source) { struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt; /* * Construct an IP header. */ ip->ip_hl_v = 0x45; //asm("nop"); ip->ip_tos = 0; ip->ip_len = htons(IP_HDR_SIZE); ip->ip_id = htons(net_ip_id++); ip->ip_off = htons(IP_FLAGS_DFRAG); /* Don't fragment */ ip->ip_ttl = 255; ip->ip_sum = 0; /* already in network byte order */ memcpy((void *)&ip->ip_src, &source, sizeof(struct in_addr)); /* already in network byte order */ memcpy((void *)&ip->ip_dst, &dest, sizeof(struct in_addr)); } int main(int argc, char** argv) { uint8_t *pkt; struct in_addr bcast_ip, src_ip; bcast_ip.s_addr = 0xFFFFFFFFL; src_ip.s_addr = 0x0L; pkt = net_pkt_buf; memset((void *)pkt, 0, sizeof(net_pkt_buf)); pkt += ETH_HDR_SIZE; net_set_ip_header(pkt, bcast_ip, src_ip); return 1; }