summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2009-01-22 12:39:32 (GMT)
committer Jaromil <jaromil@dyne.org>2009-01-22 12:39:32 (GMT)
commitf5005bf41cd529ca2589ff2764746bd77be98e59 (patch)
tree7dd0ecd2d15091ff3a5b4d9f794957db9bc7a058
parent76b8394b1905f2661c561d4d037c56f6fe490d7c (diff)
handshake scripts
and some fix on udpbroadcast
-rw-r--r--scripts/README12
-rwxr-xr-xscripts/listen-handshake.sh32
-rwxr-xr-xscripts/offer_handshake.sh35
-rw-r--r--udpbroadcast.cpp8
4 files changed, 86 insertions, 1 deletions
diff --git a/scripts/README b/scripts/README
new file mode 100644
index 0000000..99cb916
--- /dev/null
+++ b/scripts/README
@@ -0,0 +1,12 @@
+
+Here are scripts used for setup of the syncstarter at boot time
+
+handshake programs are used for the network syncstarter
+in order to verify the presence of all scheduled players
+they are blocking processes, after their successful exit(0)
+everyone should be online
+
+the GNU version of netcat is required, honouring the flag -c
+
+- jrml
+
diff --git a/scripts/listen-handshake.sh b/scripts/listen-handshake.sh
new file mode 100755
index 0000000..bf612e9
--- /dev/null
+++ b/scripts/listen-handshake.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+if [ -z $1 ]; then
+ echo "usage: $0 network_interface"
+ echo "example: $0 eth0"
+ exit 1
+fi
+IFACE="$1"
+
+
+NC="netcat -c"
+# check if it is openbsd netcat
+NC_ver="`netcat -h 2>&1|head -n 1 | awk '{print $1}'`"
+if [ "$NC_ver" = "OpenBSD" ]; then
+ echo "using OpenBSD version of netcat"
+ NC="netcat -q 0"
+fi
+
+# some more version might be around that is not supported..
+
+IP="`ifconfig $IFACE | grep 'inet addr'| awk '{print $2}'|cut -f2 -d:`"
+
+echo "listening on $IFACE configured with address $IP ..."
+master="`echo | $NC -u -l 3332`"
+
+echo "contacted by master $master"
+echo "$IP" | netcat -u $master 3331
+
+echo "master replied"
+
+
+exit 0
diff --git a/scripts/offer_handshake.sh b/scripts/offer_handshake.sh
new file mode 100755
index 0000000..54950c7
--- /dev/null
+++ b/scripts/offer_handshake.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# here configure the file with the list of IP or hostnames, one per line
+LISTFILE=list
+
+if [ -z $1 ]; then
+ echo "usage: $0 network_interface"
+ echo "example: $0 eth0"
+ exit 1
+fi
+IFACE="$1"
+
+IP="`ifconfig $IFACE | grep 'inet addr'| awk '{print $2}'|cut -f2 -d:`"
+
+ready=false
+
+for i in `cat $LISTFILE`; do
+ rm -f /tmp/handshake.$i.ok
+ echo -n "handshaking $i"
+
+ # background listener
+ (answer=`echo | nc -q 0 -u -l 3331`;
+ echo $answer > /tmp/handshake.$i.ok) &
+
+ while ! [ -r /tmp/handshake.$i.ok ]; do
+ sleep 1
+ ../udpbroadcast $i 3332 $IP 1>&2 > /dev/null
+ echo -n "."
+ done
+ echo -n " answer: `cat /tmp/handshake.$i.ok`"
+ rm /tmp/handshake.$i.ok
+ echo
+done
+
+exit 0
diff --git a/udpbroadcast.cpp b/udpbroadcast.cpp
index 7e9ae73..80d47ab 100644
--- a/udpbroadcast.cpp
+++ b/udpbroadcast.cpp
@@ -53,7 +53,12 @@ int main(int argc, char *argv[])
their_addr.sin_addr = *((struct in_addr *)he->h_addr);
memset(their_addr.sin_zero, '\0', sizeof their_addr.sin_zero);
- if ((numbytes=sendto(sockfd, argv[3], strlen(argv[3]), 0,
+ // forge string with newline
+ int len = strlen(argv[3]);
+ char *temp = (char*)calloc(len+2,sizeof(char));
+ snprintf(temp,len+2,"%s\n\n",argv[3]);
+
+ if ((numbytes=sendto(sockfd, temp, len+2, 0,
(struct sockaddr *)&their_addr, sizeof their_addr)) == -1) {
perror("sendto");
exit(1);
@@ -62,6 +67,7 @@ int main(int argc, char *argv[])
printf("sent %d bytes to %s\n", numbytes, inet_ntoa(their_addr.sin_addr));
close(sockfd);
+ free(temp);
return 0;
}