Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2001 Pekka Riikonen
+ Copyright (C) 1997 - 2005 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
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
+ the Free Software Foundation; version 2 of the License.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* $Id$ */
#include "silcincludes.h"
-#include "silcnet.h"
/* Accepts a connection from a particular socket */
/* Get socket options */
-int silc_net_get_socket_opt(int sock, int level, int option,
+int silc_net_get_socket_opt(int sock, int level, int option,
void *optval, int *opt_len)
{
return getsockopt(sock, level, option, optval, opt_len);
if (count != 3)
return FALSE;
-
+
return TRUE;
}
return FALSE;
addr++;
}
-
+
return TRUE;
}
r->result = strdup(tmp);
silc_schedule_task_add(schedule, 0, silc_net_resolve_completion, r, 0, 1,
- SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+ SILC_TASK_TIMEOUT);
silc_schedule_wakeup(schedule);
return NULL;
}
r->result = strdup(tmp);
silc_schedule_task_add(schedule, 0, silc_net_resolve_completion, r, 0, 1,
- SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+ SILC_TASK_TIMEOUT);
silc_schedule_wakeup(schedule);
return NULL;
}
/* Resolves IP address for hostname. */
-bool silc_net_gethostbyname(const char *name, bool prefer_ipv6, char *address,
+bool silc_net_gethostbyname(const char *name, bool prefer_ipv6, char *address,
SilcUInt32 address_len)
{
#ifdef HAVE_IPV6
memset(address, 0, address_len);
strncpy(address, tmp, strlen(tmp));
#endif
-
+
return TRUE;
}
/* Resolves IP address for hostname async. */
-void silc_net_gethostbyname_async(const char *name,
+void silc_net_gethostbyname_async(const char *name,
bool prefer_ipv6,
SilcSchedule schedule,
SilcNetResolveCallback completion,
{
#ifdef HAVE_IPV6
struct addrinfo req, *ai;
-
+
memset(&req, 0, sizeof(req));
req.ai_socktype = SOCK_STREAM;
req.ai_flags = AI_CANONNAME;
-
+
if (getaddrinfo(addr, NULL, &req, &ai))
return FALSE;
if (getnameinfo(ai->ai_addr, ai->ai_addrlen, name, name_len, NULL, 0, 0)) {
freeaddrinfo(ai);
#else
struct hostent *hp;
+ unsigned char a[16];
- hp = gethostbyaddr(addr, strlen(addr), AF_INET);
+ if (!silc_net_addr2bin(addr, a, sizeof(a)))
+ return FALSE;
+
+ hp = gethostbyaddr(a, 4, AF_INET);
if (!hp)
return FALSE;
if (name_len < strlen(hp->h_name))
memset(name, 0, name_len);
strncpy(name, hp->h_name, strlen(hp->h_name));
#endif
-
+
return TRUE;
}
/* Resolves hostname by IP address async. */
-void silc_net_gethostbyaddr_async(const char *addr,
+void silc_net_gethostbyaddr_async(const char *addr,
SilcSchedule schedule,
SilcNetResolveCallback completion,
void *context)
struct sockaddr_storage remote;
char s[NI_MAXHOST];
- *hostname = NULL;
+ if (hostname)
+ *hostname = NULL;
*ip = NULL;
SILC_LOG_DEBUG(("Resolving remote hostname and IP address"));
struct sockaddr_in remote;
char *host_ip;
- *hostname = NULL;
+ if (hostname)
+ *hostname = NULL;
*ip = NULL;
SILC_LOG_DEBUG(("Resolving remote hostname and IP address"));
return FALSE;
#endif
- /* Get host by address */
- if (!silc_net_gethostbyaddr(*ip, host, sizeof(host)))
- return FALSE;
+ /* Do reverse lookup if we want hostname too. */
+ if (hostname) {
+ /* Get host by address */
+ if (!silc_net_gethostbyaddr(*ip, host, sizeof(host)))
+ return FALSE;
- *hostname = silc_memdup(host, strlen(host));
- SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname));
+ *hostname = silc_memdup(host, strlen(host));
+ SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname));
- /* Reverse */
- if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host)))
- return FALSE;
+ /* Reverse */
+ if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host)))
+ return FALSE;
- if (strcmp(*ip, host))
- return FALSE;
+ if (strcmp(*ip, host))
+ return FALSE;
+ }
SILC_LOG_DEBUG(("Resolved IP address `%s'", *ip));
return TRUE;
struct sockaddr_storage local;
char s[NI_MAXHOST];
- *hostname = NULL;
+ if (hostname)
+ *hostname = NULL;
*ip = NULL;
SILC_LOG_DEBUG(("Resolving local hostname and IP address"));
struct sockaddr_in local;
char *host_ip;
- *hostname = NULL;
+ if (hostname)
+ *hostname = NULL;
*ip = NULL;
SILC_LOG_DEBUG(("Resolving local hostname and IP address"));
return FALSE;
#endif
- /* Get host by address */
- if (!silc_net_gethostbyaddr(*ip, host, sizeof(host)))
- return FALSE;
+ /* Do reverse lookup if we want hostname too. */
+ if (hostname) {
+ /* Get host by address */
+ if (!silc_net_gethostbyaddr(*ip, host, sizeof(host)))
+ return FALSE;
- *hostname = silc_memdup(host, strlen(host));
- SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname));
+ *hostname = silc_memdup(host, strlen(host));
+ SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname));
- /* Reverse */
- if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host)))
- return FALSE;
+ /* Reverse */
+ if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host)))
+ return FALSE;
- if (strcmp(*ip, host))
- return FALSE;
+ if (strcmp(*ip, host))
+ return FALSE;
+ }
SILC_LOG_DEBUG(("Resolved IP address `%s'", *ip));
return TRUE;
if (getnameinfo((struct sockaddr *)&remote, len, NULL, 0, s, sizeof(s),
NI_NUMERICSERV))
return 0;
-
+
return atoi(s);
#else
struct sockaddr_in remote;
if (getnameinfo((struct sockaddr *)&local, len, NULL, 0, s, sizeof(s),
NI_NUMERICSERV))
return 0;
-
+
return atoi(s);
#else
struct sockaddr_in local;