#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <err.h>
#include <netdb.h>
#include <stdio.h>

int main(int argc, char **argv) {
  struct addrinfo *ai, *p;
  struct addrinfo hints = {.ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM};
  int res;

  if (argc != 3) errx(1, "usage: %s host port", argv[0]);

  res = getaddrinfo(argv[1], argv[2], &hints, &ai);
  if (res) errx(1, "getaddrinfo: %s", gai_strerror(res));

  for (p = ai; p; p = p->ai_next) {
    char ip[128];
    res = getnameinfo(p->ai_addr, p->ai_addrlen, ip, sizeof(ip), NULL, 0,
                      NI_NUMERICHOST);
    if (res) errx(1, "getnameinfo: %s", gai_strerror(res));
    printf("%s\n", ip);
  }

  freeaddrinfo(ai);
  return 0;
}