Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Helper to build an IP header given the source host address (sha), target
- * host address (tha), and the desired TTL. The header is created where
- * iphdr points to.
- */
- void
- buildIpHeader(struct iphdr * iphdr, struct in_addr * sha, struct in_addr * tha,
- u_int8_t ttl) {
- /* ==================================================================== *
- * YOUR TASK *
- * Build an IP Header *
- * ==================================================================== */
- iphdr->version = 4;
- iphdr->ihl = 5;
- iphdr->tos = 0;
- iphdr->tot_len = htons(28);
- iphdr->id = htons(rand());
- iphdr->frag_off = htons(0);
- iphdr->ttl = ttl;
- iphdr->protocol = IPPROTO_ICMP;
- iphdr->saddr = sha->s_addr;
- iphdr->daddr = tha->s_addr;
- iphdr->check = in_cksum( (u_int16_t *)iphdr, sizeof(struct iphdr));
- /* TASK END.
- * ==================================================================== */
- }
- /**
- * Helper to create an ICMP Echo Request (type 8, code 0) whith given Id
- * and sequence number. The header is created where icmphdr points to.
- */
- void
- buildIcmpEchoRequest(struct icmphdr * icmphdr, u_int16_t id, u_int16_t seq) {
- /* ==================================================================== *
- * YOUR TASK *
- * Build an ICMP Echo Request Header. *
- * ==================================================================== */
- icmphdr->type = 8;
- icmphdr->code = 0;
- icmphdr->un.echo.id = htons(id);
- icmphdr->un.echo.sequence = htons(seq);
- icmphdr->checksum = in_cksum((u_int16_t *)icmphdr, sizeof(struct icmphdr));
- /* TASK END.
- * ==================================================================== */
- }
Add Comment
Please, Sign In to add comment