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:55 priikone
24 * Importet from internal CVS/Added Log headers.
29 #include "silcincludes.h"
31 /* Converts ID to string. */
33 unsigned char *silc_id_id2str(void *id, SilcIdType type)
35 unsigned char *ret_id;
36 SilcServerID *server_id;
37 SilcClientID *client_id;
38 SilcChannelID *channel_id;
42 server_id = (SilcServerID *)id;
43 ret_id = silc_calloc(8, sizeof(unsigned char));
44 SILC_PUT32_MSB(server_id->ip.s_addr, ret_id);
45 SILC_PUT16_MSB(server_id->port, &ret_id[4]);
46 SILC_PUT16_MSB(server_id->rnd, &ret_id[6]);
50 client_id = (SilcClientID *)id;
51 ret_id = silc_calloc(16, sizeof(unsigned char));
52 SILC_PUT32_MSB(client_id->ip.s_addr, ret_id);
53 ret_id[4] = client_id->rnd;
54 memcpy(&ret_id[5], client_id->hash, CLIENTID_HASH_LEN);
58 channel_id = (SilcChannelID *)id;
59 ret_id = silc_calloc(8, sizeof(unsigned char));
60 SILC_PUT32_MSB(channel_id->ip.s_addr, ret_id);
61 SILC_PUT16_MSB(channel_id->port, &ret_id[4]);
62 SILC_PUT16_MSB(channel_id->rnd, &ret_id[6]);
70 /* Converts string to a ID */
72 void *silc_id_str2id(unsigned char *id, SilcIdType type)
78 SilcServerID *server_id = silc_calloc(1, sizeof(*server_id));
79 SILC_GET32_MSB(server_id->ip.s_addr, id);
80 SILC_GET16_MSB(server_id->port, &id[4]);
81 SILC_GET16_MSB(server_id->rnd, &id[6]);
87 SilcClientID *client_id = silc_calloc(1, sizeof(*client_id));
88 SILC_GET32_MSB(client_id->ip.s_addr, id);
89 client_id->rnd = id[4];
90 memcpy(client_id->hash, &id[5], CLIENTID_HASH_LEN);
96 SilcChannelID *channel_id = silc_calloc(1, sizeof(*channel_id));
97 SILC_GET32_MSB(channel_id->ip.s_addr, id);
98 SILC_GET16_MSB(channel_id->port, &id[4]);
99 SILC_GET16_MSB(channel_id->rnd, &id[6]);
108 /* Returns length of the ID */
110 unsigned int silc_id_get_len(SilcIdType type)
114 return SILC_ID_SERVER_LEN;
117 return SILC_ID_CLIENT_LEN;
119 case SILC_ID_CHANNEL:
120 return SILC_ID_CHANNEL_LEN;