/*
- silcutil.c
+ silcutil.c
- Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+ Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 2002 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
int ret;
struct stat stats;
+#ifndef SILC_WIN32\r
ret = lstat(filename, &stats);
- if (ret < 0)
- return 0;
+#else\r
+ ret = stat(filename, &stats);\r
+#endif\r
+ if (ret < 0)\r
+ return 0;\r
return (uint64)stats.st_size;
}
if (!string)
return FALSE;
+ if (string[0] == '@') {
+ if (left)
+ *left = strdup(string);
+ return TRUE;
+ }
+
if (strchr(string, '@')) {
tlen = strcspn(string, "@");
case SILC_ID_SERVER:
{
SilcServerID *server_id = (SilcServerID *)id;
- struct in_addr ipv4;
-
if (server_id->ip.data_len > 4) {
-
+#ifdef HAVE_IPV6
+ struct in6_addr ipv6;
+ memmove(&ipv6, server_id->ip.data, sizeof(ipv6));
+ if (!inet_ntop(AF_INET6, &ipv6, tmp, sizeof(tmp)))
+ strcat(rid, tmp);
+#endif
} else {
- SILC_GET32_MSB(ipv4.s_addr, server_id->ip.data);
+ struct in_addr ipv4;
+ memmove(&ipv4.s_addr, server_id->ip.data, 4);
strcat(rid, inet_ntoa(ipv4));
}
case SILC_ID_CLIENT:
{
SilcClientID *client_id = (SilcClientID *)id;
- struct in_addr ipv4;
-
if (client_id->ip.data_len > 4) {
-
+#ifdef HAVE_IPV6
+ struct in6_addr ipv6;
+ memmove(&ipv6, client_id->ip.data, sizeof(ipv6));
+ if (!inet_ntop(AF_INET6, &ipv6, tmp, sizeof(tmp)))
+ strcat(rid, tmp);
+#endif
} else {
- SILC_GET32_MSB(ipv4.s_addr, client_id->ip.data);
+ struct in_addr ipv4;
+ memmove(&ipv4.s_addr, client_id->ip.data, 4);
strcat(rid, inet_ntoa(ipv4));
}
case SILC_ID_CHANNEL:
{
SilcChannelID *channel_id = (SilcChannelID *)id;
- struct in_addr ipv4;
-
if (channel_id->ip.data_len > 4) {
-
+#ifdef HAVE_IPV6
+ struct in6_addr ipv6;
+ memmove(&ipv6, channel_id->ip.data, sizeof(ipv6));
+ if (!inet_ntop(AF_INET6, &ipv6, tmp, sizeof(tmp)))
+ strcat(rid, tmp);
+#endif
} else {
- SILC_GET32_MSB(ipv4.s_addr, channel_id->ip.data);
+ struct in_addr ipv4;
+ memmove(&ipv4.s_addr, channel_id->ip.data, 4);
strcat(rid, inet_ntoa(ipv4));
}
return strdup(string);
}
+
+/* Creates fingerprint from data, usually used with SHA1 digests */
+
+char *silc_fingerprint(const unsigned char *data, uint32 data_len)
+{
+ char fingerprint[64], *cp;
+ int i;
+
+ memset(fingerprint, 0, sizeof(fingerprint));
+ cp = fingerprint;
+ for (i = 0; i < data_len; i++) {
+ snprintf(cp, sizeof(fingerprint), "%02X", data[i]);
+ cp += 2;
+
+ if ((i + 1) % 2 == 0)
+ snprintf(cp++, sizeof(fingerprint), " ");
+
+ if ((i + 1) % 10 == 0)
+ snprintf(cp++, sizeof(fingerprint), " ");
+ }
+ i--;
+ if ((i + 1) % 2 == 0)
+ cp[-2] = 0;
+ if ((i + 1) % 10 == 0)
+ cp[-1] = 0;
+
+ return strdup(fingerprint);
+}