When trying to compile farsight2 with gcc I get errors of strict aliasing violations on lines of code like sa = (struct sockaddr_in *) &ifr.ifr_addr; I can get rid of these errors by using a union instead of recasting, the following diff works for me: diff --git a/gst-libs/gst/farsight/fs-interfaces.c b/gst-libs/gst/farsight/fs-in index 66d936b..2493454 100644 --- a/gst-libs/gst/farsight/fs-interfaces.c +++ b/gst-libs/gst/farsight/fs-interfaces.c @@ -325,6 +325,11 @@ fs_interfaces_get_local_ips (gboolean include_loopback) gchar * fs_interfaces_get_ip_for_interface (gchar *interface_name) { + + union { + struct sockaddr s_addr; + struct sockaddr_in sin_addr; + } sm; struct ifreq ifr; struct sockaddr_in *sa; gint sockfd; @@ -347,7 +352,8 @@ fs_interfaces_get_ip_for_interface (gchar *interface_name) } close (sockfd); - sa = (struct sockaddr_in *) &ifr.ifr_addr; + sm.s_addr = ifr.ifr_addr; + sa = &sm.sin_addr; GST_DEBUG ("Address for %s: %s", interface_name, inet_ntoa (sa->sin_addr)); return g_strdup (inet_ntoa (sa->sin_addr)); } But I'm no coder so I'd like to know if there's a proper way of doing it. I can't check the result either cause pass that problem I'm having unrelated compiling problems. R.
That looks really evil. Maybe we should just compile with -fno-strict-aliasing
I agree my patch is nasty, but I think type punning via unions is quite standard to avoid strict aliasing rules violations. I'm sure someone here can write something nicer, but I don't know of any other form of avoiding it. I found this old thread in the nmap development branch: http://seclists.org/nmap-dev/2009/q3/694 the two links there toward the end are an interesting reading. Cheers, R.
*** Bug 22412 has been marked as a duplicate of this bug. ***
patch confirmed working.
Alrgiht, put the union in the git master.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.