home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!era!ejb
- From: ejb@ERA.COM (Jay Berkenbilt)
- Subject: gcc 2.2.2d: htonl, etc. problem with -O and netinet/in.h
- Message-ID: <1992Aug31.151452.26313@ERA.COM>
- Sender: ejb@ERA.COM (Jay Berkenbilt)
- Organization: Engineering Research Associates, Vienna, VA
- Date: Mon, 31 Aug 1992 15:14:52 GMT
- Lines: 32
-
-
- Hello. With gcc 2.2.2d, htonl, htons, ntohl, or ntohs,
- everything works fine except when you #include <netinet/in.h>
- and compile with -O. In this case, bytes/words are not swapped.
- This can be demonstrated with the following program:
-
- #include <netinet/in.h>
- int main(void)
- {
- printf("%08x, %08x, %04x, %04x\n",
- htonl(0x01020304), ntohl(0x01020304),
- htons(0x0102), ntohs(0x0102));
- return 0;
- }
-
- The output of this program should be
-
- 04030201, 04030201, 0201, 0201
-
- If you compile this with gcc -O, you will get
-
- 01020304, 01020304, 0102, 0102
-
- Although it seems that this should be an error with the inline
- assembly routines defined in netinet/in.h, I'm not sure whether
- that is really the problem or not. Either not including
- <netinet/in.h> or not using -O produces correct results.
-
-
- --
- Jay Berkenbilt (ejb@ERA.COM)
- Engineering Research Associates
-