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

Unable to cross compile on Linux #27

Open
yani opened this issue May 8, 2023 · 4 comments
Open

Unable to cross compile on Linux #27

yani opened this issue May 8, 2023 · 4 comments

Comments

@yani
Copy link

yani commented May 8, 2023

I had to change cross-compile-mingw.sh to use src paths:

i686-w64-mingw32-gcc -o pwnat.exe -O3 -DWIN32 src/socket.c src/message.c src/strlcpy.c src/client.c src/packet.c src/list.c src/udpserver.c src/udpclient.c src/pwnat.c src/destination.c -lws2_32

But now I'm getting the following output:

In file included from src/socket.h:34,
                 from src/socket.c:35:
src/common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
src/socket.c: In function ‘sock_connect’:
src/socket.c:154:52: warning: passing argument 4 of ‘setsockopt’ from incompatible pointer type [-Wincompatible-pointer-types]
  154 |     setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int));
      |                                                    ^~~~~~~~~~
      |                                                    |
      |                                                    int *
In file included from src/socket.h:30,
                 from src/socket.c:35:
/usr/share/mingw-w64/include/winsock2.h:1029:88: note: expected ‘const char *’ but argument is of type ‘int *’
 1029 |   WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
      |                                                                            ~~~~~~~~~~~~^~~~~~
src/socket.c:155:38: error: ‘SO_REUSEPORT’ undeclared (first use in this function); did you mean ‘PO_REN_PORT’?
  155 |     setsockopt(sock->fd, SOL_SOCKET, SO_REUSEPORT, &reuseport, sizeof(int));
      |                                      ^~~~~~~~~~~~
      |                                      PO_REN_PORT
src/socket.c:155:38: note: each undeclared identifier is reported only once for each function it appears in
src/socket.c:155:52: warning: passing argument 4 of ‘setsockopt’ from incompatible pointer type [-Wincompatible-pointer-types]
  155 |     setsockopt(sock->fd, SOL_SOCKET, SO_REUSEPORT, &reuseport, sizeof(int));
      |                                                    ^~~~~~~~~~
      |                                                    |
      |                                                    int *
In file included from src/socket.h:30,
                 from src/socket.c:35:
/usr/share/mingw-w64/include/winsock2.h:1029:88: note: expected ‘const char *’ but argument is of type ‘int *’
 1029 |   WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
      |                                                                            ~~~~~~~~~~~~^~~~~~
In file included from src/message.c:30:
src/common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
In file included from src/client.c:29:
src/common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
src/client.c: In function ‘client_send_udp_data’:
src/client.c:312:5: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
  312 |     gettimeofday(&client->tcp2udp_timeout, NULL);
      |     ^~~~~~~~~~~~
In file included from src/packet.c:22:
src/common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
In file included from src/list.h:25,
                 from src/list.c:24:
src/common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
In file included from src/udpserver.c:35:
src/common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
In file included from src/udpclient.c:43:
src/common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
src/udpclient.c: In function ‘udpclient’:
src/udpclient.c:143:70: warning: implicit declaration of function ‘hstrerror’; did you mean ‘strerror’? [-Wimplicit-function-declaration]
  143 |         printf("Couldn't resolve server address: '%s': %s\n", phost, hstrerror(h_errno));
      |                                                                      ^~~~~~~~~
      |                                                                      strerror
In file included from src/pwnat.c:33:
src/common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |        
@WuNein
Copy link

WuNein commented Jun 29, 2023

me too, same error

@samyk
Copy link
Owner

samyk commented Aug 8, 2023

This may be resolved in c50d093 if someone can confirm? You can download latest from git.

@Grub4K
Copy link

Grub4K commented Jan 20, 2024

On d100795 using i686-w64-mingw32-gcc -o pwnat.exe -O3 -DWIN32 *.c -lws2_32 -Wall -Wshadow -Wpointer-arith -Wwrite-strings from within the src/ directory, it still fails:

stderr
client.c: In function ‘client_send_udp_data’:
client.c:312:5: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
  312 |     gettimeofday(&client->tcp2udp_timeout, NULL);
      |     ^~~~~~~~~~~~
In file included from gettimeofday.c:4:
gettimeofday.h:15:8: error: redefinition of ‘struct timezone’
   15 | struct timezone
      |        ^~~~~~~~
In file included from gettimeofday.h:4:
/usr/i686-w64-mingw32/include/time.h:295:8: note: originally defined here
  295 | struct timezone {
      |        ^~~~~~~~
In file included from packet.c:16:
gettimeofday.h:15:8: error: redefinition of ‘struct timezone’
   15 | struct timezone
      |        ^~~~~~~~
In file included from gettimeofday.h:4:
/usr/i686-w64-mingw32/include/time.h:295:8: note: originally defined here
  295 | struct timezone {
      |        ^~~~~~~~
pwnat.c: In function ‘main’:
pwnat.c:60:37: warning: passing argument 3 of ‘getopt’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   60 |     while((ret = getopt(argc, argv, "hscv6ap")) != EOF)
      |                                     ^~~~~~~~~
In file included from pwnat.c:30:
xgetopt.h:23:42: note: expected ‘char *’ but argument is of type ‘const char *’
   23 | int getopt(int argc, char *argv[], char *optstring);
      |                                    ~~~~~~^~~~~~~~~
socket.c: In function ‘sock_connect’:
socket.c:155:50: warning: passing argument 4 of ‘setsockopt’ from incompatible pointer type [-Wincompatible-pointer-types]
  155 |   setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int));
      |                                                  ^~~~~~~~~~
      |                                                  |
      |                                                  int *
In file included from socket.h:30,
                 from socket.c:35:
/usr/i686-w64-mingw32/include/winsock2.h:1035:88: note: expected ‘const char *’ but argument is of type ‘int *’
 1035 |   WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
      |                                                                            ~~~~~~~~~~~~^~~~~~
In file included from udpclient.c:40:
gettimeofday.h:15:8: error: redefinition of ‘struct timezone’
   15 | struct timezone
      |        ^~~~~~~~
In file included from udpclient.c:26:
/usr/i686-w64-mingw32/include/time.h:295:8: note: originally defined here
  295 | struct timezone {
      |        ^~~~~~~~
udpclient.c: In function ‘udpclient’:
udpclient.c:146:74: error: too many arguments to function ‘WSAGetLastError’
  146 |             printf("Couldn't resolve server address: '%s': %s\n", phost, WSAGetLastError(h_errno));
      |                                                                          ^~~~~~~~~~~~~~~
In file included from gettimeofday.h:6:
/usr/i686-w64-mingw32/include/winsock2.h:1049:34: note: declared here
 1049 |   WINSOCK_API_LINKAGE int WSAAPI WSAGetLastError(void);
      |                                  ^~~~~~~~~~~~~~~
udpclient.c:146:61: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat=]
  146 |             printf("Couldn't resolve server address: '%s': %s\n", phost, WSAGetLastError(h_errno));
      |                                                            ~^            ~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                             |            |
      |                                                             char *       int
      |                                                            %d
In file included from udpserver.c:32:
gettimeofday.h:15:8: error: redefinition of ‘struct timezone’
   15 | struct timezone
      |        ^~~~~~~~
