Skip to content
Snippets Groups Projects
Commit 9ffd9084 authored by clohr's avatar clohr
Browse files

Préparation de la version 0.7

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/C/branches/version-0.7@2326 b32b6428-25c9-4566-ad07-03861ab6144f
parent 3693c467
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ test: all
@/bin/echo -e "" $(foreach i,$(DEMOS)," ./$(i) -a 224.0.29.200 -p 1234 -s my_secret\n")
DEMO2 = thermoPC dummyLamp dumper dummyDimmer dummyShutter
DEMO2 = thermoPC dummyLamp dumper dummyDimmer dummyShutter lampCommander
test2: $(DEMO2)
xfce4-terminal -e true $(foreach i,$(DEMO2),--tab -e "$(SHELL) -c \"LD_LIBRARY_PATH+=:. ./$(i) -a 224.0.29.200 -p 1234 -s my_secret\"" -T $(i))
......
......@@ -45,7 +45,7 @@ Following applications are proposed as proof of concept:
## Copyright
- Christophe Lohr - IMT Atlantique - 2017
- Christophe Lohr - IMT Atlantique - 2019
- The demo applications are provided according to the terms of the
GNU General Public License v3.0 and following
- Dual-licenses are accepted, contact us.
......@@ -41,6 +41,16 @@ FILE *xAAL_error_log = NULL;
* Helpers for accessing the bus
*/
bool is_multicast(struct addrinfo *ai) {
switch (ai->ai_family) {
case AF_INET:
return IN_MULTICAST(ntohl( ((struct sockaddr_in*)(ai->ai_addr))->sin_addr.s_addr ));
case AF_INET6:
return IN6_IS_ADDR_MULTICAST( ((struct sockaddr_in6 *)(ai->ai_addr))->sin6_addr.s6_addr);
default:
return false;
}
}
/* Join the xAAL bus
......@@ -75,6 +85,7 @@ bool xAAL_join_bus(const char *addr,
bus->sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (bus->sfd == -1)
continue;
if (is_multicast(rp)) {
if (setsockopt(bus->sfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) {
if (xAAL_error_log) fprintf(xAAL_error_log, "SO_REUSEADDR: %s\n", strerror(errno));
close(bus->sfd);
......@@ -82,18 +93,21 @@ bool xAAL_join_bus(const char *addr,
}
if (bind(bus->sfd, rp->ai_addr, rp->ai_addrlen) == 0)
break; /* Success */
if (xAAL_error_log) fprintf(xAAL_error_log, "Trying port %s: %s\n", port, strerror(errno));
} else {
if (connect(bus->sfd, rp->ai_addr, rp->ai_addrlen) == 0)
break; /* Success */
}
if (xAAL_error_log) fprintf(xAAL_error_log, "Trying %s %s: %s\n", addr, port, strerror(errno));
close(bus->sfd);
}
if (rp == NULL) { /* No address succeeded */
if (xAAL_error_log) fprintf(xAAL_error_log, "Could not bind\n");
if (xAAL_error_log) fprintf(xAAL_error_log, "Could not open socket\n");
return false;
}
/* Now, join the group if it is a multicast address, or connect to it if it is an unicast address */
if (is_multicast(rp)) /* Now, join the group */
switch (rp->ai_family) {
case AF_INET:
if ( IN_MULTICAST(ntohl( ((struct sockaddr_in*)(rp->ai_addr))->sin_addr.s_addr )) ) {
memcpy(&mreqn.imr_multiaddr.s_addr, &(((struct sockaddr_in*)(rp->ai_addr))->sin_addr), sizeof(struct in_addr));
mreqn.imr_address.s_addr = INADDR_ANY;
mreqn.imr_ifindex = 0;
......@@ -109,15 +123,8 @@ bool xAAL_join_bus(const char *addr,
if (xAAL_error_log) fprintf(xAAL_error_log, "Could not %s multicast loop: %s\n", mcast_loop?"enable":"disable", strerror(errno));
return false;
}
} else {
if ( connect(bus->sfd, rp->ai_addr, rp->ai_addrlen) ) {
if (xAAL_error_log) fprintf(xAAL_error_log, "Could connect the unicast peer: %s\n", strerror(errno));
return false;
}
}
break;
case AF_INET6:
if ( IN6_IS_ADDR_MULTICAST( ((struct sockaddr_in6 *)(rp->ai_addr))->sin6_addr.s6_addr) ) {
memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6*)(rp->ai_addr))->sin6_addr), sizeof(struct in6_addr));
mreq6.ipv6mr_interface = 0;
if ( setsockopt(bus->sfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) == -1) {
......@@ -132,12 +139,6 @@ bool xAAL_join_bus(const char *addr,
if (xAAL_error_log) fprintf(xAAL_error_log, "Could not %s multicast loop: %s\n", mcast_loop?"enable":"disable", strerror(errno));
return false;
}
} else {
if ( connect(bus->sfd, rp->ai_addr, rp->ai_addrlen) ) {
if (xAAL_error_log) fprintf(xAAL_error_log, "Could connect the unicast peer: %s\n", strerror(errno));
return false;
}
}
break;
default:
if (xAAL_error_log) fprintf(xAAL_error_log, "Unknown protocol %d\n", rp->ai_family);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment