/*
 * Copyright 1988, 1989, 1990, 1991 Massachusetts Institute of Technology
 */
#include"structs.h"

notify_hosts()
{
  int cc;
  FILE *fp, *fopen();
  char temp[100];

  struct hostent *hp;
  fp = fopen(HOST_NOTIFY_FILE,"r");
  if (fp == NULL) {
#ifdef OBSOLETE
    if (DEBUG) printf("> Unable to read %s\n",HOST_NOTIFY_FILE);
#endif OBSOLETE
    return;
  }
  
  if (DEBUG) printf("Attempting notification.\n");
  while (fscanf(fp, "%s\n",temp) != EOF) {
      if (strcmp(temp, localaddress)) {
	notice.sin_addr.s_addr = inet_addr(temp);
	if (notice.sin_addr.s_addr != -1) {
	  cc = sendto(notice_socket, RESPONSE, strlen(RESPONSE)+1, 0, &notice, 
		      sizeof(struct sockaddr_in));
	  if (DEBUG && cc == -1) printf("Couldn't notify %s\n",temp);
	  else if (DEBUG) printf("Notified %s\n",temp);
	}
	else if (DEBUG) printf("> Couldn't find %s\n",temp);
      }
      else if (DEBUG) printf("> Refuse to notify myself.\n");
    }
}
    
check_remote_servers()
{
 
  int i, cc;
  struct hostent *hp;
  
  for (i = 0; i < num_forwards; i++) {
    if (remote_servers[i].fd == -1) {
      hp = gethostbyname(remote_servers[i].name);
      if (hp != 0) {
	bcopy(hp->h_addr,&notice.sin_addr,hp->h_length);
	cc = sendto(notice_socket, QUERY, strlen(QUERY)+1, 0, &notice, 
		    sizeof(struct sockaddr_in));
	if (DEBUG && cc == -1) printf("Couldn't query %s\n",
				      remote_servers[i].name);
	else if (DEBUG) printf("Queried %s\n",remote_servers[i].name);
      }
      else if (DEBUG) printf("> Couldn't find %s\n",remote_servers[i].name);
    }
  }
}
