Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- udp_orig.c 2018-01-18 14:17:00.219413603 +0000
- +++ udp.c 2018-01-18 16:03:21.633650570 +0000
- @@ -1,20 +1,25 @@
- -#include <unistd.h>
- #include <stdio.h>
- +#include <stdlib.h>
- +#include <string.h>
- +#include <unistd.h>
- #include <sys/socket.h>
- +#include <arpa/inet.h>
- +#include <netinet/in.h>
- #include <netinet/ip.h>
- #include <netinet/udp.h>
- // The packet length
- #define PCKT_LEN 8192
- +#pragma pack(push, 1)
- +
- // Can create separate header file (.h) for all headers' structure
- // The IP header's structure
- struct ipheader {
- - unsigned char iph_ihl:5, iph_ver:4;
- + unsigned char iph_ihl:4, iph_ver:4;
- unsigned char iph_tos;
- unsigned short int iph_len;
- unsigned short int iph_ident;
- - unsigned char iph_flag;
- unsigned short int iph_offset;
- unsigned char iph_ttl;
- unsigned char iph_protocol;
- @@ -31,6 +36,8 @@
- unsigned short int udph_chksum;
- };
- +#pragma pack(pop)
- +
- // total udp header length: 8 bytes (=64 bits)
- // Function for checksum calculation. From the RFC,
- // the checksum algorithm is:
- @@ -98,7 +105,7 @@
- ip->iph_ihl = 5;
- ip->iph_ver = 4;
- ip->iph_tos = 16; // Low delay
- -ip->iph_len = sizeof(struct ipheader) + sizeof(struct udpheader);
- +ip->iph_len = htons(sizeof(struct ipheader) + sizeof(struct udpheader));
- ip->iph_ident = htons(54321);
- ip->iph_ttl = 64; // hops
- ip->iph_protocol = 17; // UDP
- @@ -117,7 +124,7 @@
- udp->udph_len = htons(sizeof(struct udpheader));
- // Calculate the checksum for integrity
- -ip->iph_chksum = csum((unsigned short *)buffer, sizeof(struct ipheader) + sizeof(struct udpheader));
- +ip->iph_chksum = htons(csum((unsigned short *)buffer, sizeof(struct ipheader) + sizeof(struct udpheader)));
- // Inform the kernel do not fill up the packet structure. we will build our own...
- if(setsockopt(sd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement