LibVNC / libvncserver

LibVNCServer/LibVNCClient are cross-platform C libraries that allow you to easily implement VNC server or client functionality in your program.
GNU General Public License v2.0
1.08k stars 483 forks source link

Build fails on FreeBSD: error: use of undeclared identifier 'PF_INET' #548

Closed VVD closed 1 year ago

VVD commented 1 year ago

Describe the bug Compile of 0.9.14 fails on FreeBSD, but 0.9.13 build without errors.

To Reproduce Compile 0.9.14.

Expected Behavior Compile without errors.

Logs/Backtraces

/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:56:18: warning: implicit declaration of function 'accept' is invalid in C99 [-Wimplicit-function-declaration]
    proxy_sock = accept(data->local_listensock, (struct sockaddr *)&sin, &sinlen);
                 ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:63:5: warning: implicit declaration of function 'close' is invalid in C99 [-Wimplicit-function-declaration]
    rfbCloseSocket(data->local_listensock);
    ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:117:6: note: expanded from macro 'rfbCloseSocket'
            _rfbCloseSocket(s);         \
            ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:107:25: note: expanded from macro '_rfbCloseSocket'
#define _rfbCloseSocket close
                        ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:94:19: warning: implicit declaration of function 'recv' is invalid in C99 [-Wimplicit-function-declaration]
            len = recv(proxy_sock, buf, sizeof(buf), 0);
                  ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:127:21: warning: implicit declaration of function 'send' is invalid in C99 [-Wimplicit-function-declaration]
                i = send(proxy_sock, buf + wr, len - wr, 0);
                    ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:146:5: warning: implicit declaration of function 'close' is invalid in C99 [-Wimplicit-function-declaration]
    rfbCloseSocket(proxy_sock);
    ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:117:6: note: expanded from macro 'rfbCloseSocket'
            _rfbCloseSocket(s);         \
            ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:107:25: note: expanded from macro '_rfbCloseSocket'
#define _rfbCloseSocket close
                        ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:154:5: warning: implicit declaration of function 'close' is invalid in C99 [-Wimplicit-function-declaration]
    rfbCloseSocket(data->ssh_sock);
    ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:117:6: note: expanded from macro 'rfbCloseSocket'
            _rfbCloseSocket(s);         \
            ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:107:25: note: expanded from macro '_rfbCloseSocket'
#define _rfbCloseSocket close
                        ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:213:22: warning: implicit declaration of function 'socket' is invalid in C99 [-Wimplicit-function-declaration]
    data->ssh_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
                     ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:213:29: error: use of undeclared identifier 'PF_INET'
    data->ssh_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
                            ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:213:38: error: use of undeclared identifier 'SOCK_STREAM'
    data->ssh_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
                                     ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:220:25: error: use of undeclared identifier 'AF_INET'
    hints.ai_family   = AF_INET;
                        ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:221:25: error: use of undeclared identifier 'SOCK_STREAM'
    hints.ai_socktype = SOCK_STREAM;
                        ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:224:19: error: use of undeclared identifier 'AF_INET'
        sin.sin_family = AF_INET;
                         ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:233:8: warning: implicit declaration of function 'connect' is invalid in C99 [-Wimplicit-function-declaration]
    if(connect(data->ssh_sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
       ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:288:37: error: use of undeclared identifier 'PF_INET'
    data->local_listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
                                    ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:288:46: error: use of undeclared identifier 'SOCK_STREAM'
    data->local_listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
                                             ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:293:22: error: use of undeclared identifier 'AF_INET'
    sin.sin_family = AF_INET;
                     ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:301:14: warning: implicit declaration of function 'bind' is invalid in C99 [-Wimplicit-function-declaration]
    if(-1 == bind(data->local_listensock, (struct sockaddr *)&sin, sinlen)) {
             ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:305:14: warning: implicit declaration of function 'listen' is invalid in C99 [-Wimplicit-function-declaration]
    if(-1 == listen(data->local_listensock, 1)) {
             ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:311:9: warning: implicit declaration of function 'getsockname' is invalid in C99 [-Wimplicit-function-declaration]
    if (getsockname(data->local_listensock, (struct sockaddr *)&sin, &sinlen ) == -1){
        ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:340:5: warning: implicit declaration of function 'close' is invalid in C99 [-Wimplicit-function-declaration]
    rfbCloseSocket(data->local_listensock);
    ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:117:6: note: expanded from macro 'rfbCloseSocket'
            _rfbCloseSocket(s);         \
            ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:107:25: note: expanded from macro '_rfbCloseSocket'
#define _rfbCloseSocket close
                        ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:341:5: warning: implicit declaration of function 'close' is invalid in C99 [-Wimplicit-function-declaration]
    rfbCloseSocket(data->ssh_sock);
    ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:117:6: note: expanded from macro 'rfbCloseSocket'
            _rfbCloseSocket(s);         \
            ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:107:25: note: expanded from macro '_rfbCloseSocket'
#define _rfbCloseSocket close
                        ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/client_examples/sshtunnel.c:423:6: warning: implicit declaration of function 'close' is invalid in C99 [-Wimplicit-function-declaration]
            rfbCloseSocket(client->sock);
            ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:117:6: note: expanded from macro 'rfbCloseSocket'
            _rfbCloseSocket(s);         \
            ^
/tmp/work/usr/ports/net/libvncserver/work/libvncserver-LibVNCServer-0.9.14/rfb/rfbproto.h:107:25: note: expanded from macro '_rfbCloseSocket'
#define _rfbCloseSocket close
                        ^
14 warnings and 8 errors generated.

Your environment (please complete the following information):

Additional context Issue on FreeBSD's bugtracker: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269039 accept require #include <sys/types.h> and #include <sys/socket.h>: https://www.freebsd.org/cgi/man.cgi?query=accept&sektion=2 close require #include <unistd.h>: https://www.freebsd.org/cgi/man.cgi?query=close&sektion=2

Patch:

--- client_examples/sshtunnel.c.orig
+++ client_examples/sshtunnel.c
@@ -10,6 +10,11 @@
  *  - added name resolution for the ssh host
  */

+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
 #include <rfb/rfbclient.h>
 #include <libssh2.h>
 #include <arpa/inet.h>
VVD commented 1 year ago

Configure stage silent "grab" libssh2 if it installed:

If libssh2 not installed: Could NOT find LibSSH2 (missing: LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR)

If libssh2 installed: -- Found LibSSH2: /usr/local/lib/libssh2.so (found version "1.10.0")

What purpose of the file client_examples/sshtunnel.c for build libvncserver? If it's just example, maybe remove it from default build and other examples too?

bk138 commented 1 year ago

What purpose of the file client_examples/sshtunnel.c for build libvncserver? If it's just example, maybe remove it from default build and other examples too?

As the dir implies, it's an example. You can build without examples if wanted.

bk138 commented 1 year ago

@VVD I now fixed it by checking header availability #ifdefs, not OS-specific ones. Should work for you as well me thinks