Posix sockets function getaddrinfo not returning correct IP addresses
Hello, I am attempting to resolve the domain name "www.google.com" using the function "getaddrinfo()". I used the command strace to try and see if I could spot the issue but to no avail. I posted my code and the output of the strace command with the executable compiled from the posted code. I would greatly appreciate any help! Thank you in advance!
Code:
#include <stdio.h> |
Here is the first half of the strace output...
execve("./main", ["./main"], [/* 39 vars */]) = 0 brk(0) = 0x13ad000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e17000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=83408, ...}) = 0 mmap(NULL, 83408, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc649e02000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\355\1\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1437064, ...}) = 0 mmap(NULL, 3545160, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc64989a000 mprotect(0x7fc6499f3000, 2093056, PROT_NONE) = 0 mmap(0x7fc649bf2000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x158000) = 0x7fc649bf2000 mmap(0x7fc649bf7000, 18504, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc649bf7000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e01000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e00000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649dff000 arch_prctl(ARCH_SET_FS, 0x7fc649e00700) = 0 mprotect(0x7fc649bf2000, 16384, PROT_READ) = 0 mprotect(0x7fc649e19000, 4096, PROT_READ) = 0 munmap(0x7fc649e02000, 83408) = 0 socket(PF_NETLINK, SOCK_RAW, 0) = 3 bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0 getsockname(3, {sa_family=AF_NETLINK, pid=4539, groups=00000000}, [12]) = 0 sendto(3, "\24\0\0\0\26\0\1\3\337\23\337R\0\0\0\0\0\0\0\0", 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20 recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"0\0\0\0\24\0\2\0\337\23\337R\273\21\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 108 recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"@\0\0\0\24\0\2\0\337\23\337R\273\21\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 128 recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0\337\23\337R\273\21\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 20 close(3) = 0 brk(0) = 0x13ad000 brk(0x13ce000) = 0x13ce000 socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3 connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) close(3) = 0 socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3 connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) close(3) = 0 open("/etc/nsswitch.conf", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=513, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e16000 read(3, "# /etc/nsswitch.conf\n#\n# Example"..., 4096) = 513 read(3, "", 4096) = 0 close(3) = 0 munmap(0x7fc649e16000, 4096) = 0 open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=83408, ...}) = 0 mmap(NULL, 83408, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc649e02000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/tls/x86_64/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/lib/tls/x86_64", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/lib/tls/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/lib/tls", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/lib/x86_64/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/lib/x86_64", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/lib/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/lib", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0 open("/usr/lib/tls/x86_64/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib/tls/x86_64", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/usr/lib/tls/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib/tls", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 open("/usr/lib/x86_64/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib/x86_64", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/usr/lib/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib", {st_mode=S_IFDIR|0755, st_size=81920, ...}) = 0 open("/lib/x86_64-linux-gnu/tls/x86_64/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/lib/x86_64-linux-gnu/tls/x86_64", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/tls/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/lib/x86_64-linux-gnu/tls", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/x86_64/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/lib/x86_64-linux-gnu/x86_64", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib/x86_64-linux-gnu/tls/x86_64", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/usr/lib/x86_64-linux-gnu/tls/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib/x86_64-linux-gnu/tls", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/usr/lib/x86_64-linux-gnu/x86_64/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib/x86_64-linux-gnu/x86_64", 0x7fff37a8a900) = -1 ENOENT (No such file or directory) open("/usr/lib/x86_64-linux-gnu/libnss_db.so.2", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 munmap(0x7fc649e02000, 83408) = 0 open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=83408, ...}) = 0 mmap(NULL, 83408, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc649e02000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libnss_files.so.2", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\"\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=51728, ...}) = 0 mmap(NULL, 2147752, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc64968d000 mprotect(0x7fc649699000, 2093056, PROT_NONE) = 0 mmap(0x7fc649898000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xb000) = 0x7fc649898000 close(3) = 0 mprotect(0x7fc649898000, 4096, PROT_READ) = 0 munmap(0x7fc649e02000, 83408) = 0 open("/etc/services", O_RDONLY|O_CLOEXEC) = 3 fcntl(3, F_GETFD) = 0x1 (flags FD_CLOEXEC) fstat(3, {st_mode=S_IFREG|0644, st_size=19666, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e16000 read(3, "# Network services, Internet sty"..., 4096) = 4096 close(3) = 0 munmap(0x7fc649e16000, 4096) = 0 getpid() = 4539 open("/etc/resolv.conf", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=89, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e16000 read(3, "# Generated by NetworkManager\ndo"..., 4096) = 89 read(3, "", 4096) = 0 close(3) = 0 munmap(0x7fc649e16000, 4096) = 0 socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3 connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) close(3) = 0 socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3 connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) close(3) |
And here is the second half of the strace output
open("/etc/host.conf", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=9, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e16000 read(3, "multi on\n", 4096) = 9 read(3, "", 4096) = 0 close(3) = 0 munmap(0x7fc649e16000, 4096) = 0 open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=223, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e16000 read(3, "127.0.0.1\tlocalhost\n127.0.1.1\tOV"..., 4096) = 223 read(3, "", 4096) = 0 close(3) = 0 munmap(0x7fc649e16000, 4096) = 0 open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=83408, ...}) = 0 mmap(NULL, 83408, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc649e02000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libnss_mdns4_minimal.so.2", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \v\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=9456, ...}) = 0 mmap(NULL, 2104672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc64948b000 mprotect(0x7fc64948d000, 2093056, PROT_NONE) = 0 mmap(0x7fc64968c000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7fc64968c000 close(3) = 0 munmap(0x7fc649e02000, 83408) = 0 open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=83408, ...}) = 0 mmap(NULL, 83408, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc649e02000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libnss_dns.so.2", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\20\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=22928, ...}) = 0 mmap(NULL, 2117888, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc649285000 mprotect(0x7fc64928a000, 2093056, PROT_NONE) = 0 mmap(0x7fc649489000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4000) = 0x7fc649489000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libresolv.so.2", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\3008\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=80712, ...}) = 0 mmap(NULL, 2185864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc64906f000 mprotect(0x7fc649082000, 2093056, PROT_NONE) = 0 mmap(0x7fc649281000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12000) = 0x7fc649281000 mmap(0x7fc649283000, 6792, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc649283000 close(3) = 0 mprotect(0x7fc649281000, 4096, PROT_READ) = 0 mprotect(0x7fc649489000, 4096, PROT_READ) = 0 munmap(0x7fc649e02000, 83408) = 0 stat("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=89, ...}) = 0 open("/etc/resolv.conf", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=89, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e16000 read(3, "# Generated by NetworkManager\ndo"..., 4096) = 89 read(3, "", 4096) = 0 close(3) = 0 munmap(0x7fc649e16000, 4096) = 0 socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3 connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, 16) = 0 poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}]) sendto(3, "\303<\1\0\0\1\0\0\0\0\0\0\3www\6google\3com\0\0\1\0\1", 32, MSG_NOSIGNAL, NULL, 0) = 32 poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}]) ioctl(3, FIONREAD, [112]) = 0 recvfrom(3, "\303<\201\200\0\1\0\5\0\0\0\0\3www\6google\3com\0\0\1\0\1"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, [16]) = 112 close(3) = 0 stat("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=89, ...}) = 0 open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=223, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e16000 read(3, "127.0.0.1\tlocalhost\n127.0.1.1\tOV"..., 4096) = 223 read(3, "", 4096) = 0 close(3) = 0 munmap(0x7fc649e16000, 4096) = 0 stat("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=89, ...}) = 0 socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3 connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, 16) = 0 poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}]) sendto(3, "\375\223\1\0\0\1\0\0\0\0\0\0\3www\6google\3com\0\0\1\0\1", 32, MSG_NOSIGNAL, NULL, 0) = 32 poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}]) ioctl(3, FIONREAD, [112]) = 0 recvfrom(3, "\375\223\201\200\0\1\0\5\0\0\0\0\3www\6google\3com\0\0\1\0\1"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, [16]) = 112 close(3) = 0 open("/etc/gai.conf", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=2940, ...}) = 0 fstat(3, {st_mode=S_IFREG|0644, st_size=2940, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc649e16000 read(3, "# Configuration for getaddrinfo("..., 4096) = 2940 read(3, "", 4096) = 0 close(3) = 0 munmap(0x7fc649e16000, 4096) = 0 socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3 connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("74.125.228.112")}, 16) = 0 getsockname(3, {sa_family=AF_INET, sin_port=htons(44680), sin_addr=inet_addr("192.168.0.11")}, [16]) = 0 connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("74.125.228.116")}, 16) = 0 getsockname(3, {sa_family=AF_INET, sin_port=htons(50853), sin_addr=inet_addr("192.168.0.11")}, [16]) = 0 connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("74.125.228.115")}, 16) = 0 getsockname(3, {sa_family=AF_INET, sin_port=htons(50596), sin_addr=inet_addr("192.168.0.11")}, [16]) = 0 connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("74.125.228.114")}, 16) = 0 getsockname(3, {sa_family=AF_INET, sin_port=htons(42541), sin_addr=inet_addr("192.168.0.11")}, [16]) = 0 connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("74.125.228.113")}, 16) = 0 getsockname(3, {sa_family=AF_INET, sin_port=htons(42429), sin_addr=inet_addr("192.168.0.11")}, [16]) = 0 close(3) = 0 write(2, "IP address: [ 2.0.0.80 ]\n", 25IP address: [ 2.0.0.80 ] ) = 25 write(2, "IP address: [ 2.0.0.80 ]\n", 25IP address: [ 2.0.0.80 ] ) = 25 write(2, "IP address: [ 2.0.0.80 ]\n", 25IP address: [ 2.0.0.80 ] ) = 25 write(2, "IP address: [ 2.0.0.80 ]\n", 25IP address: [ 2.0.0.80 ] ) = 25 write(2, "IP address: [ 2.0.0.80 ]\n", 25IP address: [ 2.0.0.80 ] ) = 25 exit_group(0) = ? |
All times are GMT -5. The time now is 05:36 AM. |