Kooiomo
Kooiomo

Reputation: 55

getnameinfo -- what's syscall for it in Linux?

There's a function https://linux.die.net/man/3/getnameinfo How do I know what the syscall for it is? There's no such a function in Linux syscall table. Or does exist only in that C library?

Upvotes: 3

Views: 3238

Answers (1)

jxh
jxh

Reputation: 70472

getnameinfo has no direct system call. It is a library function that performs a number of activities to fulfill the request. For example, when looking up the host name, it will likely try to:

  • consult local files (such as /etc/nsswitch.conf and /etc/hosts)
  • find the IP address of its DNS server (read /etc/resolv.conf)
  • perform socket writes and reads using the DNS protocol to ask for the host name

If you write a simple application using the getnameinfo API correctly, you can then use the strace utility to find out what system calls are being used. There will be a lot of extra information, but if you study it carefully, you will see the relevant calls being made. A few lines of the relevant output on my system:

...
open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
...
open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 3
...
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, 16) = 0
...

Upvotes: 5

Related Questions