예제 #1
0
/*
 * Solaris Kerberos:
 * krb5int_address_get_realm() given an address (either IPv4 or IPv6) tries to
 * find a realm based on the DNS name of that address. Assumes that its being
 * used as a callback for krb5int_foreach_localaddr().
 */
static int krb5int_address_get_realm(void *data, struct sockaddr *addr) {
	
	krb5_context context = data;
	struct hostent *he = NULL;

	switch (addr->sa_family) {
		case AF_INET:
			he = res_gethostbyaddr((char*)(&sa2sin(addr)->sin_addr),
			    sizeof(sa2sin(addr)->sin_addr), AF_INET);
			break;
		case AF_INET6:
			he = res_gethostbyaddr(
			    (char*)(&sa2sin6(addr)->sin6_addr),
			    sizeof(sa2sin6(addr)->sin6_addr), AF_INET6);
			break;
	}

	if (he) {
		/* Try to find realm using returned DNS name */
		krb5int_fqdn_get_realm(context, he->h_name,
		    &context->default_realm);

		/* If a realm was found return 1 to immediately halt
		 * krb5int_foreach_localaddr()
		 */ 
		if (context->default_realm != 0) {
			return (1);
		}
	}
	return (0);
}
예제 #2
0
파일: addr_res.c 프로젝트: nfarrar/mudfiles
main(int argc, char *argv[]) 
{
  int sd;
  char buff[512];
  struct sockaddr_in my_addr, reply_addr;
  extern struct hostent *res_gethostbyaddr();

  if((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  {
    perror("socket");
    exit(1);
  }
  memset((char *) &my_addr, sizeof(my_addr), 0);
  my_addr.sin_family = AF_INET;
  my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  my_addr.sin_port = htons(PORT);
  if(bind(sd, (struct sockaddr *) &my_addr, sizeof(my_addr)) < 0)
  {
    perror("bind");
    exit(1);
  }
  while(1)
  {
    int n, len;
    char *p;
    unsigned long addr;
    struct hostent *hp;
    
    len = sizeof(reply_addr);
    if((n = recvfrom(sd, buff, sizeof(buff), 0, 
		     (struct sockaddr *) &reply_addr, &len)) < 0)
    {
      perror("recvfrom");
      exit(1);
    }
    buff[n] = '\0';
    if(p = strchr(buff, '\n'))
      *p = '\0';
    addr = inet_addr(buff);
    if (addr != -1) 
    {
      hp = res_gethostbyaddr(&addr, 4, AF_INET);
      if (!hp) 
      {
	sleep(5);
	hp = res_gethostbyaddr(&addr, 4, AF_INET);
      }
      if (hp) 
      {
	sprintf(buff + strlen(buff), " %s", hp->h_name);
	if((sendto(sd, buff, strlen(buff), 0, &reply_addr, len)) < 0)
	{
	  perror("sendto");
	  abort();
	}
      }
    }
  }
}