home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / linux / 9489 < prev    next >
Encoding:
Text File  |  1992-08-31  |  1.2 KB  |  43 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!era!ejb
  3. From: ejb@ERA.COM (Jay Berkenbilt)
  4. Subject: gcc 2.2.2d: htonl, etc. problem with -O and netinet/in.h
  5. Message-ID: <1992Aug31.151452.26313@ERA.COM>
  6. Sender: ejb@ERA.COM (Jay Berkenbilt)
  7. Organization: Engineering Research Associates, Vienna, VA
  8. Date: Mon, 31 Aug 1992 15:14:52 GMT
  9. Lines: 32
  10.  
  11.  
  12. Hello.  With gcc 2.2.2d, htonl, htons, ntohl, or ntohs,
  13. everything works fine except when you #include <netinet/in.h>
  14. and compile with -O.  In this case, bytes/words are not swapped.
  15. This can be demonstrated with the following program:
  16.  
  17. #include <netinet/in.h>
  18. int main(void)
  19. {
  20.     printf("%08x, %08x, %04x, %04x\n",
  21.        htonl(0x01020304), ntohl(0x01020304),
  22.        htons(0x0102), ntohs(0x0102));
  23.     return 0;
  24. }
  25.  
  26. The output of this program should be
  27.  
  28. 04030201, 04030201, 0201, 0201
  29.  
  30. If you compile this with gcc -O, you will get
  31.  
  32. 01020304, 01020304, 0102, 0102
  33.  
  34. Although it seems that this should be an error with the inline
  35. assembly routines defined in netinet/in.h, I'm not sure whether
  36. that is really the problem or not.  Either not including
  37. <netinet/in.h> or not using -O produces correct results.
  38.  
  39.  
  40. -- 
  41.                                 Jay Berkenbilt (ejb@ERA.COM)
  42.                                 Engineering Research Associates
  43.