5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 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.
23 * Revision 1.2 2001/02/02 13:34:45 priikone
26 * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
27 * Importet from internal CVS/Added Log headers.
32 #include "serverincludes.h"
34 /* Creates a Server ID. Newly created Server ID is returned to the
37 void silc_id_create_server_id(int sock, SilcRng rng, SilcServerID **new_id)
39 struct sockaddr_in server;
42 SILC_LOG_DEBUG(("Creating new Server ID"));
44 *new_id = silc_calloc(1, sizeof(**new_id));
45 if (*new_id == NULL) {
46 SILC_LOG_ERROR(("Could not allocate new Server ID"));
52 rval = getsockname(sock, (struct sockaddr *)&server, &len);
54 SILC_LOG_ERROR(("Could not get IP address: %s", strerror(errno)));
61 (*new_id)->ip = server.sin_addr;
62 (*new_id)->port = server.sin_port;
63 (*new_id)->rnd = silc_rng_get_rn16(rng);
65 SILC_LOG_DEBUG(("New ID (%s)", silc_id_render(*new_id, SILC_ID_SERVER)));
68 /* Creates Client ID */
70 void silc_id_create_client_id(SilcServerID *server_id, SilcRng rng,
71 SilcHash md5hash, char *nickname,
72 SilcClientID **new_id)
74 unsigned char hash[16];
76 SILC_LOG_DEBUG(("Creating new Client ID"));
78 *new_id = silc_calloc(1, sizeof(**new_id));
79 if (*new_id == NULL) {
80 SILC_LOG_ERROR(("Could not allocate new Client ID"));
84 /* Create hash of the nickanem */
85 silc_hash_make(md5hash, nickname, strlen(nickname), hash);
88 (*new_id)->ip.s_addr = server_id->ip.s_addr;
89 (*new_id)->rnd = silc_rng_get_byte(rng);
90 memcpy((*new_id)->hash, hash, CLIENTID_HASH_LEN);
92 SILC_LOG_DEBUG(("New ID (%s)", silc_id_render(*new_id, SILC_ID_CLIENT)));
95 /* Creates Channel ID */
97 void silc_id_create_channel_id(SilcServerID *router_id, SilcRng rng,
98 SilcChannelID **new_id)
100 SILC_LOG_DEBUG(("Creating new Channel ID"));
102 *new_id = silc_calloc(1, sizeof(**new_id));
103 if (*new_id == NULL) {
104 SILC_LOG_ERROR(("Could not allocate new Channel ID"));
109 (*new_id)->ip.s_addr = router_id->ip.s_addr;
110 (*new_id)->port = router_id->port;
111 (*new_id)->rnd = silc_rng_get_rn16(rng);
113 SILC_LOG_DEBUG(("New ID (%s)", silc_id_render(*new_id, SILC_ID_CHANNEL)));