Thread View: comp.sys.sgi.misc
5 messages
5 total messages
Started by Mark Stephan Coyle
Mon, 21 Dec 1992 03:31
Gethostbyname Error
Author: Mark Stephan Coyle
Date: Mon, 21 Dec 1992 03:31
Date: Mon, 21 Dec 1992 03:31
20 lines
948 bytes
948 bytes
Hi, I am programming on a 4D 310 VGX and am getting a segmentation fault whenvever I use the system call "gethostbyname". The code works on other machines, bu not on this sgi. Any clues? thanks in advance Mark S. Coyle ------------------------------------------------------------------------- Computer Science Department Human Factors Research Lab University of Minnesota Minneapolis, Mn coyle@mars.cs.umn.edu coyle@dexter.psych.umn.edu
Re: Gethostbyname Error
Author: Dave Olson
Date: Mon, 21 Dec 1992 06:19
Date: Mon, 21 Dec 1992 06:19
16 lines
1218 bytes
1218 bytes
In <1992Dec21.033141.15406@news2.cis.umn.edu> coyle@mars.cs.umn.edu (Mark Stephan Coyle) writes:
| I am programming on a 4D 310 VGX and am getting a segmentation fault
| whenvever I use the system call "gethostbyname". The code works on
| other machines, bu not on this sgi. Any clues?
Hard to say, w/o any backtrace or the relevant part of the code.
Are you perhaps passing a bogus pointer?
While folks at SGI are willing to help, we aren't psychic...
It is sort of expected that anybody writing code is at least
capable of getting backtraces with a debugger.
--
Let no one tell me that silence gives consent, | Dave Olson
because whoever is silent dissents. | Silicon Graphics, Inc.
Maria Isabel Barreno | olson@sgi.com
Re: Gethostbyname Error
Author: Mark Stephan Coyle
Date: Mon, 21 Dec 1992 18:11
Date: Mon, 21 Dec 1992 18:11
130 lines
5176 bytes
5176 bytes
In <1992Dec21.033141.15406@news2.cis.umn.edu> coyle@mars.cs.umn.edu (Mark Stephan Coyle) writes:
| I am programming on a 4D 310 VGX and am getting a segmentation fault
| whenvever I use the system call "gethostbyname". The code works on
| other machines, bu not on this sgi. Any clues?
Hard to say, w/o any backtrace or the relevant part of the code.
Are you perhaps passing a bogus pointer?
While folks at SGI are willing to help, we aren't psychic...
*****It is sort of expected that anybody writing code is at least
capable of getting backtraces with a debugger.
--
Let no one tell me that silence gives consent, | Dave Olson
because whoever is silent dissents. | Silicon Graphics, Inc.
Maria Isabel Barreno | olson@sgi.com
------------------------------------------------------------------------------
*****Well I am glad I fit in with what Dave expects from a programmer (-:)
Thanks for the response. As I said, the code works fine on other machines,
including Sparcs, Suns, and another SGI. But on this machine, I get the following:
dbx a.out
dbx version 2.10 11/15/91 2:02
Type 'help' for help.
Reading symbolic information of `a.out' . . .
main:29 29 sock=socket(AF_INET,SOCK_DGRAM,0);
(dbx) run 2001
Interrupt
(dbx) run 2001
Process 14353 (a.out) started
Process 14353 (a.out) Segmentation fault [main:42 +0x8,0x4002d8]
42 bcopy(hp->h_addr, &(server.sin_addr.s_addr),hp->h_length);
(dbx) where
> 0 main(argc = 2, argv = 0x7fffc784) ["/usr/people/coyle/devel/flight/Sockets/i_net_send.c":42, 0x4002d8]
Interstingly, and possibly connected, is what I get when I try to print
out some simple tracing commands using printf. Note that I segment fault
if I do the gethostbyname call, and then use printf, even if I exit immediately after the printf call:
(dbx) run 2001
Process 14364 (a.out) started
Process 14364 (a.out) Segmentation fault [_flsbuf:162 +0x8,0x4019ac]
Source (of flsbuf.c) not available for Process 14364
(dbx) where
> 0 _flsbuf(0x4d, 0x10000d84, 0x7fffbe48, 0x0, 0x0, 0x0) ["flsbuf.c":162, 0x4019ac]
1 _doprnt(0x10000d84, 0x7fffc1fc, 0x7fffbe48, 0x0, 0x0, 0x4002dc) ["doprnt.c":302, 0x403d34]
2 .printf.printf(0x10000490, 0x1000c8d0, 0x8, 0x0, 0x0, 0x0) ["printf.c":54, 0x400af4]
3 main(argc = 2, argv = 0x7fffc784) ["/usr/people/coyle/devel/flight/Sockets/i_net_send.c":41, 0x4002d8]
I have made a simple example of the code I am using, it still exhibits the
same problem:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <time.h>
#define TRUE 1
#define M_SOCKET 0x00000001
int data[1024];
struct hosttable {
char hname[40];
int worm;
};
clock_t start,end;
int main(int argc, char **argv)
{
int sock ;
int i ;
struct sockaddr_in server;
struct hostent *hp, *gethostbyname();
char buf[1024];
char host[40];
char mtype;
char mcontent[40];
struct hosttable htable[5];
sock=socket(AF_INET,SOCK_DGRAM,0);
if(sock<0) {
perror("opening stream socket");
exit(0);
};
server.sin_port = htons(atoi(argv[1]));
server.sin_family=AF_INET;
start=end=clock();
while(TRUE){
start=end=clock();
printf("Made it past gethostbyname \n");
hp=gethostbyname("dexter.psych.umn.edu");
printf("Made it past gethostbyname \n");
exit(1);
bcopy(hp->h_addr, &(server.sin_addr.s_addr),hp->h_length);
if(connect(sock,&server,sizeof(server))<0){
perror("connecting datagram socket");
}
if(write(sock,data,sizeof(data))<0)
perror("writing on stream socket");
end=clock();
}
Note that I will segment fault wven with this code. My earlier hypothesis that it is in the gethostbyname is now not entirely true, but the call to gethostbyname is doing somthing to cause the program to crash. The printf
before the gethostbyname call works fine, but the printf after the call causes a crash (see the second example of crashing above) even with the exit call.
Well, hope this helps anyone in figuring out what is going on.
thanks in advance
Mark S Coyle
Computer Science Dept
Univ of Minnesota
Minneapolis, Mn
Re: Gethostbyname Error
Author: Steve Gallichio
Date: Tue, 22 Dec 1992 15:54
Date: Tue, 22 Dec 1992 15:54
40 lines
2005 bytes
2005 bytes
Mark Stephan Coyle:
> I am programming on a 4D 310 VGX and am getting a segmentation fault
> whenvever I use the system call "gethostbyname". The code works on
> other machines, bu not on this sgi. Any clues?
Dave (the Psychic Debugger) Olson:
> Are you perhaps passing a bogus pointer?
Andrew Cherenson:
> It's important to make sure hp isn't NULL before using it.
RTFM gethostbyname:
> There are two versions of the routines documented in this manual entry:
> the standard C library version and the NIS version in /usr/lib/libsun.a.
> The programmatic interface of both versions is identical, except for
> gethostent. The standard version is the default; if you want the NIS
> version, follow the instructions for (3Y) routines in intro(3). The
> differences are described below.
[...make sure to include -lsun BEFORE -lc_s if you are including
the c library on the link line... (ed)]
>
> LIBC VERSION
> The default resolution order is: query the BIND name server first, if is
> not configured, then search /etc/hosts.
>
> NIS VERSION
> If NIS is enabled, gethostbyname and gethostbyaddr access the NIS
> databases. Otherwise, they use the same resolution order as the libc
> versions.
My guess is that you want to pick up the NIS entry for dexter.psych.umn.edu
but are not getting it without the linking of -lsun.
Hope this helps...now back to my tarot cards.
--
Steve Gallichio |"Have you ever heard of Plato? Aristotle? Socrates?
Cadkey, Inc. | ...Morons!"
steveg@cadkey.com |
Re: Gethostbyname Error
Author: Dave Olson
Date: Wed, 23 Dec 1992 04:48
Date: Wed, 23 Dec 1992 04:48
37 lines
2059 bytes
2059 bytes
In <1992Dec21.181140.21504@news2.cis.umn.edu> coyle@mars.cs.umn.edu (Mark Stephan Coyle) writes:
| *****Well I am glad I fit in with what Dave expects from a programmer (-:)
|
|
|
| Thanks for the response. As I said, the code works fine on other machines,
| including Sparcs, Suns, and another SGI. But on this machine, I get the following:
|
|
| dbx a.out
| dbx version 2.10 11/15/91 2:02
| Type 'help' for help.
| Reading symbolic information of `a.out' . . .
| main:29 29 sock=socket(AF_INET,SOCK_DGRAM,0);
| (dbx) run 2001
| Interrupt
| (dbx) run 2001
| Process 14353 (a.out) started
| Process 14353 (a.out) Segmentation fault [main:42 +0x8,0x4002d8]
| 42 bcopy(hp->h_addr, &(server.sin_addr.s_addr),hp->h_length);
| (dbx) where
| > 0 main(argc = 2, argv = 0x7fffc784) ["/usr/people/coyle/devel/flight/Sockets/i_net_send.c":42, 0x4002d8]
|
|
| Interstingly, and possibly connected, is what I get when I try to print
| out some simple tracing commands using printf. Note that I segment fault
| if I do the gethostbyname call, and then use printf, even if I exit immediately after the printf call:
Your test program works fine for me, -O, and -g, on 3 different
machines, with 3 different OS's and development releases...
That is whether the gethostbyname succeeds or fails (I tried
both).
--
Let no one tell me that silence gives consent, | Dave Olson
because whoever is silent dissents. | Silicon Graphics, Inc.
Maria Isabel Barreno | olson@sgi.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads