From caf64d8849b4395200aa75fd8f95b5b37709dead Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Wed, 12 Aug 2009 11:24:33 +0000 Subject: [PATCH] * ecore_con: Add broadcast support from Atton Jonathan. SVN revision: 41701 --- legacy/ecore/src/lib/ecore_con/Ecore_Con.h | 1 + legacy/ecore/src/lib/ecore_con/ecore_con.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h index 1dcc7179e6..b240221135 100644 --- a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h +++ b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h @@ -85,6 +85,7 @@ extern "C" { ECORE_CON_REMOTE_TCP, ECORE_CON_REMOTE_MCAST, ECORE_CON_REMOTE_UDP, + ECORE_CON_REMOTE_BROADCAST, ECORE_CON_USE_SSL2 = (1 << 4), ECORE_CON_USE_SSL3 = (1 << 5), ECORE_CON_USE_TLS = (1 << 6) diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con.c b/legacy/ecore/src/lib/ecore_con/ecore_con.c index 04a41dfb6e..c124b93fa6 100644 --- a/legacy/ecore/src/lib/ecore_con/ecore_con.c +++ b/legacy/ecore/src/lib/ecore_con/ecore_con.c @@ -361,7 +361,7 @@ ecore_con_server_connect(Ecore_Con_Type compl_type, const char *name, int port, type = compl_type & ECORE_CON_TYPE; - if ((type == ECORE_CON_REMOTE_TCP || type == ECORE_CON_REMOTE_UDP) && (port < 0)) return NULL; + if ((type == ECORE_CON_REMOTE_TCP || type == ECORE_CON_REMOTE_UDP || ECORE_CON_REMOTE_BROADCAST) && (port < 0)) return NULL; if ((type == ECORE_CON_LOCAL_USER) || (type == ECORE_CON_LOCAL_SYSTEM) || (type == ECORE_CON_LOCAL_ABSTRACT)) @@ -457,7 +457,7 @@ ecore_con_server_connect(Ecore_Con_Type compl_type, const char *name, int port, /* TCP */ if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect, svr)) goto error; } - else if (type == ECORE_CON_REMOTE_UDP) + else if (type == ECORE_CON_REMOTE_UDP || type == ECORE_CON_REMOTE_BROADCAST) { /* UDP and MCAST */ if (!ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect, svr)) goto error; @@ -1080,7 +1080,7 @@ _ecore_con_cb_udp_connect(void *data, Ecore_Con_Info *net_info) { Ecore_Con_Server *svr; int curstate = 0; - + int broadcast = 1; svr = data; if (!net_info) goto error; @@ -1088,8 +1088,16 @@ _ecore_con_cb_udp_connect(void *data, Ecore_Con_Info *net_info) if (svr->fd < 0) goto error; if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; - if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0) - goto error; + + if(svr->type == ECORE_CON_REMOTE_BROADCAST) + { + if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) < 0) goto error; + } + else + { + if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0) goto error; + } + if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) goto error; else