I want to see the source of functions like ns_initparse(), res_search() etc. Where can I look for them?
3 Answers
Here's are the steps I take find the source for res_search
.
$ man res_search
I see in that man page: Link with -lresolv
$ ls /usr/lib/libresolv*
Oops, nothing there. Where else do we look? How about:
$ ls /lib/libresolv* /lib/libresolv-2.7.so /lib/libresolv.so.2
Great. Now what package is that from?
$ rpm -qf /lib/libresolv-2.7.so glibc-2.7-2
Ah. It's in glibc
. Now, there are two choices. I can fetch the source RPMs, and look through those, in order to get the exact version that that my system was built from, but that's a bit complicated to set up.
If you don't need the exact source RPM that you were built from, you can instead look through the [upstream](http://en.wikipedia.org/wiki/Upstream_(software_development)) source code. Just look around the glibc
site to find the source code, and start looking through there.
$ curl -O http://ftp.gnu.org/gnu/glibc/glibc-2.7.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 20.2M 100 20.2M 0 0 12.3M 0 0:00:01 0:00:01 --:--:-- 12.8M $ tar xzf glibc-2.7.tar.gz $ cd glibc-2.7 $ find . -name "*.c" | xargs grep res_search ./resolv/res_data.c:res_search(const char *name, /* domain name */ ./resolv/res_data.c:# undef res_search ./resolv/res_data.c:weak_alias (__res_search, res_search);
And there you have it!
If you have Git installed, instead of just downloading the tarball, you could clone the git repo, and look through that. That way, you can also look at any past or future version, to see how it's changed over time.
$ git clone git://sourceware.org/git/glibc.git $ cd glibc $ git checkout glibc-2.7 $ git grep res_search resolv/res_data.c:res_search(const char *name, /* domain name */ resolv/res_data.c:# undef res_search resolv/res_data.c:weak_alias (__res_search, res_search);

- 322,767
- 57
- 360
- 340
I am not sure if you are interested in Fedora specific stuff, but I have had good luck with Google Code Search for finding source code for certain functions.

- 12,799
- 11
- 66
- 80
-
Thank u very much. This is a great link. I did not know that we search functions at google code. – avd Nov 08 '09 at 05:49
-
The chances are that those library functions are not Fedora specific. – Stephen C Nov 08 '09 at 06:22
-
Google Code Search is now dead. But see http://stackoverflow.com/questions/7778034/replacement-for-google-code-search for various replacements. – jjlin Jul 26 '13 at 23:36
Once you figure out which package provides the functions you are interested in, all you need to do on Fedora is debuginfo-install glibc-2.7-2
. More info here.

- 199,314
- 34
- 295
- 362