Thread: simple error or strange compiler?

  1. #1
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214

    simple error or strange compiler?

    i guess its the fromer one.

    Code:
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netdb.h>
    #include <netinet/in.h>
    
    int main ()
    {
        struct iphdr *ip;
        
        ip = (struct iphdr *) malloc(sizeof(struct iphdr));
        
        ip->ihl = 5;
        ip->version = 4;
        ip->tos = 0;
        ip->tot_len = sizeof(struct iphdr) + 452;
        ip->id = htons(getuid());
        ip->ttl = 255;
        ip->protocol = IPPROTO_TCP;
        ip->saddr = inet_addr("127.0.0.1");
        ip->daddr = inet_addr("127.0.0.1");
        ip->check = in_cksum((unsigned short *)ip; sizeof(struct iphdr));
        
        return 0;
    }
    i am getting a strange error:
    "dereferencing pointer to an incomplete type."

    is there something wrong with my pointer?
    or what else?

    thank you

    cya

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >ip->check = in_cksum((unsigned short *)ip; sizeof(struct iphdr));

    Read this line carefully.

  3. #3
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    the pointer ip points to the check element in the iphdr structure.
    i dont know what you mean, because i dont see a syntax error or
    something like that.
    my whole code is not correct.

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    In the line I mentioned, there is a ; which I think should not be there.

  5. #5
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    thanks i am really blind!

    but the following error keeps persisting from line 13 to 22:
    "dereferencing pointer to incomplete type"

    what is wrong with my pointers?
    anyone? thanks

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by threahdead

    but the following error keeps persisting from line 13 to 22:
    "dereferencing pointer to incomplete type"
    It means it doesn't know what a struct iphdr looks like. Have you included all the correct header files?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    i forgot about #include <linux/ip.h>.
    so that is fixed and my packet ready for takeoff .

    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Socialising Chat Bots
    By bengreenwood in forum C++ Programming
    Replies: 10
    Last Post: 11-28-2007, 08:42 AM
  2. Reading game port with a simple compiler like BuilderX?
    By MaxxMan-X in forum Game Programming
    Replies: 7
    Last Post: 02-27-2005, 11:15 AM
  3. Compiler questions
    By DvdHeijden in forum C++ Programming
    Replies: 6
    Last Post: 01-17-2005, 03:00 PM
  4. Dev C++ Compiler, Indentation?
    By Zeusbwr in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2004, 06:13 AM
  5. lcc win32 compiler download problems
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-01-2004, 07:39 PM