-int add_host_h(conn_list_t *cl)
-{
- char *options;
- conn_list_t *old, *new;
-cp
- new = new_conn_list();
-
- if(sscanf(cl->buffer, "%*d %as %lx:%d %as", &new->name, &new->real_ip, &new->port, &options) != 4)
- {
- syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s)"), cl->name, cl->hostname);
- return -1;
- }
-
- /* Check if option string is valid */
-
- if((new->options = str2opt(options)) == -1)
- {
- syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s): invalid option string"), cl->name, cl->hostname);
- return -1;
- }
-
- /* Check if identity is a valid name */
-
- if(!check_id(new->name))
- {
- syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s): invalid identity name"), cl->name, cl->hostname);
- return -1;
- }
-
- /* Check if somebody tries to add ourself */
-
- if(!strcmp(new->name, myself->name))
- {
- syslog(LOG_ERR, _("Warning: got ADD_HOST from %s (%s) for ourself, restarting"), cl->name, cl->hostname);
- sighup = 1;
- return 0;
- }
-
- /* Fill in more of the new conn_list structure */
-
- new->hostname = hostlookup(htonl(new->real_ip));
-
- /* Check if the new host already exists in the connnection list */
-
- if((old = lookup_id(new->name)))
- {
- if((new->real_ip == old->real_ip) && (new->port == old->port))
- {
- if(debug_lvl > DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Got duplicate ADD_HOST for %s (%s) from %s (%s)"),
- old->name, old->hostname, new->name, new->hostname);
- return 0;
- }
- else
- {
- if(debug_lvl > DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Removing old entry for %s (%s)"),
- old->name, old->hostname);
- old->status.active = 0;
- terminate_connection(old);
- }
- }
-
- /* Fill in rest of conn_list structure */
-
- new->nexthop = cl;
- new->status.active = 1;
-
- /* Hook it up into the conn_list */
-
- conn_list_add(conn_list, new);
-
- /* Tell the rest about the new host */
-
- notify_others(new, cl, send_add_host);
-
-cp
- return 0;
-}