From: "Richard B. Johnson" <root@chaos.analogic.com>
To: Yigit Can <yigit.can@karel.com.tr>
Cc: kernelnewbies <kernelnewbies@nl.linux.org>,
linux c programming <linux-c-programming@vger.kernel.org>
Subject: Re: getprotobyname failure
Date: Wed, 26 Feb 2003 08:56:18 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.3.95.1030226084926.2982A-100000@chaos> (raw)
In-Reply-To: <001d01c2dd96$eac076f0$3002a8c0@yigitcan>
On Wed, 26 Feb 2003, Yigit Can wrote:
> Hello,
>
> I have a problem with getprotobyname() function.
>
> I wrote a simple program that only uses getprotobyname function
[SNIPPED...]
getprotobyname() has nothing to do with linux-kernel so you should
not have sent your inquiry to the linux-kernel list. This is one
of the functions that is provided by your 'C' runtime library.
Here is an example of it working....
Script started on Wed Feb 26 08:46:40 2003
# cat xxx.c
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
int main(void){
struct protoent *protocol=NULL;
protocol=getprotobyname("tcp");
printf("\n RESULT : %02x \n",protocol->p_proto);
return 0;
}
# gcc -Wall -o xxx -O2 xxx.c
# xxx
RESULT : 06
# # Works. Now you can `strace` it to see why yours doesn't.
# strace xxx
execve("./xxx", ["xxx"], [/* 32 vars */]) = 0
brk(0) = 0x8049680
open("/etc/ld.so.preload", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
old_mmap(NULL, 0, PROT_READ|PROT_WRITE, MAP_PRIVATE, 3, 0) = 0
close(3) = 0
open("/lib/libc.so.6", O_RDONLY) = 3
old_mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, 3, 0) = 0x4000c000
munmap(0x4000c000, 4096) = 0
old_mmap(NULL, 644232, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x4000c000
mprotect(0x40097000, 74888, PROT_NONE) = 0
old_mmap(0x40097000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x8b000) = 0x40097000
old_mmap(0x4009d000, 50312, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4009d000
close(3) = 0
mprotect(0x4000c000, 569344, PROT_READ|PROT_WRITE) = 0
mprotect(0x4000c000, 569344, PROT_READ|PROT_EXEC) = 0
personality(PER_LINUX) = 0
getpid() = 2974
brk(0) = 0x8049680
brk(0x8049a98) = 0x8049a98
brk(0x804a000) = 0x804a000
open("/etc/nsswitch.conf", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1261, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400aa000
read(3, "#\n# /etc/nsswitch.conf\n#\n# An ex"..., 4096) = 1261
brk(0x804b000) = 0x804b000
read(3, "", 4096) = 0
close(3) = 0
munmap(0x400aa000, 4096) = 0
open("/lib/libnss_nisplus.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib//libnss_nisplus.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/intel/compiler50/ia32/lib/libnss_nisplus.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/X11R6/lib/libnss_nisplus.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/Office50/lib/libnss_nisplus.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/java/lib/i686/libnss_nisplus.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=16707, ...}) = 0
old_mmap(NULL, 16707, PROT_READ, MAP_PRIVATE, 3, 0) = 0x400aa000
close(3) = 0
open("/usr/local/lib/libnss_nisplus.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libnss_files.so.1", O_RDONLY) = 3
old_mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, 3, 0) = 0x400af000
munmap(0x400af000, 4096) = 0
old_mmap(NULL, 35156, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x400af000
mprotect(0x400b7000, 2388, PROT_NONE) = 0
old_mmap(0x400b7000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x7000) = 0x400b7000
close(3) = 0
mprotect(0x400af000, 32768, PROT_READ|PROT_WRITE) = 0
mprotect(0x400af000, 32768, PROT_READ|PROT_EXEC) = 0
open("/etc/protocols", O_RDONLY) = 3
fcntl(3, F_GETFD) = 0
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=715, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400b8000
read(3, "#\n# protocols\tThis file describe"..., 4096) = 715
close(3) = 0
munmap(0x400b8000, 4096) = 0
fstat(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(3, 0), ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400b8000
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(1, "\n", 1
) = 1
write(1, " RESULT : 06 \n", 14 RESULT : 06
) = 14
munmap(0x400b8000, 4096) = 0
_exit(0) = ?
# exit
exit
Script done on Wed Feb 26 08:47:08 2003
If you are not running from an ix86 PC, you may need to
link in another library when you compile the code. For instance,
on my Sun workstation, I have to do...
gcc -Wall -O2 -o xxx xxx.c -lsocket -lnsl
... to load all the libraries I need for networking. It's just
the same as when you do floating-point math, you need to load
the math libraries with '-lm'
Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.
next prev parent reply other threads:[~2003-02-26 13:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-26 12:59 getprotobyname failure Yigit Can
2003-02-26 13:56 ` Richard B. Johnson [this message]
-- strict thread matches above, loose matches on Subject: below --
2003-02-25 8:57 Yigit Can
2003-02-26 0:58 ` Glynn Clements
2003-02-25 8:34 Yigit Can
2003-02-25 14:24 ` Jason Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.3.95.1030226084926.2982A-100000@chaos \
--to=root@chaos.analogic.com \
--cc=kernelnewbies@nl.linux.org \
--cc=linux-c-programming@vger.kernel.org \
--cc=yigit.can@karel.com.tr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).