toaruos/apps/nslookup.c
2021-09-09 19:42:19 +09:00

33 lines
745 B
C

/* vim: tabstop=4 shiftwidth=4 noexpandtab
* This file is part of ToaruOS and is released under the terms
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2016-2018 K. Lange
*
* nslookup - perform nameserver lookups
*
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
int main(int argc, char * argv[]) {
if (argc < 2) return 1;
struct hostent * host = gethostbyname(argv[1]);
if (!host) {
fprintf(stderr, "%s: not found\n", argv[1]);
return 1;
}
char * addr = inet_ntoa(*(struct in_addr*)host->h_addr_list[0]);
fprintf(stderr, "%s: %s\n", host->h_name, addr);
return 0;
}