public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "john dot phelps at solipsys dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/12511] New: When building with -O2 getsockname may fail Date: Sat, 04 Oct 2003 23:22:00 -0000 [thread overview] Message-ID: <20031004232203.12511.john.phelps@solipsys.com> (raw) PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12511 Summary: When building with -O2 getsockname may fail Product: gcc Version: 3.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: john dot phelps at solipsys dot com CC: gcc-bugs at gcc dot gnu dot org For some odd reason using the htons function causes the getsockname call to fail under RedHat 9. A code snippet is included. The mere presence of the htons call for the sockaddr_in.port member causes the problem with getsockname to occur. Compiling with -O0 will allow things to function properly. Not sure if this is HTMLized... <pre> # include <byteswap.h> # include <errno.h> # include <sys/socket.h> # include <netinet/in.h> #include <iostream> // Compile with: g++ -O2 testGetsockname.C -o testGetsockname // // Set FIX_THE_PROBLEM to 1 in order to make things work. // # define FIX_THE_PROBLEM 0 //------------------------------------------------------------------------- // int main() { # if FIX_THE_PROBLEM if( false ) { u_short junk = htons( 1234 ); } # endif // Create a socket to work with. // int sd = socket( AF_INET, SOCK_DGRAM, 0 ); // Create a sockaddr structure to work with. // struct sockaddr saddr; socklen_t slen; // The getsockname call will fail if htons is used with the sockaddr_in // struture below. Note that the mere presence of the htons invocation // will cause the getsockname call to fail. // if( getsockname( sd, &saddr, &slen ) < 0 ) { std::cerr << "getsockname failed: " << errno << std::endl; return(-1); } else { std::cerr << "getsockname SUCCESS" << std::endl; } // Create a sockaddr_in to cause the issue. // struct sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons( 8000 ); // This is the problem line? sin.sin_addr.s_addr = htonl( INADDR_ANY ); std::cerr << "sin.sin_port = " << sin.sin_port << std::endl; return(0); } </pre>
next reply other threads:[~2003-10-04 23:22 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-10-04 23:22 john dot phelps at solipsys dot com [this message] 2003-10-04 23:38 ` [Bug c++/12511] " pinskia at gcc dot gnu dot org 2003-10-06 12:46 ` john dot phelps at solipsys dot com 2003-12-15 22:18 ` dhazeghi at yahoo dot com 2004-02-06 1:31 ` [Bug c++/12511] [3.3 Regression] " pinskia at gcc dot gnu dot org 2004-02-15 12:35 ` gdr at gcc dot gnu dot org 2004-03-10 12:21 ` [Bug optimization/12511] " giovannibajo at libero dot it 2004-04-18 17:29 ` gdr at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20031004232203.12511.john.phelps@solipsys.com \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).