Example #1
0
int getaddrinfo(const char *node, const char *service,
                const struct addrinfo *hints, struct addrinfo **res) {

  struct addrinfo *cur, *prev = NULL;
  struct hostent *he;
  struct in_addr ip;
  unsigned short portno;
  int i;

  if (service)
    portno = htons(atoi(service));
  else
    portno = 0;

  if (hints && hints->ai_flags & AI_PASSIVE) {
    *res = new_ai(portno, htonl(0x00000000));
    return 0;
  }

  if (!node) {
    *res = new_ai(portno, htonl(0x7f000001));
    return 0;
  }

  if (inet_pton(AF_INET, node, &ip)) {
    *res = new_ai(portno, ip.s_addr);
    return 0;
  }

  he = gethostbyname(node);
  if (he && he->h_addr_list[0]) {
    for (i = 0; he->h_addr_list[i]; i++) {
      cur = new_ai(portno, ((struct in_addr *)he->h_addr_list[i])->s_addr);

      if (prev)
        prev->ai_next = cur;
      else
        *res = cur;

      prev = cur;
    }
    return 0;
  }

  return EAI_NODATA;
}
Example #2
0
sanguis::server::entities::transfer_result
sanguis::server::entities::with_ai::on_create()
{
	// TODO: Improve this!
	sanguis::server::ai::tree::base_unique_ptr new_ai(
		create_ai_(
			ai_context_
		)
	);

	sanguis::server::ai::tree::base &ai_ref(
		*new_ai
	);

	ai_ =
		optional_ai_unique_ptr(
			std::move(
				new_ai
			)
		);

	return
		ai_ref.transfer();
}