Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.89 KB | None | 0 0
  1. --- udp_orig.c  2018-01-18 14:17:00.219413603 +0000
  2. +++ udp.c   2018-01-18 16:03:21.633650570 +0000
  3. @@ -1,20 +1,25 @@
  4. -#include <unistd.h>
  5.  #include <stdio.h>
  6. +#include <stdlib.h>
  7. +#include <string.h>
  8. +#include <unistd.h>
  9.  #include <sys/socket.h>
  10. +#include <arpa/inet.h>
  11. +#include <netinet/in.h>
  12.  #include <netinet/ip.h>
  13.  #include <netinet/udp.h>
  14.  
  15.  // The packet length
  16.  #define PCKT_LEN 8192
  17.  
  18. +#pragma pack(push, 1)
  19. +
  20.  // Can create separate header file (.h) for all headers' structure
  21.  // The IP header's structure
  22.  struct ipheader {
  23. -    unsigned char      iph_ihl:5, iph_ver:4;
  24. +    unsigned char      iph_ihl:4, iph_ver:4;
  25.      unsigned char      iph_tos;
  26.      unsigned short int iph_len;
  27.      unsigned short int iph_ident;
  28. -    unsigned char      iph_flag;
  29.      unsigned short int iph_offset;
  30.      unsigned char      iph_ttl;
  31.      unsigned char      iph_protocol;
  32. @@ -31,6 +36,8 @@
  33.      unsigned short int udph_chksum;
  34.  };
  35.  
  36. +#pragma pack(pop)
  37. +
  38.  // total udp header length: 8 bytes (=64 bits)
  39.  // Function for checksum calculation. From the RFC,
  40.  // the checksum algorithm is:
  41. @@ -98,7 +105,7 @@
  42.  ip->iph_ihl = 5;
  43.  ip->iph_ver = 4;
  44.  ip->iph_tos = 16; // Low delay
  45. -ip->iph_len = sizeof(struct ipheader) + sizeof(struct udpheader);
  46. +ip->iph_len = htons(sizeof(struct ipheader) + sizeof(struct udpheader));
  47.  ip->iph_ident = htons(54321);
  48.  ip->iph_ttl = 64; // hops
  49.  ip->iph_protocol = 17; // UDP
  50. @@ -117,7 +124,7 @@
  51.  udp->udph_len = htons(sizeof(struct udpheader));
  52.  
  53.  // Calculate the checksum for integrity
  54. -ip->iph_chksum = csum((unsigned short *)buffer, sizeof(struct ipheader) + sizeof(struct udpheader));
  55. +ip->iph_chksum = htons(csum((unsigned short *)buffer, sizeof(struct ipheader) + sizeof(struct udpheader)));
  56.  
  57.  // Inform the kernel do not fill up the packet structure. we will build our own...
  58.  if(setsockopt(sd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement