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.1.1.1 2000/06/27 11:36:56 priikone
24 * Importet from internal CVS/Added Log headers.
29 #include "serverincludes.h"
31 /* Creates a Server ID. Newly created Server ID is returned to the
34 void silc_id_create_server_id(int sock, SilcRng rng, SilcServerID **new_id)
36 struct sockaddr_in server;
39 SILC_LOG_DEBUG(("Creating new Server ID"));
41 *new_id = silc_calloc(1, sizeof(**new_id));
42 if (*new_id == NULL) {
43 SILC_LOG_ERROR(("Could not allocate new Server ID"));
49 rval = getsockname(sock, (struct sockaddr *)&server, &len);
51 SILC_LOG_ERROR(("Could not get IP address: %s", strerror(errno)));
58 (*new_id)->ip = server.sin_addr;
59 (*new_id)->port = server.sin_port;
60 (*new_id)->rnd = silc_rng_get_rn16(rng);
63 /* Creates Client ID */
65 void silc_id_create_client_id(SilcServerID *server_id, SilcRng rng,
66 SilcHash md5hash, char *nickname,
67 SilcClientID **new_id)
69 unsigned char hash[16];
71 SILC_LOG_DEBUG(("Creating new Client ID"));
73 *new_id = silc_calloc(1, sizeof(**new_id));
74 if (*new_id == NULL) {
75 SILC_LOG_ERROR(("Could not allocate new Client ID"));
79 /* Create hash of the nickanem */
80 silc_hash_make(md5hash, nickname, strlen(nickname), hash);
83 (*new_id)->ip.s_addr = server_id->ip.s_addr;
84 (*new_id)->rnd = silc_rng_get_byte(rng);
85 memcpy((*new_id)->hash, hash, CLIENTID_HASH_LEN);
88 /* Creates Channel ID */
90 void silc_id_create_channel_id(SilcServerID *router_id, SilcRng rng,
91 SilcChannelID **new_id)
93 SILC_LOG_DEBUG(("Creating new Channel ID"));
95 *new_id = silc_calloc(1, sizeof(**new_id));
96 if (*new_id == NULL) {
97 SILC_LOG_ERROR(("Could not allocate new Channel ID"));
102 (*new_id)->ip.s_addr = router_id->ip.s_addr;
103 (*new_id)->port = router_id->port;
104 (*new_id)->rnd = silc_rng_get_rn16(rng);