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") | |
} | |
} |
$ podman export ghbn-c | tar tvf -
drwxr-xr-t root/root 0 2020-05-15 19:47 dev/
drwxr-xr-x root/root 0 2020-05-15 19:47 etc/
-rwx------ root/root 0 2020-05-15 19:47 etc/hostname
-rwx------ root/root 0 2020-05-15 19:47 etc/hosts
-rwx------ root/root 0 2020-05-15 19:47 etc/resolv.conf
-rwxrwxr-x root/root 1843296 2020-05-15 18:15 ghbn
drwxr-xr-t root/root 0 2020-05-15 19:47 proc/
drwxr-xr-x root/root 0 2020-05-15 19:47 run/
-rwx------ root/root 0 2020-05-15 19:47 run/.containerenv
drwxr-xr-t root/root 0 2020-05-15 19:47 sys/
$ podman export ghbn-go | tar tvf -
drwxr-xr-t root/root 0 2020-05-15 19:46 dev/
drwxr-xr-x root/root 0 2020-05-15 19:46 etc/
-rwx------ root/root 0 2020-05-15 19:46 etc/hostname
-rwx------ root/root 0 2020-05-15 19:46 etc/hosts
-rwx------ root/root 0 2020-05-15 19:46 etc/resolv.conf
-rwxrwxr-x root/root 2929560 2020-05-15 19:08 ghbn
drwxr-xr-t root/root 0 2020-05-15 19:46 proc/
drwxr-xr-x root/root 0 2020-05-15 19:46 run/
-rwx------ root/root 0 2020-05-15 19:46 run/.containerenv
drwxr-xr-t root/root 0 2020-05-15 19:46 sys/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiled as:
Example execution (native host):
Example execution (Docker, C):
Example execution (Docker, Go):