Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile Error on OS X Capitain #2

Open
eliabieri opened this issue Nov 11, 2015 · 13 comments
Open

Compile Error on OS X Capitain #2

eliabieri opened this issue Nov 11, 2015 · 13 comments

Comments

@eliabieri
Copy link

This is the error I get when I try to compile icmptunnel on OS X Capitain.

icmptunnel git:(master) make
gcc -c -o icmptunnel.o icmptunnel.c -I.
gcc -c -o icmp.o icmp.c -I.
icmp.c:22:29: warning: declaration of 'struct iphdr' will not be visible outside of this function [-Wvisibility]
void prepare_headers(struct iphdr *ip, struct icmphdr *icmp);
                            ^
icmp.c:22:47: warning: declaration of 'struct icmphdr' will not be visible outside of this function [-Wvisibility]
void prepare_headers(struct iphdr *ip, struct icmphdr *icmp);
                                              ^
icmp.c:100:3: warning: implicit declaration of function 'inet_pton' is invalid in C99 [-Wimplicit-function-declaration]
  inet_pton(AF_INET, packet_details->src_addr, &src_addr);
  ^
icmp.c:103:17: error: invalid application of 'sizeof' to an incomplete type 'struct iphdr'
  packet_size = sizeof(struct iphdr) + sizeof(struct icmphdr) + packet_details->payload_size;
                ^     ~~~~~~~~~~~~~~
icmp.c:91:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:103:40: error: invalid application of 'sizeof' to an incomplete type 'struct icmphdr'
  packet_size = sizeof(struct iphdr) + sizeof(struct icmphdr) + packet_details->payload_size;
                                       ^     ~~~~~~~~~~~~~~~~
icmp.c:92:10: note: forward declaration of 'struct icmphdr'
  struct icmphdr *icmp;
         ^
icmp.c:114:38: error: invalid application of 'sizeof' to an incomplete type 'struct iphdr'
  icmp = (struct icmphdr *)(packet + sizeof(struct iphdr));
                                     ^     ~~~~~~~~~~~~~~
icmp.c:91:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:115:36: error: invalid application of 'sizeof' to an incomplete type 'struct iphdr'
  icmp_payload = (char *)(packet + sizeof(struct iphdr) + sizeof(struct icmphdr));
                                   ^     ~~~~~~~~~~~~~~
icmp.c:91:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:115:59: error: invalid application of 'sizeof' to an incomplete type 'struct icmphdr'
  icmp_payload = (char *)(packet + sizeof(struct iphdr) + sizeof(struct icmphdr));
                                                          ^     ~~~~~~~~~~~~~~~~
icmp.c:92:10: note: forward declaration of 'struct icmphdr'
  struct icmphdr *icmp;
         ^
icmp.c:117:19: warning: incompatible pointer types passing 'struct iphdr *' to parameter of type 'struct iphdr *' [-Wincompatible-pointer-types]
  prepare_headers(ip, icmp);
                  ^~
icmp.c:22:36: note: passing argument to parameter 'ip' here
void prepare_headers(struct iphdr *ip, struct icmphdr *icmp);
                                   ^
icmp.c:117:23: warning: incompatible pointer types passing 'struct icmphdr *' to parameter of type 'struct icmphdr *' [-Wincompatible-pointer-types]
  prepare_headers(ip, icmp);
                      ^~~~
icmp.c:22:56: note: passing argument to parameter 'icmp' here
void prepare_headers(struct iphdr *ip, struct icmphdr *icmp);
                                                       ^
icmp.c:119:5: error: incomplete definition of type 'struct iphdr'
  ip->tot_len = htons(packet_size);
  ~~^
icmp.c:91:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:120:5: error: incomplete definition of type 'struct iphdr'
  ip->saddr = src_addr.s_addr;
  ~~^
icmp.c:91:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:121:5: error: incomplete definition of type 'struct iphdr'
  ip->daddr = dest_addr.s_addr;
  ~~^
icmp.c:91:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:125:7: error: incomplete definition of type 'struct icmphdr'
  icmp->type = packet_details->type;
  ~~~~^
icmp.c:92:10: note: forward declaration of 'struct icmphdr'
  struct icmphdr *icmp;
         ^
icmp.c:126:7: error: incomplete definition of type 'struct icmphdr'
  icmp->checksum = 0;
  ~~~~^
icmp.c:92:10: note: forward declaration of 'struct icmphdr'
  struct icmphdr *icmp;
         ^
