home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / sgi / misc / 67 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.2 KB  |  72 lines

  1. Newsgroups: comp.sys.sgi.misc
  2. Path: sparky!uunet!spool.mu.edu!sgiblab!sgigate!sgi!xingping.esd.sgi.com!arc
  3. From: arc@xingping.esd.sgi.com (Andrew Cherenson)
  4. Subject: Re: Gethostbyname Error
  5. Message-ID: <tt4p428@sgi.sgi.com>
  6. Sender: arc@xingping.esd.sgi.com
  7. Organization: Silicon Graphics, Inc.  Mountain View, CA
  8. Date: Tue, 22 Dec 1992 00:22:31 GMT
  9. Lines: 61
  10.  
  11. The following code doesn't coredump for me on 4.0.5:
  12.     Made it past gethostbyname 
  13.     Made it past gethostbyname 
  14. It's important to make sure hp isn't NULL before using it.
  15.  
  16. In article <1992Dec21.181140.21504@news2.cis.umn.edu> coyle@mars.cs.umn.edu (Mark Stephan Coyle) writes:
  17. >I have  made a simple example of the code I am using, it still exhibits the
  18. >same  problem:
  19. >
  20. >#include <sys/types.h>
  21. >#include <sys/socket.h>
  22. >#include <netinet/in.h>
  23. >#include <netdb.h>
  24. >#include <stdio.h>
  25. >#include <time.h>
  26. >#define TRUE 1
  27. >#define M_SOCKET 0x00000001
  28. >int data[1024];
  29. >struct hosttable {
  30. >char hname[40];
  31. >int worm;
  32. >};
  33. >clock_t start,end;
  34. >
  35. >
  36. >
  37. >int main(int argc, char **argv)
  38. >{
  39. >        int sock ;
  40. >        int i ;
  41. >        struct sockaddr_in server;
  42. >        struct hostent *hp, *gethostbyname();
  43. >        char buf[1024];
  44. >        char host[40];
  45. >        char mtype;
  46. >        char mcontent[40];
  47. >        struct hosttable htable[5];
  48. >                sock=socket(AF_INET,SOCK_DGRAM,0);
  49. >                if(sock<0) {
  50. >                        perror("opening stream socket");
  51. >                        exit(0);
  52. >                        };
  53. >                server.sin_port = htons(atoi(argv[1]));
  54. >
  55. >                server.sin_family=AF_INET;
  56. >                start=end=clock();
  57. >                while(TRUE){
  58. >                start=end=clock();
  59. >                printf("Made it past gethostbyname \n");
  60. >                hp=gethostbyname("dexter.psych.umn.edu");
  61. >                printf("Made it past gethostbyname \n");
  62. >                exit(1);
  63. >                bcopy(hp->h_addr, &(server.sin_addr.s_addr),hp->h_length);
  64. >                if(connect(sock,&server,sizeof(server))<0){
  65. >                        perror("connecting datagram socket");
  66. >                }
  67. >                        if(write(sock,data,sizeof(data))<0)
  68. >                        perror("writing on stream socket");
  69. >                end=clock();
  70. >         }
  71.  
  72.