socket_wrapper: Make it work on freebsd for udp packets
authorStefan Metzmacher <metze@samba.org>
Sun, 10 Oct 2010 10:29:08 +0000 (12:29 +0200)
committerMatthieu Patou <mat@samba.org>
Sun, 10 Oct 2010 12:56:59 +0000 (12:56 +0000)
Autobuild-User: Matthieu Patou <mat@samba.org>
Autobuild-Date: Sun Oct 10 12:57:00 UTC 2010 on sn-devel-104

lib/socket_wrapper/socket_wrapper.c

index 9d732ee65299d7e18d7e9222c11776f1e7329eab..c52d98cf91ddcc41a72922c409fd36a3363851d0 100644 (file)
@@ -1967,7 +1967,17 @@ _PUBLIC_ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, con
                        si->defer_connect = 0;
                }
 
-               ret = real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr));
+               /* Man page for Linux says:
+                * "the error EISONN may be returned when they are not NULL and 0"
+                * But in practice it's not on x86/amd64, but on other unix it is
+                * (ie. freebsd)
+                * So if we are already connected we send NULL/0
+                */
+               if (si->connected) {
+                       ret = real_sendto(s, buf, len, flags, NULL, 0);
+               } else {
+                       ret = real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr));
+               }
                break;
        default:
                ret = -1;