Home > Software engineering >  In which library write writev and other functions that operate on socket like send also and where is
In which library write writev and other functions that operate on socket like send also and where is

Time:12-19

I like to run this command to look for function names similar to sendfile, send, write writev on my some system library or kernel. command

nm -D /usr/lib/libopenal.so.1 //or T option

But I don't know where to look for these functions exact name the idea is I just run the above command with piping with grep so I can get exact names of functions like sendfile,

Someone told me then write may have name 64__sys_write which is king of correct, maybe its some other function so I like to know can I get this info on ubuntu linux

CodePudding user response:

But I don't know where to look for these functions

You don't need to know where to look, but you should learn how to find out answers to trivial questions (like this one) on your own.

Here are steps you could have used:

  1. Select a program which exercises the function(s) you are interested in. In the case of send, nc and telnet seem like good potential candidates.
  2. Verify that indeed the selected program calls send:
nm -AD $(which nc telnet) | grep ' send'
/usr/bin/nc:                 U sendmsg@GLIBC_2.2.5
/usr/bin/telnet:                 U send@GLIBC_2.2.5

Ok, suppose we are interested in send only, so telnet is our "target" and nc isn't.

  1. Find out which libraries telnet uses:
ldd /usr/bin/telnet
        linux-vdso.so.1 (0x00007ffe957d4000)
        libstdc  .so.6 => /lib/x86_64-linux-gnu/libstdc  .so.6 (0x00007f2f2e2f4000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2f2e12f000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2f2dfea000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f2f2e53c000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2f2dfd0000)

The function send must be defined in one of these. Which one?

  1. Run nm -D | grep ' send' on each one, to find that the function is defined in libc.so.6:
nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep ' send'
00000000000fee60 W send@@GLIBC_2.2.5
00000000000f3430 T sendfile@@GLIBC_2.2.5
00000000000f3430 W sendfile64@@GLIBC_2.3
00000000000ff520 W sendmmsg@@GLIBC_2.14
00000000000fef20 W sendmsg@@GLIBC_2.2.5
00000000000fefc0 W sendto@@GLIBC_2.2.5

Bonus: you've found out that sendfile is also defined in libc.so.6.

  • Related