Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 16805c1776
Fetching contributors…

Cannot retrieve contributors at this time

file 35 lines (29 sloc) 0.835 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <string.h>
#include <netdb.h>
#include <stdio.h>

extern int h_errno;

int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s host:port command [arg1 arg2 ..]\n", argv[0]);
    return 1;
  }

  int fd = socket(PF_INET, SOCK_STREAM, 0);
  size_t pos = strcspn(argv[1], ":");
  char *host = argv[1];
  short port = (short)atoi(argv[1] + pos + 1);
  host[pos] = '\0';
  //struct hostent *hent4 = gethostbyname2(host, PF_INET);

  struct sockaddr sa;
  socklen_t salen;
  
  printf("-> %s:%d\n", host, port);
  int inforet = getnameinfo(&sa, salen, host, strlen(host), NULL, 0, 0);
  if (inforet == 0) {
    printf("OK\n");
  } else {
    printf("%d\n", inforet);
    printf("%s\n", gai_strerror(inforet));
  }
  
  return -1;
}
Something went wrong with that request. Please try again.