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

  1. Newsgroups: comp.sys.sgi.misc
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!mars.cs.umn.edu!coyle
  3. From: coyle@mars.cs.umn.edu (Mark Stephan Coyle)
  4. Subject: Re: Gethostbyname Error
  5. Message-ID: <1992Dec21.181140.21504@news2.cis.umn.edu>
  6. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  7. Nntp-Posting-Host: mars.cs.umn.edu
  8. Organization: University of Minnesota
  9. References: <1992Dec21.033141.15406@news2.cis.umn.edu> <ts526sg@zuni.esd.sgi.com>
  10. Date: Mon, 21 Dec 1992 18:11:40 GMT
  11. Lines: 134
  12.  
  13. In <1992Dec21.033141.15406@news2.cis.umn.edu> coyle@mars.cs.umn.edu (Mark Stephan Coyle) writes:
  14. | I am programming on a 4D 310 VGX and am getting a segmentation fault
  15. | whenvever I use the system call "gethostbyname".  The code works on
  16. | other machines, bu not on this sgi.  Any clues?
  17.  
  18. Hard to say, w/o any backtrace or the relevant part of the code.
  19. Are you perhaps passing a bogus pointer?
  20.  
  21. While folks at SGI are willing to help, we aren't psychic...
  22.  
  23. *****It is sort of expected that anybody writing code is at least
  24. capable of getting backtraces with a debugger.
  25. --
  26. Let no one tell me that silence gives consent,  |   Dave Olson
  27. because whoever is silent dissents.             |   Silicon Graphics, Inc.
  28.     Maria Isabel Barreno                        |   olson@sgi.com
  29.  
  30.  
  31. ------------------------------------------------------------------------------
  32.  
  33. *****Well I am glad I fit in with what Dave expects from a programmer (-:)
  34.  
  35.  
  36.  
  37. Thanks for the response.  As I said, the code works fine on other machines,
  38. including Sparcs, Suns, and another SGI.  But on this machine, I get the following:
  39.  
  40.  
  41. dbx a.out
  42. dbx version 2.10 11/15/91 2:02
  43. Type 'help' for help.
  44. Reading symbolic information of `a.out' . . .
  45. main:29   29  sock=socket(AF_INET,SOCK_DGRAM,0);
  46. (dbx) run 2001
  47. Interrupt
  48. (dbx) run 2001
  49. Process 14353 (a.out) started
  50. Process 14353 (a.out) Segmentation fault [main:42 +0x8,0x4002d8]
  51.   42  bcopy(hp->h_addr, &(server.sin_addr.s_addr),hp->h_length);
  52. (dbx) where
  53. >  0 main(argc = 2, argv = 0x7fffc784) ["/usr/people/coyle/devel/flight/Sockets/i_net_send.c":42, 0x4002d8]
  54.  
  55.  
  56. Interstingly, and possibly connected, is what I get when I try to print
  57. out some simple tracing commands using printf.  Note that I segment fault
  58. if I do the gethostbyname call, and then use printf, even if I exit immediately after the printf call:
  59.  
  60.  
  61. (dbx) run 2001
  62. Process 14364 (a.out) started
  63. Process 14364 (a.out) Segmentation fault [_flsbuf:162 +0x8,0x4019ac]
  64.          Source (of flsbuf.c) not available for Process 14364
  65. (dbx) where
  66. >  0 _flsbuf(0x4d, 0x10000d84, 0x7fffbe48, 0x0, 0x0, 0x0) ["flsbuf.c":162, 0x4019ac]
  67.    1 _doprnt(0x10000d84, 0x7fffc1fc, 0x7fffbe48, 0x0, 0x0, 0x4002dc) ["doprnt.c":302, 0x403d34]
  68.    2 .printf.printf(0x10000490, 0x1000c8d0, 0x8, 0x0, 0x0, 0x0) ["printf.c":54, 0x400af4]
  69.    3 main(argc = 2, argv = 0x7fffc784) ["/usr/people/coyle/devel/flight/Sockets/i_net_send.c":41, 0x4002d8]
  70.  
  71.  
  72. I have  made a simple example of the code I am using, it still exhibits the
  73. same  problem:
  74.  
  75. #include <sys/types.h>
  76. #include <sys/socket.h>
  77. #include <netinet/in.h>
  78. #include <netdb.h>
  79. #include <stdio.h>
  80. #include <time.h>
  81. #define TRUE 1
  82. #define M_SOCKET 0x00000001
  83. int data[1024];
  84. struct hosttable {
  85. char hname[40];
  86. int worm;
  87. };
  88. clock_t start,end;
  89.  
  90.  
  91.  
  92. int main(int argc, char **argv)
  93. {
  94.         int sock ;
  95.         int i ;
  96.         struct sockaddr_in server;
  97.         struct hostent *hp, *gethostbyname();
  98.         char buf[1024];
  99.         char host[40];
  100.         char mtype;
  101.         char mcontent[40];
  102.         struct hosttable htable[5];
  103.                 sock=socket(AF_INET,SOCK_DGRAM,0);
  104.                 if(sock<0) {
  105.                         perror("opening stream socket");
  106.                         exit(0);
  107.                         };
  108.                 server.sin_port = htons(atoi(argv[1]));
  109.  
  110.                 server.sin_family=AF_INET;
  111.                 start=end=clock();
  112.                 while(TRUE){
  113.                 start=end=clock();
  114.                 printf("Made it past gethostbyname \n");
  115.                 hp=gethostbyname("dexter.psych.umn.edu");
  116.                 printf("Made it past gethostbyname \n");
  117.                 exit(1);
  118.                 bcopy(hp->h_addr, &(server.sin_addr.s_addr),hp->h_length);
  119.                 if(connect(sock,&server,sizeof(server))<0){
  120.                         perror("connecting datagram socket");
  121.                 }
  122.                         if(write(sock,data,sizeof(data))<0)
  123.                         perror("writing on stream socket");
  124.                 end=clock();
  125.          }
  126.  
  127.        
  128.  
  129. 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
  130. 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.
  131.  
  132.  
  133. Well,  hope this helps anyone in figuring out what is going on.
  134.  
  135.  
  136. thanks in advance
  137.  
  138.  
  139. Mark S Coyle
  140. Computer Science Dept
  141. Univ of Minnesota
  142. Minneapolis, Mn
  143.  
  144.  
  145.  
  146.  
  147.