In file included from gettimeofday.h:4:
/usr/i686-w64-mingw32/include/time.h:295:8: note: originally defined here
  295 | struct timezone {
      |        ^~~~~~~~
udpserver.c: In function ‘udpserver’:
udpserver.c:257:40: warning: pointer targets in passing argument 2 of ‘recv’ differ in signedness [-Wpointer-sign]
  257 |         while ((ip = recv(listen_sock, packet, 100, 0)) > 0)
      |                                        ^~~~~~
      |                                        |
      |                                        unsigned char *
In file included from gettimeofday.h:6:
/usr/i686-w64-mingw32/include/winsock2.h:1028:54: note: expected ‘char *’ but argument is of type ‘unsigned char *’
 1028 |   WINSOCK_API_LINKAGE int WSAAPI recv(SOCKET s,char *buf,int len,int flags);
      |                                                ~~~~~~^~~

Same story when trying to build on c50d093

stderr
In file included from client.c:29:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
client.c: In function ‘client_send_udp_data’:
client.c:312:5: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
  312 |     gettimeofday(&client->tcp2udp_timeout, NULL);
      |     ^~~~~~~~~~~~
In file included from gettimeofday.c:4:
gettimeofday.h:17:24: warning: "/*" within comment [-Wcomment]
   17 |   int  tz_minuteswest; /* minutes W of Greenwich *
      |                         
gettimeofday.h:18:24: warning: "/*" within comment [-Wcomment]
   18 |   int  tz_dsttime;     /* type of dst correction *
      |                         
gettimeofday.c: In function ‘gettimeofday’:
gettimeofday.c:22:15: error: ‘DELTA_EPOCH_IN_MICROSECS’ undeclared (first use in this function)
   22 |     tmpres -= DELTA_EPOCH_IN_MICROSECS;
      |               ^~~~~~~~~~~~~~~~~~~~~~~~
gettimeofday.c:22:15: note: each undeclared identifier is reported only once for each function it appears in
In file included from list.h:25,
                 from list.c:24:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
In file included from message.c:30:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
In file included from packet.c:16:
gettimeofday.h:17:24: warning: "/*" within comment [-Wcomment]
   17 |   int  tz_minuteswest; /* minutes W of Greenwich *
      |                         
gettimeofday.h:18:24: warning: "/*" within comment [-Wcomment]
   18 |   int  tz_dsttime;     /* type of dst correction *
      |                         
In file included from packet.c:22:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
In file included from pwnat.c:33:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
pwnat.c: In function ‘main’:
pwnat.c:60:37: warning: passing argument 3 of ‘getopt’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   60 |     while((ret = getopt(argc, argv, "hscv6ap")) != EOF)
      |                                     ^~~~~~~~~
In file included from pwnat.c:30:
xgetopt.h:23:42: note: expected ‘char *’ but argument is of type ‘const char *’
   23 | int getopt(int argc, char *argv[], char *optstring);
      |                                    ~~~~~~^~~~~~~~~
In file included from socket.h:34,
                 from socket.c:35:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from socket.h:31:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
socket.c: In function ‘sock_connect’:
socket.c:155:50: warning: passing argument 4 of ‘setsockopt’ from incompatible pointer type [-Wincompatible-pointer-types]
  155 |   setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int));
      |                                                  ^~~~~~~~~~
      |                                                  |
      |                                                  int *
In file included from socket.h:30:
/usr/i686-w64-mingw32/include/winsock2.h:1035:88: note: expected ‘const char *’ but argument is of type ‘int *’
 1035 |   WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
      |                                                                            ~~~~~~~~~~~~^~~~~~
In file included from udpclient.c:40:
gettimeofday.h:17:24: warning: "/*" within comment [-Wcomment]
   17 |   int  tz_minuteswest; /* minutes W of Greenwich *
      |                         
gettimeofday.h:18:24: warning: "/*" within comment [-Wcomment]
   18 |   int  tz_dsttime;     /* type of dst correction *
      |                         
In file included from udpclient.c:43:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
udpclient.c: In function ‘udpclient’:
udpclient.c:143:70: warning: implicit declaration of function ‘hstrerror’; did you mean ‘strerror’? [-Wimplicit-function-declaration]
  143 |         printf("Couldn't resolve server address: '%s': %s\n", phost, hstrerror(h_errno));
      |                                                                      ^~~~~~~~~
      |                                                                      strerror
udpclient.c:143:57: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat=]
  143 |         printf("Couldn't resolve server address: '%s': %s\n", phost, hstrerror(h_errno));
      |                                                        ~^            ~~~~~~~~~~~~~~~~~~
      |                                                         |            |
      |                                                         char *       int
      |                                                        %d
In file included from udpserver.c:32:
gettimeofday.h:17:24: warning: "/*" within comment [-Wcomment]
   17 |   int  tz_minuteswest; /* minutes W of Greenwich *
      |                         
gettimeofday.h:18:24: warning: "/*" within comment [-Wcomment]
   18 |   int  tz_dsttime;     /* type of dst correction *
      |                         
In file included from udpserver.c:35:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
udpserver.c: In function ‘udpserver’:
udpserver.c:257:40: warning: pointer targets in passing argument 2 of ‘recv’ differ in signedness [-Wpointer-sign]
  257 |         while ((ip = recv(listen_sock, packet, 100, 0)) > 0)
      |                                        ^~~~~~
      |                                        |
      |                                        unsigned char *
In file included from gettimeofday.h:6:
/usr/i686-w64-mingw32/include/winsock2.h:1028:54: note: expected ‘char *’ but argument is of type ‘unsigned char *’
 1028 |   WINSOCK_API_LINKAGE int WSAAPI recv(SOCKET s,char *buf,int len,int flags);
      |                                                ~~~~~~^~~

@sweet-de-way
Copy link

d100795 上,从目录内使用,它仍然失败:i686-w64-mingw32-gcc -o pwnat.exe -O3 -DWIN32 *.c -lws2_32 -Wall -Wshadow -Wpointer-arith -Wwrite-strings``src/

stderr

client.c: In function ‘client_send_udp_data’:
client.c:312:5: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
  312 |     gettimeofday(&client->tcp2udp_timeout, NULL);
      |     ^~~~~~~~~~~~
In file included from gettimeofday.c:4:
gettimeofday.h:15:8: error: redefinition of ‘struct timezone’
   15 | struct timezone
      |        ^~~~~~~~
In file included from gettimeofday.h:4:
/usr/i686-w64-mingw32/include/time.h:295:8: note: originally defined here
  295 | struct timezone {
      |        ^~~~~~~~
In file included from packet.c:16:
gettimeofday.h:15:8: error: redefinition of ‘struct timezone’
   15 | struct timezone
      |        ^~~~~~~~
In file included from gettimeofday.h:4:
/usr/i686-w64-mingw32/include/time.h:295:8: note: originally defined here
  295 | struct timezone {
      |        ^~~~~~~~
pwnat.c: In function ‘main’:
pwnat.c:60:37: warning: passing argument 3 of ‘getopt’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   60 |     while((ret = getopt(argc, argv, "hscv6ap")) != EOF)
      |                                     ^~~~~~~~~
In file included from pwnat.c:30:
xgetopt.h:23:42: note: expected ‘char *’ but argument is of type ‘const char *’
   23 | int getopt(int argc, char *argv[], char *optstring);
      |                                    ~~~~~~^~~~~~~~~
socket.c: In function ‘sock_connect’:
socket.c:155:50: warning: passing argument 4 of ‘setsockopt’ from incompatible pointer type [-Wincompatible-pointer-types]
  155 |   setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int));
      |                                                  ^~~~~~~~~~
      |                                                  |
      |                                                  int *
In file included from socket.h:30,
                 from socket.c:35:
/usr/i686-w64-mingw32/include/winsock2.h:1035:88: note: expected ‘const char *’ but argument is of type ‘int *’
 1035 |   WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
      |                                                                            ~~~~~~~~~~~~^~~~~~
In file included from udpclient.c:40:
gettimeofday.h:15:8: error: redefinition of ‘struct timezone’
   15 | struct timezone
      |        ^~~~~~~~
In file included from udpclient.c:26:
/usr/i686-w64-mingw32/include/time.h:295:8: note: originally defined here
  295 | struct timezone {
      |        ^~~~~~~~
udpclient.c: In function ‘udpclient’:
udpclient.c:146:74: error: too many arguments to function ‘WSAGetLastError’
  146 |             printf("Couldn't resolve server address: '%s': %s\n", phost, WSAGetLastError(h_errno));
      |                                                                          ^~~~~~~~~~~~~~~
In file included from gettimeofday.h:6:
/usr/i686-w64-mingw32/include/winsock2.h:1049:34: note: declared here
 1049 |   WINSOCK_API_LINKAGE int WSAAPI WSAGetLastError(void);
      |                                  ^~~~~~~~~~~~~~~
udpclient.c:146:61: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat=]
  146 |             printf("Couldn't resolve server address: '%s': %s\n", phost, WSAGetLastError(h_errno));
      |                                                            ~^            ~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                             |            |
      |                                                             char *       int
      |                                                            %d
In file included from udpserver.c:32:
gettimeofday.h:15:8: error: redefinition of ‘struct timezone’
   15 | struct timezone
      |        ^~~~~~~~
In file included from gettimeofday.h:4:
/usr/i686-w64-mingw32/include/time.h:295:8: note: originally defined here
  295 | struct timezone {
      |        ^~~~~~~~
udpserver.c: In function ‘udpserver’:
udpserver.c:257:40: warning: pointer targets in passing argument 2 of ‘recv’ differ in signedness [-Wpointer-sign]
  257 |         while ((ip = recv(listen_sock, packet, 100, 0)) > 0)
      |                                        ^~~~~~
      |                                        |
      |                                        unsigned char *
In file included from gettimeofday.h:6:
/usr/i686-w64-mingw32/include/winsock2.h:1028:54: note: expected ‘char *’ but argument is of type ‘unsigned char *’
 1028 |   WINSOCK_API_LINKAGE int WSAAPI recv(SOCKET s,char *buf,int len,int flags);
      |                                                ~~~~~~^~~

尝试在 c50d093 上构建时也是如此

stderr

In file included from client.c:29:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
client.c: In function ‘client_send_udp_data’:
client.c:312:5: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
  312 |     gettimeofday(&client->tcp2udp_timeout, NULL);
      |     ^~~~~~~~~~~~
In file included from gettimeofday.c:4:
gettimeofday.h:17:24: warning: "/*" within comment [-Wcomment]
   17 |   int  tz_minuteswest; /* minutes W of Greenwich *
      |                         
gettimeofday.h:18:24: warning: "/*" within comment [-Wcomment]
   18 |   int  tz_dsttime;     /* type of dst correction *
      |                         
gettimeofday.c: In function ‘gettimeofday’:
gettimeofday.c:22:15: error: ‘DELTA_EPOCH_IN_MICROSECS’ undeclared (first use in this function)
   22 |     tmpres -= DELTA_EPOCH_IN_MICROSECS;
      |               ^~~~~~~~~~~~~~~~~~~~~~~~
gettimeofday.c:22:15: note: each undeclared identifier is reported only once for each function it appears in
In file included from list.h:25,
                 from list.c:24:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
In file included from message.c:30:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
In file included from packet.c:16:
gettimeofday.h:17:24: warning: "/*" within comment [-Wcomment]
   17 |   int  tz_minuteswest; /* minutes W of Greenwich *
      |                         
gettimeofday.h:18:24: warning: "/*" within comment [-Wcomment]
   18 |   int  tz_dsttime;     /* type of dst correction *
      |                         
In file included from packet.c:22:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
In file included from pwnat.c:33:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
pwnat.c: In function ‘main’:
pwnat.c:60:37: warning: passing argument 3 of ‘getopt’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   60 |     while((ret = getopt(argc, argv, "hscv6ap")) != EOF)
      |                                     ^~~~~~~~~
In file included from pwnat.c:30:
xgetopt.h:23:42: note: expected ‘char *’ but argument is of type ‘const char *’
   23 | int getopt(int argc, char *argv[], char *optstring);
      |                                    ~~~~~~^~~~~~~~~
In file included from socket.h:34,
                 from socket.c:35:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from socket.h:31:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
socket.c: In function ‘sock_connect’:
socket.c:155:50: warning: passing argument 4 of ‘setsockopt’ from incompatible pointer type [-Wincompatible-pointer-types]
  155 |   setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int));
      |                                                  ^~~~~~~~~~
      |                                                  |
      |                                                  int *
In file included from socket.h:30:
/usr/i686-w64-mingw32/include/winsock2.h:1035:88: note: expected ‘const char *’ but argument is of type ‘int *’
 1035 |   WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
      |                                                                            ~~~~~~~~~~~~^~~~~~
In file included from udpclient.c:40:
gettimeofday.h:17:24: warning: "/*" within comment [-Wcomment]
   17 |   int  tz_minuteswest; /* minutes W of Greenwich *
      |                         
gettimeofday.h:18:24: warning: "/*" within comment [-Wcomment]
   18 |   int  tz_dsttime;     /* type of dst correction *
      |                         
In file included from udpclient.c:43:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
udpclient.c: In function ‘udpclient’:
udpclient.c:143:70: warning: implicit declaration of function ‘hstrerror’; did you mean ‘strerror’? [-Wimplicit-function-declaration]
  143 |         printf("Couldn't resolve server address: '%s': %s\n", phost, hstrerror(h_errno));
      |                                                                      ^~~~~~~~~
      |                                                                      strerror
udpclient.c:143:57: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat=]
  143 |         printf("Couldn't resolve server address: '%s': %s\n", phost, hstrerror(h_errno));
      |                                                        ~^            ~~~~~~~~~~~~~~~~~~
      |                                                         |            |
      |                                                         char *       int
      |                                                        %d
In file included from udpserver.c:32:
gettimeofday.h:17:24: warning: "/*" within comment [-Wcomment]
   17 |   int  tz_minuteswest; /* minutes W of Greenwich *
      |                         
gettimeofday.h:18:24: warning: "/*" within comment [-Wcomment]
   18 |   int  tz_dsttime;     /* type of dst correction *
      |                         
In file included from udpserver.c:35:
common.h:31:72: warning: parameter 2 (‘src’) has void type
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                                             ~~~~~~~~~~~^~~
common.h:31:43: error: conflicting types for ‘inet_ntop’; have ‘char(int,  const void,  char *, socklen_t)’ {aka ‘char(int,  const void,  char *, int)’}
   31 |     WINSOCK_API_LINKAGE const char WSAAPI inet_ntop(int af, const void src, char *dst, socklen_t size);
      |                                           ^~~~~~~~~
In file included from common.h:30:
/usr/i686-w64-mingw32/include/ws2tcpip.h:400:35: note: previous declaration of ‘inet_ntop’ with type ‘const CHAR *(INT,  const void *, CHAR *, size_t)’ {aka ‘const char *(int,  const void *, char *, unsigned int)’}
  400 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
udpserver.c: In function ‘udpserver’:
udpserver.c:257:40: warning: pointer targets in passing argument 2 of ‘recv’ differ in signedness [-Wpointer-sign]
  257 |         while ((ip = recv(listen_sock, packet, 100, 0)) > 0)
      |                                        ^~~~~~
      |                                        |
      |                                        unsigned char *
In file included from gettimeofday.h:6:
/usr/i686-w64-mingw32/include/winsock2.h:1028:54: note: expected ‘char *’ but argument is of type ‘unsigned char *’
 1028 |   WINSOCK_API_LINKAGE int WSAAPI recv(SOCKET s,char *buf,int len,int flags);
      |                                                ~~~~~~^~~

The error "struct timezone" is because mingw follows the POSIX specification and defines "struct timezone".
The author defines "struct timezone" because "struct timezone" is not defined under Windows.
To solve this error, you just need to comment "struct timezone" in "gettimeofday.h".

The same is true for the errors about "inet_pton" and "inet_ntop", you need to comment them in the HEAER file.

The reason for this may be that these functions were not defined under previous mingw.

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

No branches or pull requests

5 participants