Need help getting a linux code to run

Posted:
in Genius Bar edited January 2014
This is for a class I'm talking and so far I got all the other code running (note: the code was given to me by my professor) its for a sniffer and it needs to use the BSD sockets which I know Tiger has and I located every header file but for some reason I get a ton of errors and from what I have researched there usually associated with missing header files. I would like to know if anyone who has the knowledge to figure out these errors and how I can fix them.



Heres more info on the code, it was designed around Fedora and its a sniffer / injector (its for Ethical Hacking class FYI) the problem I'm having is when trying to make the file (the makefile has no errors, that we know of) I get all these errors.



Quote:

Project #1/snifferv3 root# make

gcc -g -c -o sniffer3.o sniffer3.c

sniffer3.c: In function 'main':

sniffer3.c:10: error: 'PF_PACKET' undeclared (first use in this function)

sniffer3.c:10: error: (Each undeclared identifier is reported only once

sniffer3.c:10: error: for each function it appears in.)

sniffer3.c:10: error: 'ETH_P_IP' undeclared (first use in this function)

sniffer3.c:24: error: invalid application of 'sizeof' to incomplete type 'struct iphdr'

sniffer3.c:35: error: dereferencing pointer to incomplete type

sniffer3.c: In function 'print_ip_header':

sniffer3.c:56: error: dereferencing pointer to incomplete type

sniffer3.c:58: error: dereferencing pointer to incomplete type

sniffer3.c:60: error: dereferencing pointer to incomplete type

sniffer3.c:60: error: dereferencing pointer to incomplete type

sniffer3.c:61: error: dereferencing pointer to incomplete type

sniffer3.c:61: error: dereferencing pointer to incomplete type

sniffer3.c:61: error: dereferencing pointer to incomplete type

sniffer3.c:61: error: dereferencing pointer to incomplete type

sniffer3.c:61: error: dereferencing pointer to incomplete type

sniffer3.c:61: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c:62: error: dereferencing pointer to incomplete type

sniffer3.c: In function 'print_tcp_header':

sniffer3.c:70: error: 'struct tcphdr' has no member named 'source'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'source'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'source'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'source'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'dest'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'dest'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'dest'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'dest'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'ack_seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'ack_seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'ack_seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'ack_seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'ack_seq'

sniffer3.c:70: error: 'struct tcphdr' has no member named 'ack_seq'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'window'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'window'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'window'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'window'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'check'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'check'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'check'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'check'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'urg_ptr'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'urg_ptr'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'urg_ptr'

sniffer3.c:71: error: 'struct tcphdr' has no member named 'urg_ptr'

sniffer3.c:73: error: 'struct tcphdr' has no member named 'syn'

sniffer3.c:74: error: 'struct tcphdr' has no member named 'rst'

sniffer3.c:75: error: 'struct tcphdr' has no member named 'ack'

sniffer3.c:76: error: 'struct tcphdr' has no member named 'psh'

sniffer3.c:77: error: 'struct tcphdr' has no member named 'fin'

sniffer3.c:78: error: 'struct tcphdr' has no member named 'urg'

make: *** [sniffer3.o] Error 1



Makefile



Quote:

# LLamada al compilador

CC = gcc -g



all: sniffer3 inject



# LLamada al Linker

sniffer: sniffer3.o

\t$(CC) sniffer3.o -o sniffer3



# LLamada al Linker

inject: inject.o

\t$(CC) inject.o -o inject



# Compiler call

sniffer.o: sniffer3.c

\t$(CC) -c sniffer3.c



# Compiler call

inject.o: inject.c

\t$(CC) -c inject.c



If anyone needs the actual code of the sniffer and injector I will gladly send it to the person who would like to try and help me, thanks for your time and patience. Also if anyone has questions and or comments let me know.



Thanks Allen

Comments

  • Reply 1 of 1
    MarvinMarvin Posts: 15,355moderator
    The code looks like it's written differently on OS X. The only tcphdr struct looks like this:



    struct tcphdr {

    \tunsigned short\tth_sport;\t/* source port */

    \tunsigned short\tth_dport;\t/* destination port */

    \ttcp_seq\tth_seq;\t\t\t/* sequence number */

    \ttcp_seq\tth_ack;\t\t\t/* acknowledgement number */

    #if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN

    \tunsigned int\tth_x2:4,\t/* (unused) */

    \t\t\tth_off:4;\t/* data offset */

    #endif

    #if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN

    \tunsigned int\tth_off:4,\t/* data offset */

    \t\t\tth_x2:4;\t/* (unused) */

    #endif

    \tunsigned char\tth_flags;

    #define\tTH_FIN\t0x01

    #define\tTH_SYN\t0x02

    #define\tTH_RST\t0x04

    #define\tTH_PUSH\t0x08

    #define\tTH_ACK\t0x10

    #define\tTH_URG\t0x20

    #define\tTH_ECE\t0x40

    #define\tTH_CWR\t0x80

    #define\tTH_FLAGS\t(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH _URG|TH_ECE|TH_CWR)



    \tunsigned short\tth_win;\t\t/* window */

    \tunsigned short\tth_sum;\t\t/* checksum */

    \tunsigned short\tth_urp;\t\t/* urgent pointer */

    };



    Maybe you need to rename some objects to their equivalent so seq changes th_seq.



    You can find the location of these code objects using fgrep btw. In the terminal, this command:



    fgrep -i -r "tcphdr" /System/Library/Frameworks/



    will recursively (-r) search case insensitively (-i) for the string tcphdr throughout the entire Frameworks folder file contents. It's pretty quick. You will find the code in there and in /usr/include. The Frameworks often just point to code in /usr/include. Couldn't find a definition for PF_PACKET though.
Sign In or Register to comment.