summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfcolin2000-12-20 16:47:19 +0000
committerfcolin2000-12-20 16:47:19 +0000
commitd47112e5481abb3004811cd0ae6d270c24461d9c (patch)
tree6d7eca5fbd53af0b1614fc9f4045be89db59af59 /src
parent2a5b456e050011846b366062403ae3f9ec45fedb (diff)
downloadivy-c-d47112e5481abb3004811cd0ae6d270c24461d9c.zip
ivy-c-d47112e5481abb3004811cd0ae6d270c24461d9c.tar.gz
ivy-c-d47112e5481abb3004811cd0ae6d270c24461d9c.tar.bz2
ivy-c-d47112e5481abb3004811cd0ae6d270c24461d9c.tar.xz
multicast and glut eventloop support
Diffstat (limited to 'src')
-rw-r--r--src/ivy.c6
-rw-r--r--src/ivyprobe.c37
-rw-r--r--src/ivysocket.c36
3 files changed, 76 insertions, 3 deletions
diff --git a/src/ivy.c b/src/ivy.c
index 7099430..b5651df 100644
--- a/src/ivy.c
+++ b/src/ivy.c
@@ -608,7 +608,7 @@ void IvyStart (const char* bus)
*/
broadcast = SocketBroadcastCreate (SupervisionPort, 0, BroadcastReceive );
-
+
/* then, if we only have a port number, resort to default value for network */
if (p == q)
p = DefaultIvyBus;
@@ -636,6 +636,10 @@ void IvyStart (const char* bus)
/* addresses are terminated by a comma or end of string */
} else {
printf ("Broadcasting on network %lx, port %d\n", mask, SupervisionPort);
+ // test mask value agaisnt CLASS D
+ if ( IN_MULTICAST( mask ) )
+ SocketAddMember (broadcast , mask );
+
SocketSendBroadcast (broadcast, mask, SupervisionPort, "%d %hu\n", VERSION, ApplicationPort);
numelem = 0;
mask = 0xffffffff;
diff --git a/src/ivyprobe.c b/src/ivyprobe.c
index c73df3a..f8e02fb 100644
--- a/src/ivyprobe.c
+++ b/src/ivyprobe.c
@@ -6,7 +6,7 @@
*
* Main and only file
*
- * Authors: François-Régis Colin <fcolin@cena.dgac.fr>
+ * Authors: François-Régis Colin <fcolin@cena.fr>
*
* $Id$
*
@@ -24,6 +24,10 @@
#undef IVYMAINLOOP
#endif
+#ifdef GLUTMAINLOOP
+#undef IVYMAINLOOP
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -39,6 +43,9 @@
#ifdef GTKMAINLOOP
#include "ivygtkloop.h"
#endif
+#ifdef GLUTMAINLOOP
+#include "ivyglutloop.h"
+#endif
#ifdef IVYMAINLOOP
#include "ivyloop.h"
#endif
@@ -79,6 +86,9 @@ void HandleStdin (Channel channel, HANDLE fd, void *data)
#ifdef GTKMAINLOOP
IvyGtkChannelClose(channel);
#endif
+#ifdef GLUTMAINLOOP
+ IvyGlutChannelClose(channel);
+#endif
#ifdef IVYMAINLOOP
IvyChannelClose (channel);
IvyStop();
@@ -183,6 +193,9 @@ void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent
#ifdef GTKMAINLLOP
IvyGtkChannelSetUp( 0, NULL, NULL, HandleStdin);
#endif
+#ifdef GLUTMAINLLOP
+ IvyGlutChannelSetUp( 0, NULL, NULL, HandleStdin);
+#endif
#ifdef IVYMAINLOOP
IvyChannelSetUp (0, NULL, NULL, HandleStdin);
#endif
@@ -208,7 +221,14 @@ void TimerCall(TimerId id, void *user_data, unsigned long delta)
/*if ((int)user_data == 5) TimerModify (id, 2000);*/
}
#endif
-
+#ifdef GLUTMAINLLOP
+void
+display(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT);
+ glFlush();
+}
+#endif
int main(int argc, char *argv[])
{
@@ -236,6 +256,12 @@ int main(int argc, char *argv[])
cntx = XtCreateApplicationContext();
IvyXtChannelAppContext (cntx);
#endif
+#ifdef GLUTMAINLLOOP
+ glutInit(&argc, argv);
+ glutCreateWindow("IvyProbe Test");
+ glClearColor(0.49, 0.62, 0.75, 0.0);
+ glutDisplayFunc(display);
+#endif
IvyInit ("IVYPROBE", "IVYPROBE READY", ApplicationCallback,NULL,NULL,NULL);
for (; optind < argc; optind++)
IvyBindMsg (Callback, NULL, argv[optind]);
@@ -247,6 +273,9 @@ int main(int argc, char *argv[])
#ifdef GTKMAINLOOP
IvyGtkChannelSetUp (0, NULL, NULL, HandleStdin);
#endif
+#ifdef GLUTMAINLOOP
+ IvyGlutChannelSetUp (0, NULL, NULL, HandleStdin);
+#endif
#ifdef IVYMAINLOOP
IvyChannelSetUp (0, NULL, NULL, HandleStdin);
#endif
@@ -266,6 +295,10 @@ int main(int argc, char *argv[])
#ifdef GTKMAINLOOP
gtk_main();
#endif
+#ifdef GLUTMAINLOOP
+ glutMainLoop();
+#endif
+
#ifdef IVYMAINLOOP
IvyMainLoop (0);
#endif
diff --git a/src/ivysocket.c b/src/ivysocket.c
index 9d40f3d..582d227 100644
--- a/src/ivysocket.c
+++ b/src/ivysocket.c
@@ -579,3 +579,39 @@ void SocketSendBroadcast (Client client, unsigned long host, unsigned short port
perror ("*** send ***");
} va_end (ap );
}
+
+/* Socket Multicast */
+
+int SocketAddMember(Client client, unsigned long host )
+{
+ struct ip_mreq imr;
+/*
+Multicast datagrams with initial TTL 0 are restricted to the same host.
+Multicast datagrams with initial TTL 1 are restricted to the same subnet.
+Multicast datagrams with initial TTL 32 are restricted to the same site.
+Multicast datagrams with initial TTL 64 are restricted to the same region.
+Multicast datagrams with initial TTL 128 are restricted to the same continent.
+Multicast datagrams with initial TTL 255 are unrestricted in scope.
+*/
+ unsigned char ttl = 64 ; // Arbitrary TTL value.
+ /* wee need to broadcast */
+
+ imr.imr_multiaddr.s_addr = htonl( host );
+ imr.imr_interface.s_addr = INADDR_ANY;
+ if(setsockopt(client->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&imr,sizeof(struct ip_mreq)) == -1 )
+ {
+ perror("setsockopt() Cannot join group");
+ fprintf(stderr, "Does your kernel support IP multicast extensions ?\n");
+ return 0;
+ }
+
+ if(setsockopt(client->fd, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) < 0 )
+ {
+ perror("setsockopt() Cannot set TTL");
+ fprintf(stderr, "Does your kernel support IP multicast extensions ?\n");
+ return 0;
+ }
+
+ return 1;
+}
+