* getprotobyname failure
@ 2003-02-26 12:59 Yigit Can
2003-02-26 13:56 ` Richard B. Johnson
0 siblings, 1 reply; 6+ messages in thread
From: Yigit Can @ 2003-02-26 12:59 UTC (permalink / raw)
To: kernelnewbies, linux kernel, linux config, linux c programming
Hello,
I have a problem with getprotobyname() function.
I wrote a simple program that only uses getprotobyname function
I can run this program on my development machine
but when I try to run this program on my basic kernel it gives me the
"memory fault" error.
the "getprotobyname" function returns NULL and i don't know the reason,
becouse i have the /etc/protocols file containing "tcp 6 TCP" line
I'm using Denx embedded linux development kit with libc-2.2.5 with an cross
compiler
my development machine has celeron type processor
and my target board is TQM850L (powerpc 850)
I've replaced my protocols and nsswitch.conf files with host machines (my
protocols file contians "tcp 6 TCP" line)
and that's made no difference.
Why the getprotobyname function returns NULL?
please help,
my program :
#include <netdb.h>
#include <stdio.h>
int main(void){
struct sockaddr_in addr;
struct protoent *protocol=NULL;
protocol=getprotobyname("tcp");
printf("\n RESULT : %02x \n",protocol->p_proto);
return 0;
}
Yigit CAN
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: getprotobyname failure 2003-02-26 12:59 getprotobyname failure Yigit Can @ 2003-02-26 13:56 ` Richard B. Johnson 0 siblings, 0 replies; 6+ messages in thread From: Richard B. Johnson @ 2003-02-26 13:56 UTC (permalink / raw) To: Yigit Can; +Cc: kernelnewbies, linux c programming 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* getprotobyname failure
@ 2003-02-25 8:57 Yigit Can
2003-02-26 0:58 ` Glynn Clements
0 siblings, 1 reply; 6+ messages in thread
From: Yigit Can @ 2003-02-25 8:57 UTC (permalink / raw)
To: linux c programming, linux kernel
Hello,
I have a problem with getprotobyname() function.
I wrote a simple program that only uses getprotobyname function
I can run this program on my development machine=20
but when I try to run this program on my basic kernel it gives me the =
"memory fault" error.
I'm using libc-2.2.5 on a powerpc 8xx development kit
so, i'm using the same library on the host and target machine.
my development machine has celeron type processor
and my target board is TQM850L (has ppc_850 processor).
I've replaced my protocols and nsswitch.conf files with host machines (my
protocols file contians "tcp 6 TCP" line)
and that's made no difference.
what can I do?
please help,
my program :
#include <netdb.h>
#include <stdio.h>
int main(void){
struct sockaddr_in addr;
struct protoent *protocol=3DNULL;
protocol=3Dgetprotobyname("tcp");
printf("\n RESULT : %02x \n",protocol->p_proto);
return 0;
}
Yigit CAN
Karel Electronics Corp.
yigit.can@karel.com.tr
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: getprotobyname failure 2003-02-25 8:57 Yigit Can @ 2003-02-26 0:58 ` Glynn Clements 0 siblings, 0 replies; 6+ messages in thread From: Glynn Clements @ 2003-02-26 0:58 UTC (permalink / raw) To: Yigit Can; +Cc: linux c programming Yigit Can wrote: > I have a problem with getprotobyname() function. > > I wrote a simple program that only uses getprotobyname function > > I can run this program on my development machine > but when I try to run this program on my basic kernel it gives me > the "memory fault" error. > > I'm using libc-2.2.5 on a powerpc 8xx development kit > so, i'm using the same library on the host and target machine. > > my development machine has celeron type processor > and my target board is TQM850L (has ppc_850 processor). I presume that you have managed to get other programs to work by cross-compiling, right? > I've replaced my protocols and nsswitch.conf files with host machines (my > protocols file contians "tcp 6 TCP" line) > and that's made no difference. > > what can I do? > > please help, > > > my program : > > #include <netdb.h> > #include <stdio.h> > > int main(void){ > > struct sockaddr_in addr; > struct protoent *protocol=NULL; > protocol=getprotobyname("tcp"); > printf("\n RESULT : %02x \n",protocol->p_proto); You should check that the pointer which getprotobyname() returns is non-NULL before trying to dereference it. -- Glynn Clements <glynn.clements@virgin.net> ^ permalink raw reply [flat|nested] 6+ messages in thread
* getprotobyname failure
@ 2003-02-25 8:34 Yigit Can
2003-02-25 14:24 ` Jason Cooper
0 siblings, 1 reply; 6+ messages in thread
From: Yigit Can @ 2003-02-25 8:34 UTC (permalink / raw)
To: linux c programming, linux config, linux kernel
Hello,
I have a problem with getprotobyname() function.
I wrote a simple program that only uses getprotobyname function
I can run this program on my development machine=20
but when I try to run this program on my basic kernel it gives me the =
"memory fault" error.
I'm using libc-2.2.5 on a powerpc 8xx development kit
so, i'm using the same library on the host and target machine.
my development machine has celeron type processor
and my target board is TQM850L (has ppc_850 processor).
I've replaced my protocols and nsswitch.conf files with host machines (my
protocols file contians "tcp 6 TCP" line)
and that's made no difference.
what can I do?
please help,
my program :
#include <netdb.h>
#include <stdio.h>
int main(void){
struct sockaddr_in addr;
struct protoent *protocol=3DNULL;
protocol=3Dgetprotobyname("tcp");
printf("\n RESULT : %02x \n",protocol->p_proto);
return 0;
}
Yigit CAN
Karel Electronics Corp.
yigit.can@karel.com.tr
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: getprotobyname failure 2003-02-25 8:34 Yigit Can @ 2003-02-25 14:24 ` Jason Cooper 0 siblings, 0 replies; 6+ messages in thread From: Jason Cooper @ 2003-02-25 14:24 UTC (permalink / raw) To: linux-c-programming Yigit Can (yigit.can@karel.com.tr) wrote: > > I can run this program on my development machine=20 > but when I try to run this program on my basic kernel it gives me the = > "memory fault" error. > > I'm using libc-2.2.5 on a powerpc 8xx development kit > so, i'm using the same library on the host and target machine. > > my development machine has celeron type processor > and my target board is TQM850L (has ppc_850 processor). > > I've replaced my protocols and nsswitch.conf files with host machines (my > protocols file contians "tcp 6 TCP" line) > and that's made no difference. Yigit, My first guess would be byte order because of the different processors. Try this page out: http://www.ecst.csuchico.edu/~beej/guide/net/bgnet.pdf It is a beginners guide, however, it does talk a bit about byte order, etc. Cooper. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-02-26 13:56 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2003-02-26 12:59 getprotobyname failure Yigit Can 2003-02-26 13:56 ` Richard B. Johnson -- 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
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).