home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sgi.misc
- Path: sparky!uunet!spool.mu.edu!sgiblab!sgigate!sgi!xingping.esd.sgi.com!arc
- From: arc@xingping.esd.sgi.com (Andrew Cherenson)
- Subject: Re: Gethostbyname Error
- Message-ID: <tt4p428@sgi.sgi.com>
- Sender: arc@xingping.esd.sgi.com
- Organization: Silicon Graphics, Inc. Mountain View, CA
- Date: Tue, 22 Dec 1992 00:22:31 GMT
- Lines: 61
-
- The following code doesn't coredump for me on 4.0.5:
- Made it past gethostbyname
- Made it past gethostbyname
- It's important to make sure hp isn't NULL before using it.
-
- In article <1992Dec21.181140.21504@news2.cis.umn.edu> coyle@mars.cs.umn.edu (Mark Stephan Coyle) writes:
- >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();
- > }
-
-