Last active
May 16, 2020 02:48
-
-
Save brianredbeard/59fae5040d38361a47477f4928ddfcfd to your computer and use it in GitHub Desktop.
Examples of name resolution (using gethostbyname() ) used in an explanation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM scratch | |
ADD ghbn /ghbn | |
CMD ["/ghbn", "example.com"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM scratch | |
ADD ghbn-go /ghbn | |
CMD ["/ghbn", "example.com"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <arpa/inet.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <netdb.h> | |
// | |
// gcc -static -ggdb -Wall -Wextra -Wpedantic -o ghbn ghbn.c | |
// | |
int main(int argc, char * argv[]) { | |
if (argc!=2) { | |
exit(1); | |
} | |
struct hostent *hosts; | |
struct in_addr *address; | |
hosts = gethostbyname(argv[1]); | |
address = (struct in_addr *) (hosts->h_addr); | |
printf("%s\n",inet_ntoa(*address)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// | |
// go build -o ghbn-go ghbn.go | |
// | |
import ( | |
"fmt" | |
"net" | |
"os" | |
) | |
func main() { | |
hostname := os.Args[1] | |
addrs, err := net.LookupHost(hostname) | |
if err != nil { | |
fmt.Print("Error resolving ", hostname) | |
os.Exit(1) | |
} | |
for _, v := range addrs { | |
fmt.Print(v) | |
fmt.Print("\n") | |
} | |
} |
Author
brianredbeard
commented
May 16, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment