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.
20 /* These are important ID types used in SILC. SILC server creates these
21 but SILC client has to handle these as well since these are used in
22 packet sending and reception. However, client never creates these
23 but it receives the correct ID's from server. Clients, servers and
24 channels are identified by the these ID's.
30 /* The SILC ID Types */
31 #define SILC_ID_NONE 0
32 #define SILC_ID_SERVER 1
33 #define SILC_ID_CLIENT 2
34 #define SILC_ID_CHANNEL 3
36 /* Type definition for the ID types. */
37 typedef uint16 SilcIdType;
39 /* The ID Lenghts. These are IPv4 based and should be noted if used directly
40 that these cannot be used with IPv6. */
41 #define SILC_ID_SERVER_LEN (64 / 8)
42 #define SILC_ID_CLIENT_LEN (128 / 8)
43 #define SILC_ID_CHANNEL_LEN (64 / 8)
45 #define CLIENTID_HASH_LEN (88 / 8) /* Client ID's 88 bit MD5 hash */
50 Generic IP address structure to indicate either IPv4 or IPv6 address.
51 This structure is used inside all SILC ID's. The true length of the
52 ID depends of the length of the IP address.
55 unsigned char data[16]; /* IP data (in MSB first order) */
56 uint8 data_len; /* Length of the data (4 or 16) */
60 64 or 160 bit SilcServerID structure:
67 SilcIDIP ip; /* n bit IP address */
68 uint16 port; /* 16 bit port */
69 uint16 rnd; /* 16 bit random number */
73 128 or 224 bit SilcClientID structure:
75 n bit ServerID IP address [bits 1-32 or bits 1-128]
77 88 bit hash value from nickname
80 SilcIDIP ip; /* n bit IP address */
81 unsigned char rnd; /* 8 bit random number */
82 unsigned char hash[CLIENTID_HASH_LEN]; /* 88 bit MD5 hash */
86 64 or 160 bit SilcChannel ID structure:
88 n bit Router's ServerID IP address [bits 1-32 or bits 1-128]
89 16 bit Router's ServerID port [bits 33-48 or bits 129-144]
93 SilcIDIP ip; /* n bit IP address */
94 uint16 port; /* 16 bit port */
95 uint16 rnd; /* 16 bit random number */
100 /* Compares two ID's. */
101 #define SILC_ID_COMPARE(id1, id2, len) (!memcmp(id1, id2, len))
103 /* Compares Client ID's */
104 #define SILC_ID_CLIENT_COMPARE(id1, id2) \
105 SILC_ID_COMPARE(id1, id2, sizeof(SilcClientID))
107 /* Compares Server ID's */
108 #define SILC_ID_SERVER_COMPARE(id1, id2) \
109 SILC_ID_COMPARE(id1, id2, sizeof(SilcServerID))
111 /* Compares Channel ID's */
112 #define SILC_ID_CHANNEL_COMPARE(id1, id2) \
113 SILC_ID_COMPARE(id1, id2, sizeof(SilcChannelID))
115 /* Compares two ID's by type */
116 #define SILC_ID_COMPARE_TYPE(id1, id2, type) \
117 (type == SILC_ID_SERVER ? SILC_ID_SERVER_COMPARE(id1, id2) : \
118 type == SILC_ID_CLIENT ? SILC_ID_CLIENT_COMPARE(id1, id2) : \
119 SILC_ID_CHANNEL_COMPARE(id1, id2))
121 /* Compare nickname hash from Client ID */
122 #define SILC_ID_COMPARE_HASH(id1, id2) \
123 (!memcmp((id1)->hash, (id2)->hash, CLIENTID_HASH_LEN))
126 unsigned char *silc_id_id2str(void *id, SilcIdType type);
127 void *silc_id_str2id(unsigned char *id, uint32 id_len, SilcIdType type);
128 uint32 silc_id_get_len(void *id, SilcIdType type);
129 void *silc_id_dup(void *id, SilcIdType type);