Added preliminary Symbian support.
[silc.git] / lib / silcutil / silcnet.c
index d778135107a8baed4365faf4e69eedb470e702de..a6c0f9271456171013bc36b0aac679bae7a2b03c 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2005 Pekka Riikonen
+  Copyright (C) 1997 - 2006 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
 */
 /* $Id$ */
 
-#include "silcincludes.h"
+#include "silc.h"
+
+/* Returns bound port from listener */
+
+SilcUInt16 *silc_net_listener_get_port(SilcNetListener listener,
+                                      SilcUInt32 *port_count)
+{
+  SilcUInt16 *ports;
+  int i;
+
+  ports = silc_calloc(listener->socks_count, sizeof(*ports));
+  if (!ports)
+    return NULL;
+
+  for (i = 0; i < listener->socks_count; i++)
+    ports[i] = silc_net_get_local_port(listener->socks[i]);
+
+  if (port_count)
+    *port_count = listener->socks_count;
+
+  return ports;
+}
 
 /* Accepts a connection from a particular socket */
 
@@ -44,12 +65,12 @@ int silc_net_get_socket_opt(int sock, int level, int option,
 
 /* Checks whether IP address sent as argument is valid IPv4 address. */
 
-bool silc_net_is_ip4(const char *addr)
+SilcBool silc_net_is_ip4(const char *addr)
 {
   int count = 0;
 
   while (*addr) {
-    if (*addr != '.' && !isdigit(*addr))
+    if (*addr != '.' && !isdigit((int)*addr))
       return FALSE;
     if (*addr == '.')
       count++;
@@ -64,11 +85,11 @@ bool silc_net_is_ip4(const char *addr)
 
 /* Checks whether IP address sent as argument is valid IPv6 address. */
 
-bool silc_net_is_ip6(const char *addr)
+SilcBool silc_net_is_ip6(const char *addr)
 {
   /* XXX does this work with all kinds of IPv6 addresses? */
   while (*addr) {
-    if (*addr != ':' && !isxdigit(*addr))
+    if (*addr != ':' && !isxdigit((int)*addr))
       return FALSE;
     addr++;
   }
@@ -78,7 +99,7 @@ bool silc_net_is_ip6(const char *addr)
 
 /* Checks whether IP address sent as argument is valid IP address. */
 
-bool silc_net_is_ip(const char *addr)
+SilcBool silc_net_is_ip(const char *addr)
 {
   if (silc_net_is_ip4(addr))
     return TRUE;
@@ -89,7 +110,7 @@ bool silc_net_is_ip(const char *addr)
 typedef struct {
   SilcNetResolveCallback completion;
   void *context;
-  bool prefer_ipv6;
+  SilcBool prefer_ipv6;
   SilcSchedule schedule;
   char *input;
   char *result;
@@ -144,8 +165,9 @@ static void *silc_net_gethostbyaddr_thread(void *context)
 
 /* Resolves IP address for hostname. */
 
-bool silc_net_gethostbyname(const char *name, bool prefer_ipv6, char *address,
-                           SilcUInt32 address_len)
+SilcBool silc_net_gethostbyname(const char *name,
+                               SilcBool prefer_ipv6, char *address,
+                               SilcUInt32 address_len)
 {
 #ifdef HAVE_IPV6
   struct addrinfo hints, *ai, *tmp, *ip4 = NULL, *ip6 = NULL;
@@ -208,7 +230,7 @@ bool silc_net_gethostbyname(const char *name, bool prefer_ipv6, char *address,
 /* Resolves IP address for hostname async. */
 
 void silc_net_gethostbyname_async(const char *name,
-                                 bool prefer_ipv6,
+                                 SilcBool prefer_ipv6,
                                  SilcSchedule schedule,
                                  SilcNetResolveCallback completion,
                                  void *context)
@@ -226,7 +248,8 @@ void silc_net_gethostbyname_async(const char *name,
 
 /* Resolves hostname by IP address. */
 
-bool silc_net_gethostbyaddr(const char *addr, char *name, SilcUInt32 name_len)
+SilcBool silc_net_gethostbyaddr(const char *addr, char *name,
+                               SilcUInt32 name_len)
 {
 #ifdef HAVE_IPV6
   struct addrinfo req, *ai;
@@ -278,10 +301,13 @@ void silc_net_gethostbyaddr_async(const char *addr,
   silc_thread_create(silc_net_gethostbyaddr_thread, r, FALSE);
 }
 
+#ifndef SILC_SYMBIAN
+
 /* Performs lookups for remote name and IP address. This peforms reverse
    lookup as well to verify that the IP has FQDN. */
 
-bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip)
+SilcBool silc_net_check_host_by_sock(SilcSocket sock, char **hostname,
+                                    char **ip)
 {
   char host[1024];
   int rval, len;
@@ -359,7 +385,8 @@ bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip)
 /* Performs lookups for local name and IP address. This peforms reverse
    lookup as well to verify that the IP has FQDN. */
 
-bool silc_net_check_local_by_sock(int sock, char **hostname, char **ip)
+SilcBool silc_net_check_local_by_sock(SilcSocket sock, char **hostname,
+                                     char **ip)
 {
   char host[1024];
   int rval, len;
@@ -436,7 +463,7 @@ bool silc_net_check_local_by_sock(int sock, char **hostname, char **ip)
 
 /* Return remote port by socket. */
 
-SilcUInt16 silc_net_get_remote_port(int sock)
+SilcUInt16 silc_net_get_remote_port(SilcSocket sock)
 {
 #ifdef HAVE_IPV6
   struct sockaddr_storage remote;
@@ -468,7 +495,7 @@ SilcUInt16 silc_net_get_remote_port(int sock)
 
 /* Return local port by socket. */
 
-SilcUInt16 silc_net_get_local_port(int sock)
+SilcUInt16 silc_net_get_local_port(SilcSocket sock)
 {
 #ifdef HAVE_IPV6
   struct sockaddr_storage local;
@@ -497,6 +524,7 @@ SilcUInt16 silc_net_get_local_port(int sock)
   return ntohs(local.sin_port);
 #endif
 }
+#endif /* !SILC_SYMBIAN */
 
 /* Return name of localhost. */