+
+ /* Assure that the ID does not exist already */
+ while (1) {
+ if (!silc_idlist_find_channel_by_id(server->local_list,
+ *new_id, NULL))
+ break;
+
+ (*new_id)->rnd++;
+
+ if (finding && (*new_id)->rnd == 0)
+ return FALSE;
+
+ if (!finding) {
+ (*new_id)->rnd = 0;
+ finding = TRUE;
+ }
+ }
+
+ SILC_LOG_DEBUG(("New ID (%s)", silc_id_render(*new_id, SILC_ID_CHANNEL)));
+
+ return TRUE;
+}
+
+/* Checks whether the `server_id' is valid. It must be based to the
+ IP address provided in the `remote' socket connection. */
+
+SilcBool silc_id_is_valid_server_id(SilcServer server,
+ SilcServerID *server_id,
+ SilcPacketStream remote)
+{
+ unsigned char ip[16];
+ const char *remote_ip;
+ SilcStream stream = silc_packet_stream_get_stream(remote);
+
+ silc_socket_stream_get_info(stream, NULL, NULL, &remote_ip, NULL);
+ if (!silc_net_addr2bin(remote_ip, ip, sizeof(ip)))
+ return FALSE;
+
+ if (silc_net_is_ip4(remote_ip)) {
+ if (!memcmp(server_id->ip.data, ip, 4))
+ return TRUE;
+ } else {
+ if (!memcmp(server_id->ip.data, ip, 16))
+ return TRUE;
+ }
+
+ return FALSE;