icmptunnel icon indicating copy to clipboard operation
icmptunnel copied to clipboard

Compile Error on OS X Capitain

Open eliabieri opened this issue 8 years ago • 13 comments

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

eliabieri avatar Nov 11 '15 19:11 eliabieri

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

DhavalKapil avatar Nov 11 '15 20:11 DhavalKapil

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.

JohnDDuncanIII avatar Nov 12 '15 04:11 JohnDDuncanIII

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.

DhavalKapil avatar Nov 12 '15 09:11 DhavalKapil

:+1:

dotpot avatar Nov 12 '15 10:11 dotpot

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.

JohnDDuncanIII avatar Nov 12 '15 20:11 JohnDDuncanIII

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

martinorob avatar Nov 18 '15 18:11 martinorob

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

qq42 avatar Feb 03 '17 22:02 qq42

Any updates on this?

prologic avatar Apr 04 '17 07:04 prologic

Not yet.

DhavalKapil avatar Apr 04 '17 17:04 DhavalKapil

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

#ifdef APPLE #define iphdr ip #endif

green4984 avatar Sep 18 '17 02:09 green4984

Got the same issues

BruceLEO1969 avatar Sep 19 '17 06:09 BruceLEO1969

Same here

BirkhoffLee avatar Nov 13 '17 02:11 BirkhoffLee

I'm having the same.

leonardoarroyo avatar Oct 27 '18 16:10 leonardoarroyo