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.
26 Note that these are currently IPv4 specific, although adding IPv6
27 support is not a bad task and SILC protocol already supports IPv6.
33 #define SILC_ID_SERVER_LEN (64 / 8)
34 #define SILC_ID_CLIENT_LEN (128 / 8)
35 #define SILC_ID_CHANNEL_LEN (64 / 8)
36 #define CLIENTID_HASH_LEN (88 / 8) /* Client ID's 88 bit MD5 hash */
39 #define SILC_ID_NONE 0
40 #define SILC_ID_SERVER 1
41 #define SILC_ID_CLIENT 2
42 #define SILC_ID_CHANNEL 3
44 /* Type definition for the ID types. */
45 typedef unsigned char SilcIdType;
48 64 bit SilcServerID structure:
55 struct in_addr ip; /* 32 bit IP */
56 unsigned short port; /* 16 bit port */
57 unsigned short rnd; /* 16 bit random number */
61 128 bit SilcClientID structure:
63 32 bit ServerID IP address [bits 1-32]
65 88 bit hash value from nickname
68 struct in_addr ip; /* 32 bit IP */
69 unsigned char rnd; /* 8 bit random number */
70 unsigned char hash[CLIENTID_HASH_LEN]; /* 88 bit MD5 hash */
74 64 bit SilcChannel ID structure:
76 32 bit Router's ServerID IP address [bits 1-32]
77 16 bit Router's ServerID port [bits 33-48]
81 struct in_addr ip; /* 32 bit IP */
82 unsigned short port; /* 16 bit port */
83 unsigned short rnd; /* 16 bit random number */
88 /* Compares two ID's */
89 #define SILC_ID_COMPARE(id1, id2, len) (memcmp(id1, id2, len))
91 /* Compares Channel ID's */
92 #define SILC_ID_CHANNEL_COMPARE(id1, id2) \
93 SILC_ID_COMPARE(id1, id2, SILC_ID_CHANNEL_LEN)
95 /* Compares Client ID's */
96 #define SILC_ID_CLIENT_COMPARE(id1, id2) \
97 SILC_ID_COMPARE(id1, id2, SILC_ID_CLIENT_LEN)
99 /* Compares Server ID's */
100 #define SILC_ID_SERVER_COMPARE(id1, id2) \
101 SILC_ID_COMPARE(id1, id2, SILC_ID_SERVER_LEN)
103 /* Compares IP addresses from the ID's. */
104 #define SILC_ID_COMPARE_IP(id1, id2) \
105 SILC_ID_COMPARE(id1, id2, 4)
107 /* Compare nickname hash from Client ID */
108 #define SILC_ID_COMPARE_HASH(id, hash) \
109 memcmp(id->hash, hash, CLIENTID_HASH_LEN)
112 unsigned char *silc_id_id2str(void *id, SilcIdType type);
113 void *silc_id_str2id(unsigned char *id, SilcIdType type);
114 unsigned int silc_id_get_len(SilcIdType type);