Re: [zeromq-dev] zmq::tcp_listener_t::get_address
Everything is building fine on Centos 6.2 this morning. Woot! Brian On Sat, Feb 18, 2012 at 3:46 PM, Mikko Koppanen mikko.koppa...@gmail.comwrote: On Sat, Feb 18, 2012 at 7:49 PM, Mikko Koppanen mikko.koppa...@gmail.com wrote: Hi, I think the following should work: https://github.com/mkoppanen/libzmq/commit/b0573486c7abf89b79d30aa4d29b0dac3d789619 Missed ntohs, updated now in tcp-get-address branch: https://github.com/mkoppanen/libzmq/tree/tcp-get-address Can you test, Brian? -- Mikko Koppanen ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] zmq::tcp_listener_t::get_address
Thanks to Ian and Mikko On Feb 19, 2012 11:01 AM, Brian Knox taote...@gmail.com wrote: Everything is building fine on Centos 6.2 this morning. Woot! Brian On Sat, Feb 18, 2012 at 3:46 PM, Mikko Koppanen mikko.koppa...@gmail.comwrote: On Sat, Feb 18, 2012 at 7:49 PM, Mikko Koppanen mikko.koppa...@gmail.com wrote: Hi, I think the following should work: https://github.com/mkoppanen/libzmq/commit/b0573486c7abf89b79d30aa4d29b0dac3d789619 Missed ntohs, updated now in tcp-get-address branch: https://github.com/mkoppanen/libzmq/tree/tcp-get-address Can you test, Brian? -- Mikko Koppanen ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
[zeromq-dev] zmq::tcp_listener_t::get_address
I was working on testing the zeromq rsyslog plugins against zeromq 3.1 today, and noticed I can no longer compile the libzmq master branch from head. I wasn't sure if this was a known issue or not so figured I'd hit the list before filing it as a bug. I'm building libzmq master checked out this morning, on Centos 6.2. Here's the error: CXXlibzmq_la-tcp_listener.lo cc1plus: warnings being treated as errors tcp_listener.cpp: In member function ‘int zmq::tcp_listener_t::get_address(std::string*)’: tcp_listener.cpp:148: error: dereferencing pointer ‘sa.120’ does break strict-aliasing rules tcp_listener.cpp:148: note: initialized from here make[2]: *** [libzmq_la-tcp_listener.lo] Error 1 make[2]: Leaving directory `/home/bknox/src/libzmq/src' make[1]: *** [all] Error 2 make[1]: Leaving directory `/home/bknox/src/libzmq/src' make: *** [all-recursive] Error 1 When I diff tcp_listener.cpp against zeromq-libzmq-75c5b67 (which does build), I get this: [bknox@centos1 src]$ diff tcp_listener.cpp ../../zeromq-libzmq-75c5b67/src/tcp_listener.cpp 25d24 #include sstream 103c102 options, NULL); --- options, NULL, NULL); 123,157d121 int zmq::tcp_listener_t::get_address (std::string *addr_) { struct sockaddr sa; char host[INET6_ADDRSTRLEN]; char serv_info[32]; int port, rc; std::stringstream portnum; // Get the details of the TCP socket socklen_t sl = sizeof(sockaddr); rc = getsockname (s, sa, sl); if (rc != 0) { return rc; } // Split the retrieval between IPv4 and v6 addresses if ( sa.sa_family == AF_INET ) { getnameinfo(sa, sizeof(struct sockaddr), host, INET6_ADDRSTRLEN, serv_info, 32, NI_NUMERICHOST); port = ntohs( ((struct sockaddr_in *)sa)-sin_port); portnum port; // Store the address for retrieval by users using wildcards *addr_ = std::string(tcp://) + std::string(host) + std::string(:) + portnum.str(); } else { getnameinfo(sa, sizeof(struct sockaddr), host, INET6_ADDRSTRLEN, serv_info, 32, NI_NUMERICHOST); port = ntohs( ((struct sockaddr_in6 *)sa)-sin6_port); portnum port; // Store the address for retrieval by users using wildcards *addr_ = std::string(tcp://[) + std::string(host) + std::string(]:) + portnum.str(); } return 0; } 207d170 B ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] zmq::tcp_listener_t::get_address
On 18 February 2012 09:52, Brian Knox taote...@gmail.com wrote: port = ntohs( ((struct sockaddr_in6 *)sa)-sin6_port); Standard aliasing problem. I am more concerned that sockaddr is being used and not sockaddr_storage. Resolution is to detect the address and copy the entire sock address structure before accessing. The compiler will remove redundant code: struct sockaddr_in6 s6; memcpy (s6, sa, sizeof(s6)); sa_port = s6.sin6_port; -- Steve-o ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] zmq::tcp_listener_t::get_address
On 19/02/2012, at 1:52 AM, Brian Knox wrote: tcp_listener.cpp: In member function ‘int zmq::tcp_listener_t::get_address(std::string*)’: tcp_listener.cpp:148: error: dereferencing pointer ‘sa.120’ does break strict-aliasing rules Nice that sa.120 is an impossible piece of syntax ..:) tcp_listener.cpp:148: note: initialized from here struct sockaddr sa; port = ntohs( ((struct sockaddr_in *)sa)-sin_port); Probably this. Casting a pointer to X to pointer to Y and then dereferencing it isn't allowed (except in a few special cases, eg void, integers of the same size). -- john skaller skal...@users.sourceforge.net ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] zmq::tcp_listener_t::get_address
On Sat, Feb 18, 2012 at 3:23 PM, john skaller skal...@users.sourceforge.net wrote: On 19/02/2012, at 1:52 AM, Brian Knox wrote: tcp_listener.cpp: In member function ‘int zmq::tcp_listener_t::get_address(std::string*)’: tcp_listener.cpp:148: error: dereferencing pointer ‘sa.120’ does break strict-aliasing rules Hi, I think the following should work: https://github.com/mkoppanen/libzmq/commit/b0573486c7abf89b79d30aa4d29b0dac3d789619 -- Mikko Koppanen ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] zmq::tcp_listener_t::get_address
On Sat, Feb 18, 2012 at 7:49 PM, Mikko Koppanen mikko.koppa...@gmail.com wrote: Hi, I think the following should work: https://github.com/mkoppanen/libzmq/commit/b0573486c7abf89b79d30aa4d29b0dac3d789619 Missed ntohs, updated now in tcp-get-address branch: https://github.com/mkoppanen/libzmq/tree/tcp-get-address Can you test, Brian? -- Mikko Koppanen ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev