aboutsummaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-02-13 11:21:35 +0100
committerAndreas Schneider <asn@cryptomilk.org>2011-02-13 11:56:47 +0100
commitcd30a1d4b1d47636f86579b666d769d395e19782 (patch)
tree282193d4d7897f9b7e46dc22154e2d0944c1e143 /src/misc.c
parentca941d6985a41498744b4c1549c7aa05dbd8d10c (diff)
downloadlibssh-cd30a1d4b1d47636f86579b666d769d395e19782.tar.gz
libssh-cd30a1d4b1d47636f86579b666d769d395e19782.tar.xz
libssh-cd30a1d4b1d47636f86579b666d769d395e19782.zip
misc: Added working ssh_is_ipaddr for Windows.
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c102
1 files changed, 69 insertions, 33 deletions
diff --git a/src/misc.c b/src/misc.c
index d8d58c0a..857600d5 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -22,6 +22,8 @@
* MA 02111-1307, USA.
*/
+#include "config.h"
+
#ifndef _WIN32
/* This is needed for a standard getpwuid_r on opensolaris */
#define _POSIX_PTHREAD_SEMANTICS
@@ -32,7 +34,6 @@
#include <arpa/inet.h>
#endif
-#include "config.h"
#include <limits.h>
#include <stdio.h>
#include <string.h>
@@ -151,6 +152,44 @@ char *ssh_get_local_username(ssh_session session) {
return NULL;
}
+
+int ssh_is_ipaddr_v4(const char *str) {
+ struct sockaddr_storage ss;
+ int sslen = sizeof(ss);
+ int rc = SOCKET_ERROR;
+
+ rc = WSAStringToAddressA((LPSTR) str,
+ AF_INET,
+ NULL,
+ (struct sockaddr*)&ss,
+ &sslen);
+ if (rc == 0) {
+ return 1;
+ }
+
+ return 0;
+}
+
+int ssh_is_ipaddr(const char *str) {
+ int rc = SOCKET_ERROR;
+
+ if (strchr(str, ':')) {
+ struct sockaddr_storage ss;
+ int sslen = sizeof(ss);
+
+ /* TODO link-local (IP:v6:addr%ifname). */
+ rc = WSAStringToAddressA((LPSTR) str,
+ AF_INET6,
+ NULL,
+ (struct sockaddr*)&ss,
+ &sslen);
+ if (rc == 0) {
+ return 1;
+ }
+ }
+
+ return ssh_is_ipaddr_v4(str);
+}
#else /* _WIN32 */
#ifndef NSS_BUFLEN_PASSWD
@@ -206,6 +245,35 @@ char *ssh_get_local_username(ssh_session session) {
return name;
}
+
+int ssh_is_ipaddr_v4(const char *str) {
+ int rc = -1;
+ struct in_addr dest;
+
+ rc = inet_pton(AF_INET, str, &dest);
+ if (rc > 0) {
+ return 1;
+ }
+
+ return 0;
+}
+
+int ssh_is_ipaddr(const char *str) {
+ int rc = -1;
+
+ if (strchr(str, ':')) {
+ struct in6_addr dest6;
+
+ /* TODO link-local (IP:v6:addr%ifname). */
+ rc = inet_pton(AF_INET6, str, &dest6);
+ if (rc > 0) {
+ return 1;
+ }
+ }
+
+ return ssh_is_ipaddr_v4(str);
+}
+
#endif /* _WIN32 */
uint64_t ntohll(uint64_t a) {
@@ -782,38 +850,6 @@ int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2) {
return 0;
}
-/* TODO for Windows, inet_pton is only available on Vista and newer */
-int ssh_is_ipaddr_v4(const char *str) {
-#ifndef _WIN32
- int rc = -1;
- struct in_addr dest;
-
- rc = inet_pton(AF_INET, str, &dest);
- if (rc > 0) {
- return 1;
- }
-#endif
- return 0;
-}
-
-/* TODO for Windows, inet_pton is only available on Vista and newer */
-int ssh_is_ipaddr(const char *str) {
-#ifndef _WIN32
- int rc = -1;
-
- if (strchr(str, ':')) {
- struct in6_addr dest6;
-
- /* TODO link-local (IP:v6:addr%ifname). */
- rc = inet_pton(AF_INET6, str, &dest6);
- if (rc > 0) {
- return 1;
- }
- }
-#endif
- return ssh_is_ipaddr_v4(str);
-}
-
/** @} */
/* vim: set ts=4 sw=4 et cindent: */