From 977dbb7511e2392275549fab8ae074eb2928e3da Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Mon, 15 Dec 2014 00:02:48 +0100 Subject: [PATCH] examples on Windows: check for socket return code Fixes VS2012 code analysis warning C28193: The variable holds a value that must be examined --- example/direct_tcpip.c | 12 ++++++++++++ example/subsystem_netconf.c | 12 ++++++++++++ example/tcpip-forward.c | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index c0cc68aa..fc086877 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -99,6 +99,18 @@ int main(int argc, char *argv[]) /* Connect to SSH server */ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); +#ifdef WIN32 + if (sock == INVALID_SOCKET) { + fprintf(stderr, "failed to open socket!\n"); + return -1; + } +#else + if (sock == -1) { + perror("socket"); + return -1; + } +#endif + sin.sin_family = AF_INET; if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(server_ip))) { perror("inet_addr"); diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index 624ef68c..8a3f9e8a 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -137,6 +137,18 @@ int main(int argc, char *argv[]) /* Connect to SSH server */ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); +#ifdef WIN32 + if (sock == INVALID_SOCKET) { + fprintf(stderr, "failed to open socket!\n"); + return -1; + } +#else + if (sock == -1) { + perror("socket"); + return -1; + } +#endif + sin.sin_family = AF_INET; if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(server_ip))) { fprintf(stderr, "inet_addr: Invalid IP address \"%s\"\n", server_ip); diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index fc0bfbc1..78363758 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -96,6 +96,18 @@ int main(int argc, char *argv[]) /* Connect to SSH server */ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); +#ifdef WIN32 + if (sock == INVALID_SOCKET) { + fprintf(stderr, "failed to open socket!\n"); + return -1; + } +#else + if (sock == -1) { + perror("socket"); + return -1; + } +#endif + sin.sin_family = AF_INET; if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(server_ip))) { perror("inet_addr");