-
- if (status == 0) {
- /* Now fully qualify the hostname. */
- memset(&hints, 0, sizeof hints);
- hints.ai_flags = AI_CANONNAME;
- hints.ai_family = AF_UNSPEC;
-
- if ((status = getaddrinfo(hostname, NULL, &hints, &res)) == 0) {
- printf("%s\n", res->ai_canonname);
- freeaddrinfo(res);
- } else {
- printf("%s\n", hostname);
+ if (argc == 2)
+ hostname = argv[1];
+ else {
+ /* First get our local name. */
+ if (gethostname(buf, sizeof buf)) {
+ fprintf(stderr, "gethostname() failed: %s\n", strerror(errno));
+ return 1;