5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
22 #include "serverincludes.h"
24 /* Creates a Server ID. Newly created Server ID is returned to the
27 void silc_id_create_server_id(int sock, SilcRng rng, SilcServerID **new_id)
29 struct sockaddr_in server;
32 SILC_LOG_DEBUG(("Creating new Server ID"));
34 *new_id = silc_calloc(1, sizeof(**new_id));
38 rval = getsockname(sock, (struct sockaddr *)&server, &len);
40 SILC_LOG_ERROR(("Could not get IP address: %s", strerror(errno)));
47 /* XXX Does not support IPv6 */
48 SILC_PUT32_MSB(server.sin_addr.s_addr, (*new_id)->ip.data);
49 (*new_id)->ip.data_len = 4;
50 (*new_id)->port = server.sin_port;
51 (*new_id)->rnd = silc_rng_get_rn16(rng);
53 SILC_LOG_DEBUG(("New ID (%s)", silc_id_render(*new_id, SILC_ID_SERVER)));
56 /* Creates Client ID */
58 void silc_id_create_client_id(SilcServerID *server_id, SilcRng rng,
59 SilcHash md5hash, char *nickname,
60 SilcClientID **new_id)
62 unsigned char hash[16];
64 SILC_LOG_DEBUG(("Creating new Client ID"));
66 *new_id = silc_calloc(1, sizeof(**new_id));
68 /* Create hash of the nickanem */
69 silc_hash_make(md5hash, nickname, strlen(nickname), hash);
72 memcpy((*new_id)->ip.data, server_id->ip.data, server_id->ip.data_len);
73 (*new_id)->ip.data_len = server_id->ip.data_len;
74 (*new_id)->rnd = silc_rng_get_byte(rng);
75 memcpy((*new_id)->hash, hash, CLIENTID_HASH_LEN);
77 SILC_LOG_DEBUG(("New ID (%s)", silc_id_render(*new_id, SILC_ID_CLIENT)));
80 /* Creates Channel ID */
82 void silc_id_create_channel_id(SilcServerID *router_id, SilcRng rng,
83 SilcChannelID **new_id)
85 SILC_LOG_DEBUG(("Creating new Channel ID"));
87 *new_id = silc_calloc(1, sizeof(**new_id));
90 memcpy((*new_id)->ip.data, router_id->ip.data, router_id->ip.data_len);
91 (*new_id)->ip.data_len = router_id->ip.data_len;
92 (*new_id)->port = router_id->port;
93 (*new_id)->rnd = silc_rng_get_rn16(rng);
95 SILC_LOG_DEBUG(("New ID (%s)", silc_id_render(*new_id, SILC_ID_CHANNEL)));