icmp.c:127:7: error: incomplete definition of type 'struct icmphdr'
  icmp->checksum = in_cksum((unsigned short *)icmp, sizeof(struct icmphdr) + packet_details->payload_size);
  ~~~~^
icmp.c:92:10: note: forward declaration of 'struct icmphdr'
  struct icmphdr *icmp;
         ^
icmp.c:127:53: error: invalid application of 'sizeof' to an incomplete type 'struct icmphdr'
  icmp->checksum = in_cksum((unsigned short *)icmp, sizeof(struct icmphdr) + packet_details->payload_size);
                                                    ^     ~~~~~~~~~~~~~~~~
icmp.c:92:10: note: forward declaration of 'struct icmphdr'
  struct icmphdr *icmp;
         ^
icmp.c:162:83: warning: passing 'int *' to parameter of type 'socklen_t *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
  packet_size = recvfrom(sock_fd, packet, MTU, 0, (struct sockaddr *)&(src_addr), &src_addr_size);
                                                                                  ^~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/sys/socket.h:592:25: note: passing argument to parameter here
                socklen_t * __restrict) __DARWIN_ALIAS_C(recvfrom);
                                      ^
icmp.c:165:38: error: invalid application of 'sizeof' to an incomplete type 'struct iphdr'
  icmp = (struct icmphdr *)(packet + sizeof(struct iphdr));
                                     ^     ~~~~~~~~~~~~~~
icmp.c:147:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:166:36: error: invalid application of 'sizeof' to an incomplete type 'struct iphdr'
  icmp_payload = (char *)(packet + sizeof(struct iphdr) + sizeof(struct icmphdr));
                                   ^     ~~~~~~~~~~~~~~
icmp.c:147:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:166:59: error: invalid application of 'sizeof' to an incomplete type 'struct icmphdr'
  icmp_payload = (char *)(packet + sizeof(struct iphdr) + sizeof(struct icmphdr));
                                                          ^     ~~~~~~~~~~~~~~~~
icmp.c:148:10: note: forward declaration of 'struct icmphdr'
  struct icmphdr *icmp;
         ^
icmp.c:169:3: warning: implicit declaration of function 'inet_ntop' is invalid in C99 [-Wimplicit-function-declaration]
  inet_ntop(AF_INET, &(ip->saddr), packet_details->src_addr, INET_ADDRSTRLEN);
  ^
icmp.c:169:26: error: incomplete definition of type 'struct iphdr'
  inet_ntop(AF_INET, &(ip->saddr), packet_details->src_addr, INET_ADDRSTRLEN);
                       ~~^
icmp.c:147:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:170:26: error: incomplete definition of type 'struct iphdr'
  inet_ntop(AF_INET, &(ip->daddr), packet_details->dest_addr, INET_ADDRSTRLEN);
                       ~~^
icmp.c:147:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
icmp.c:171:30: error: incomplete definition of type 'struct icmphdr'
  packet_details->type = icmp->type;
                         ~~~~^
icmp.c:148:10: note: forward declaration of 'struct icmphdr'
  struct icmphdr *icmp;
         ^
icmp.c:172:48: error: invalid application of 'sizeof' to an incomplete type 'struct iphdr'
  packet_details->payload_size = packet_size - sizeof(struct iphdr) - sizeof(struct icmphdr);
                                               ^     ~~~~~~~~~~~~~~
icmp.c:147:10: note: forward declaration of 'struct iphdr'
  struct iphdr *ip;
         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
7 warnings and 20 errors generated.
make: *** [icmp.o] Error 1
@DhavalKapil
Copy link
Owner

The issue is probably with some header file. Presently it works fine on linux. Will look into it in some time

@JohnDDuncanIII
Copy link

For what it's worth, I also tried compiling this with gcc47 (sourced from pkg-src and installed on OS X 10.11.2) instead of clang and it still exited with errors

