mirror of
https://github.com/libssh2/libssh2.git
synced 2025-08-05 20:55:47 +03:00
example: make x11
exclusion build-tool-agnostic
Whether to build the `x11` example or not was decided by each build tool. CMake didn't build it even on supported platforms. GNUMakefile used a specific blocklist for it, while autotools enabled it based on feature-detection. Migrate the enabler logic to an #ifdef in source and build `x11` unconditionally with all build tools. On unsupported platforms (=Windows) this program now displays a short message stating that fact. Also: - fix `x11.c` warnings uncovered after CMake started building it. - use `libssh2_socket_t` type for portability in `x11.c` too. - use detected header guards in `x11.c`. - delete a duplicate reference to `-lws2_32` from `win32/GNUmakefile` while there. Closes #909
This commit is contained in:
@@ -62,7 +62,8 @@ set(EXAMPLES
|
|||||||
ssh2_echo
|
ssh2_echo
|
||||||
ssh2_exec
|
ssh2_exec
|
||||||
subsystem_netconf
|
subsystem_netconf
|
||||||
tcpip-forward)
|
tcpip-forward
|
||||||
|
x11)
|
||||||
|
|
||||||
foreach(example ${EXAMPLES})
|
foreach(example ${EXAMPLES})
|
||||||
add_executable(example-${example} ${example}.c)
|
add_executable(example-${example} ${example}.c)
|
||||||
|
@@ -26,11 +26,8 @@ noinst_PROGRAMS = \
|
|||||||
ssh2_echo \
|
ssh2_echo \
|
||||||
ssh2_exec \
|
ssh2_exec \
|
||||||
subsystem_netconf \
|
subsystem_netconf \
|
||||||
tcpip-forward
|
tcpip-forward \
|
||||||
|
x11
|
||||||
if HAVE_SYS_UN_H
|
|
||||||
noinst_PROGRAMS += x11
|
|
||||||
endif
|
|
||||||
|
|
||||||
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/example -I../src
|
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/example -I../src
|
||||||
LDADD = $(top_builddir)/src/libssh2.la
|
LDADD = $(top_builddir)/src/libssh2.la
|
||||||
|
@@ -5,23 +5,44 @@
|
|||||||
* "ssh2 host user password [DEBUG]"
|
* "ssh2 host user password [DEBUG]"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <libssh2.h>
|
||||||
|
#include "libssh2_config.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_UN_H
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifdef HAVE_SYS_IOCTL_H
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_NETINET_IN_H
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_SOCKET_H
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_SELECT_H
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_ARPA_INET_H
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_UN_H
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
#endif
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <termios.h>
|
#endif
|
||||||
|
|
||||||
#include <libssh2.h>
|
#include <termios.h>
|
||||||
|
|
||||||
#define _PATH_UNIX_X "/tmp/.X11-unix/X%d"
|
#define _PATH_UNIX_X "/tmp/.X11-unix/X%d"
|
||||||
|
|
||||||
@@ -67,7 +88,7 @@ static void remove_node(struct chan_X11_list *elem)
|
|||||||
static void session_shutdown(LIBSSH2_SESSION *session)
|
static void session_shutdown(LIBSSH2_SESSION *session)
|
||||||
{
|
{
|
||||||
libssh2_session_disconnect(session,
|
libssh2_session_disconnect(session,
|
||||||
"Session Shutdown, Thank you for playing");
|
"Session Shutdown, Thank you for playing");
|
||||||
libssh2_session_free(session);
|
libssh2_session_free(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,8 +130,8 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel,
|
|||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
char *temp_buff = NULL;
|
char *temp_buff = NULL;
|
||||||
int display_port = 0;
|
int display_port = 0;
|
||||||
int sock = 0;
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
struct chan_X11_list *new;
|
struct chan_X11_list *new;
|
||||||
struct chan_X11_list *chan_iter;
|
struct chan_X11_list *chan_iter;
|
||||||
@@ -138,7 +159,7 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel,
|
|||||||
free(temp_buff);
|
free(temp_buff);
|
||||||
|
|
||||||
sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if(sock < 0)
|
if(sock == LIBSSH2_INVALID_SOCKET)
|
||||||
return;
|
return;
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
@@ -212,7 +233,7 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock)
|
|||||||
fds[0].revents = LIBSSH2_POLLFD_POLLIN;
|
fds[0].revents = LIBSSH2_POLLFD_POLLIN;
|
||||||
|
|
||||||
rc = libssh2_poll(fds, nfds, 0);
|
rc = libssh2_poll(fds, nfds, 0);
|
||||||
if(rc >0) {
|
if(rc > 0) {
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
nread = libssh2_channel_read(channel, buf, bufsize);
|
nread = libssh2_channel_read(channel, buf, bufsize);
|
||||||
write(sock, buf, nread);
|
write(sock, buf, nread);
|
||||||
@@ -220,12 +241,14 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock)
|
|||||||
|
|
||||||
rc = select((int)(sock + 1), &set, NULL, NULL, &timeval_out);
|
rc = select((int)(sock + 1), &set, NULL, NULL, &timeval_out);
|
||||||
if(rc > 0) {
|
if(rc > 0) {
|
||||||
|
ssize_t nread;
|
||||||
|
|
||||||
memset((void *)buf, 0, bufsize);
|
memset((void *)buf, 0, bufsize);
|
||||||
|
|
||||||
/* Data in sock */
|
/* Data in sock */
|
||||||
rc = read(sock, buf, bufsize);
|
nread = read(sock, buf, bufsize);
|
||||||
if(rc > 0) {
|
if(nread > 0) {
|
||||||
libssh2_channel_write(channel, buf, rc);
|
libssh2_channel_write(channel, buf, nread);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
free(buf);
|
free(buf);
|
||||||
@@ -248,8 +271,8 @@ int
|
|||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint32_t hostaddr = 0;
|
uint32_t hostaddr = 0;
|
||||||
int sock = 0;
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
LIBSSH2_SESSION *session;
|
LIBSSH2_SESSION *session;
|
||||||
LIBSSH2_CHANNEL *channel;
|
LIBSSH2_CHANNEL *channel;
|
||||||
@@ -298,7 +321,7 @@ main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if(sock == -1) {
|
if(sock == LIBSSH2_INVALID_SOCKET) {
|
||||||
perror("socket");
|
perror("socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -450,9 +473,11 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
rc = select((int)(fileno(stdin) + 1), &set, NULL, NULL, &timeval_out);
|
rc = select((int)(fileno(stdin) + 1), &set, NULL, NULL, &timeval_out);
|
||||||
if(rc > 0) {
|
if(rc > 0) {
|
||||||
|
ssize_t nread;
|
||||||
|
|
||||||
/* Data in stdin */
|
/* Data in stdin */
|
||||||
rc = read(fileno(stdin), buf, 1);
|
nread = read(fileno(stdin), buf, 1);
|
||||||
if(rc > 0)
|
if(nread > 0)
|
||||||
libssh2_channel_write(channel, buf, sizeof(buf));
|
libssh2_channel_write(channel, buf, sizeof(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,3 +499,14 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
printf("Sorry, this platform is not supported.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_SYS_UN_H */
|
||||||
|
@@ -52,7 +52,7 @@ RCFLAGS += -I$(PROOT)/include
|
|||||||
# examples, tests
|
# examples, tests
|
||||||
|
|
||||||
LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32
|
LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32
|
||||||
LIBS_BIN := -lssh2 -lws2_32
|
LIBS_BIN := -lssh2
|
||||||
|
|
||||||
ifdef DYN
|
ifdef DYN
|
||||||
libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a
|
libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a
|
||||||
@@ -164,7 +164,7 @@ libssh2_dll_LIBRARY := $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll
|
|||||||
libssh2_dll_a_LIBRARY := $(TARGET).dll.a
|
libssh2_dll_a_LIBRARY := $(TARGET).dll.a
|
||||||
|
|
||||||
EXAMPLES := $(PROOT)/example
|
EXAMPLES := $(PROOT)/example
|
||||||
TARGETS_EXAMPLES := $(filter-out $(EXAMPLES)/x11.exe,$(patsubst %.c,%.exe,$(strip $(wildcard $(EXAMPLES)/*.c))))
|
TARGETS_EXAMPLES := $(patsubst %.c,%.exe,$(strip $(wildcard $(EXAMPLES)/*.c)))
|
||||||
|
|
||||||
all: lib dll
|
all: lib dll
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user