🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sgi.misc
Article #40

Re: Gethostbyname Error

#40
From: Mark Stephan Coyle
Date: Mon, 21 Dec 1992 18:11
130 lines
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
Technical Details
Message-ID: <1992Dec21.181140.21504@news2.cis.umn.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!umn.edu!mars.cs.umn.edu!coyle
References: <1992Dec21.033141.15406@news2.cis.umn.edu> <ts526sg@zuni.esd.sgi.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.sgi.misc
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!umn.edu!mars.cs.umn.edu!coyle
From: coyle@mars.cs.umn.edu (Mark Stephan Coyle)
Subject: Re: Gethostbyname Error
Message-ID: <1992Dec21.181140.21504@news2.cis.umn.edu>
Sender: news@news2.cis.umn.edu (Usenet News Administration)
Nntp-Posting-Host: mars.cs.umn.edu
Organization: University of Minnesota
References: <1992Dec21.033141.15406@news2.cis.umn.edu> <ts526sg@zuni.esd.sgi.com>
Date: Mon, 21 Dec 1992 18:11:40 GMT
Lines: 134