efl_net_dialer_udp: enable SO_BROADCAST before sending to 255.255.255.255
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Tue, 18 Oct 2016 22:00:52 +0000 (20:00 -0200)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Tue, 18 Oct 2016 22:00:52 +0000 (20:00 -0200)
Like other toolkits, let's enable this automatically for users before
connecting to 255.255.255.255 IPv4 (IPADDR_BROADCAST), otherwise most
systems will just fail to connect and send packets.

src/lib/ecore_con/ecore_con.c

index cb66b27..6c788e0 100644 (file)
@@ -3197,6 +3197,17 @@ _efl_net_connect_async_run(void *data, Ecore_Thread *thread EINA_UNUSED)
    if (eina_log_domain_level_check(_ecore_con_log_dom, EINA_LOG_LEVEL_DBG))
      efl_net_ip_port_fmt(buf, sizeof(buf), d->addr);
 
+   if ((d->type == SOCK_DGRAM) &&
+       (d->addr->sa_family == AF_INET) &&
+       (((const struct sockaddr_in *)d->addr)->sin_addr.s_addr == INADDR_BROADCAST))
+     {
+        int enable = 1;
+        if (setsockopt(d->sockfd, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable)) == 0)
+          DBG("enabled SO_BROADCAST for socket=%d", d->sockfd);
+        else
+          WRN("could not enable SO_BROADCAST for socket=%d: %s", d->sockfd, strerror(errno));
+     }
+
    DBG("connecting fd=%d to %s", d->sockfd, buf);
 
    r = connect(d->sockfd, d->addr, d->addrlen);
@@ -3377,6 +3388,17 @@ _efl_net_ip_connect(const struct addrinfo *addr, int *sockfd)
                DBG("connect fd=%d to %s", fd, buf);
           }
 
+        if ((addr->ai_socktype == SOCK_DGRAM) &&
+            (addr->ai_family == AF_INET) &&
+            (((const struct sockaddr_in *)addr->ai_addr)->sin_addr.s_addr == INADDR_BROADCAST))
+          {
+             int enable = 1;
+             if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable)) == 0)
+               DBG("enabled SO_BROADCAST for socket=%d", fd);
+             else
+               WRN("could not enable SO_BROADCAST for socket=%d: %s", fd, strerror(errno));
+          }
+
         r = connect(fd, addr->ai_addr, addr->ai_addrlen);
         if (r == 0)
           {