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 2000/07/05 06:06:35 priikone
24 * Global cosmetic change.
26 * Revision 1.1.1.1 2000/06/27 11:36:55 priikone
27 * Imported from internal CVS/Added Log headers.
32 #include "silcincludes.h"
34 /* Converts ID to string. */
36 unsigned char *silc_id_id2str(void *id, SilcIdType type)
38 unsigned char *ret_id;
39 SilcServerID *server_id;
40 SilcClientID *client_id;
41 SilcChannelID *channel_id;
45 server_id = (SilcServerID *)id;
46 ret_id = silc_calloc(8, sizeof(unsigned char));
47 SILC_PUT32_MSB(server_id->ip.s_addr, ret_id);
48 SILC_PUT16_MSB(server_id->port, &ret_id[4]);
49 SILC_PUT16_MSB(server_id->rnd, &ret_id[6]);
53 client_id = (SilcClientID *)id;
54 ret_id = silc_calloc(16, sizeof(unsigned char));
55 SILC_PUT32_MSB(client_id->ip.s_addr, ret_id);
56 ret_id[4] = client_id->rnd;
57 memcpy(&ret_id[5], client_id->hash, CLIENTID_HASH_LEN);
61 channel_id = (SilcChannelID *)id;
62 ret_id = silc_calloc(8, sizeof(unsigned char));
63 SILC_PUT32_MSB(channel_id->ip.s_addr, ret_id);
64 SILC_PUT16_MSB(channel_id->port, &ret_id[4]);
65 SILC_PUT16_MSB(channel_id->rnd, &ret_id[6]);
73 /* Converts string to a ID */
75 void *silc_id_str2id(unsigned char *id, SilcIdType type)
81 SilcServerID *server_id = silc_calloc(1, sizeof(*server_id));
82 SILC_GET32_MSB(server_id->ip.s_addr, id);
83 SILC_GET16_MSB(server_id->port, &id[4]);
84 SILC_GET16_MSB(server_id->rnd, &id[6]);
90 SilcClientID *client_id = silc_calloc(1, sizeof(*client_id));
91 SILC_GET32_MSB(client_id->ip.s_addr, id);
92 client_id->rnd = id[4];
93 memcpy(client_id->hash, &id[5], CLIENTID_HASH_LEN);
99 SilcChannelID *channel_id = silc_calloc(1, sizeof(*channel_id));
100 SILC_GET32_MSB(channel_id->ip.s_addr, id);
101 SILC_GET16_MSB(channel_id->port, &id[4]);
102 SILC_GET16_MSB(channel_id->rnd, &id[6]);
111 /* Returns length of the ID */
113 unsigned int silc_id_get_len(SilcIdType type)
117 return SILC_ID_SERVER_LEN;
120 return SILC_ID_CLIENT_LEN;
122 case SILC_ID_CHANNEL:
123 return SILC_ID_CHANNEL_LEN;