gcc -c -o icmptunnel.o icmptunnel.c -I.
gcc -c -o icmp.o icmp.c -I.
icmp.c:22:47: warning: 'struct icmphdr' declared inside parameter list [enabled by default]
icmp.c:22:47: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
icmp.c:22:47: warning: 'struct iphdr' declared inside parameter list [enabled by default]
icmp.c: In function 'send_icmp_packet':
icmp.c:103:24: error: invalid application of 'sizeof' to incomplete type 'struct iphdr'
icmp.c:103:47: error: invalid application of 'sizeof' to incomplete type 'struct icmphdr'
icmp.c:114:45: error: invalid application of 'sizeof' to incomplete type 'struct iphdr'
icmp.c:115:43: error: invalid application of 'sizeof' to incomplete type 'struct iphdr'
icmp.c:115:66: error: invalid application of 'sizeof' to incomplete type 'struct icmphdr'
icmp.c:117:3: warning: passing argument 1 of 'prepare_headers' from incompatible pointer type [enabled by default]
icmp.c:22:6: note: expected 'struct iphdr *' but argument is of type 'struct iphdr *'
icmp.c:117:3: warning: passing argument 2 of 'prepare_headers' from incompatible pointer type [enabled by default]
icmp.c:22:6: note: expected 'struct icmphdr *' but argument is of type 'struct icmphdr *'
icmp.c:119:5: error: dereferencing pointer to incomplete type
icmp.c:120:5: error: dereferencing pointer to incomplete type
icmp.c:121:5: error: dereferencing pointer to incomplete type
icmp.c:125:7: error: dereferencing pointer to incomplete type
icmp.c:126:7: error: dereferencing pointer to incomplete type
icmp.c:127:7: error: dereferencing pointer to incomplete type
icmp.c:127:60: error: invalid application of 'sizeof' to incomplete type 'struct icmphdr'
icmp.c: In function 'receive_icmp_packet':
icmp.c:165:45: error: invalid application of 'sizeof' to incomplete type 'struct iphdr'
icmp.c:166:43: error: invalid application of 'sizeof' to incomplete type 'struct iphdr'
icmp.c:166:66: error: invalid application of 'sizeof' to incomplete type 'struct icmphdr'
icmp.c:169:26: error: dereferencing pointer to incomplete type
icmp.c:170:26: error: dereferencing pointer to incomplete type
icmp.c:171:30: error: dereferencing pointer to incomplete type
icmp.c:172:55: error: invalid application of 'sizeof' to incomplete type 'struct iphdr'
icmp.c:172:78: error: invalid application of 'sizeof' to incomplete type 'struct icmphdr'
icmp.c: At top level:
icmp.c:220:47: warning: 'struct icmphdr' declared inside parameter list [enabled by default]
icmp.c:220:47: warning: 'struct iphdr' declared inside parameter list [enabled by default]
icmp.c:220:6: error: conflicting types for 'prepare_headers'
icmp.c:22:6: note: previous declaration of 'prepare_headers' was here
icmp.c: In function 'prepare_headers':
icmp.c:222:5: error: dereferencing pointer to incomplete type
icmp.c:223:5: error: dereferencing pointer to incomplete type
icmp.c:224:5: error: dereferencing pointer to incomplete type
icmp.c:225:5: error: dereferencing pointer to incomplete type
icmp.c:226:5: error: dereferencing pointer to incomplete type
icmp.c:227:5: error: dereferencing pointer to incomplete type
icmp.c:228:5: error: dereferencing pointer to incomplete type
icmp.c:230:7: error: dereferencing pointer to incomplete type
icmp.c:231:7: error: dereferencing pointer to incomplete type
icmp.c:232:7: error: dereferencing pointer to incomplete type
icmp.c:233:7: error: dereferencing pointer to incomplete type
make: *** [icmp.o] Error 1

running echo $? reveals that it exited with code 2. gcc version used is version 4.7.4 built and installed yesterday.

@DhavalKapil
Copy link
Owner

Perhapsstruct iphdr is defined differently/not defined in OS X. I'll have to define it myself.

I'm still searching for other solutions though.

@dotpot
Copy link

dotpot commented Nov 12, 2015

👍

@JohnDDuncanIII
Copy link

Yeah, I tried declaring the structs manually in the icmp.c file [struct iphdr{stuff}; , etc], which fixed the 'incomplete type' issues. I do agree that there is probably a more portable solution to the problem though.

@martinorob
Copy link

@JohnDDuncanIII may you explain how do you do it? Thanks

@qq42
Copy link

qq42 commented Feb 3, 2017

@martinorob An alternative ICMP tunnel implementation with a working OS X client is Hans:
http://code.gerade.org/hans/
https://github.com/friedrich/hans

@prologic
Copy link

prologic commented Apr 4, 2017

Any updates on this?

@DhavalKapil
Copy link
Owner

Not yet.

@green4984
Copy link

struct iphdr not exists on MacOS, use the define code below

#ifdef APPLE
#define iphdr ip
#endif

@BruceLEO1969
Copy link

Got the same issues

@BirkhoffLee
Copy link

Same here

@leonardoarroyo
Copy link

I'm having the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests