* Move 'ManyGroups' and 'TooManyGroups' to the new directory of 'datefile'. And install them into '$LTPROOT/testcases/data'. * Delete 'trace_logic' that is used to debug. * Use 'test.sh' and use 'tst_*' instead of 'end_testcase'. * Use 'tst_check_cmds' to check 'netstat'. * Delete some unuseful comments. * Rename 'member.c' to 'mc_member_test.c' and some cleanup. * Fix old-style function definition in "mc_member_test.c". * Modify Makefile.
Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com> --- testcases/network/multicast/mc_member/Makefile | 4 +- testcases/network/multicast/mc_member/ManyGroups | 20 -- .../network/multicast/mc_member/TooManyGroups | 23 -- .../network/multicast/mc_member/datafiles/Makefile | 30 +++ .../multicast/mc_member/datafiles/ManyGroups | 20 ++ .../multicast/mc_member/datafiles/TooManyGroups | 23 ++ testcases/network/multicast/mc_member/mc_member | 250 ++++++++------------- .../network/multicast/mc_member/mc_member_test.c | 184 +++++++++++++++ testcases/network/multicast/mc_member/member.c | 187 --------------- 9 files changed, 352 insertions(+), 389 deletions(-) delete mode 100644 testcases/network/multicast/mc_member/ManyGroups delete mode 100644 testcases/network/multicast/mc_member/TooManyGroups create mode 100644 testcases/network/multicast/mc_member/datafiles/Makefile create mode 100644 testcases/network/multicast/mc_member/datafiles/ManyGroups create mode 100644 testcases/network/multicast/mc_member/datafiles/TooManyGroups create mode 100644 testcases/network/multicast/mc_member/mc_member_test.c delete mode 100644 testcases/network/multicast/mc_member/member.c diff --git a/testcases/network/multicast/mc_member/Makefile b/testcases/network/multicast/mc_member/Makefile index afd1114..ce95a4d 100644 --- a/testcases/network/multicast/mc_member/Makefile +++ b/testcases/network/multicast/mc_member/Makefile @@ -24,6 +24,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/env_pre.mk -INSTALL_TARGETS := mc_member *ManyGroups +INSTALL_TARGETS := mc_member -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk diff --git a/testcases/network/multicast/mc_member/ManyGroups b/testcases/network/multicast/mc_member/ManyGroups deleted file mode 100644 index 185ccdc..0000000 --- a/testcases/network/multicast/mc_member/ManyGroups +++ /dev/null @@ -1,20 +0,0 @@ -224.10.10.11 -224.10.10.12 -224.10.10.13 -224.10.10.14 -224.10.10.15 -224.10.10.16 -224.10.10.17 -224.10.10.18 -224.10.10.19 -224.10.10.20 -224.10.10.21 -224.10.10.22 -224.10.10.23 -224.10.10.24 -224.10.10.25 -224.10.10.26 -224.10.10.27 -224.10.10.28 -224.10.10.29 -224.10.10.30 diff --git a/testcases/network/multicast/mc_member/TooManyGroups b/testcases/network/multicast/mc_member/TooManyGroups deleted file mode 100644 index 3884fb3..0000000 --- a/testcases/network/multicast/mc_member/TooManyGroups +++ /dev/null @@ -1,23 +0,0 @@ -224.10.10.11 -224.10.10.12 -224.10.10.13 -224.10.10.14 -224.10.10.15 -224.10.10.16 -224.10.10.17 -224.10.10.18 -224.10.10.19 -224.10.10.20 -224.10.10.21 -224.10.10.22 -224.10.10.23 -224.10.10.24 -224.10.10.25 -224.10.10.26 -224.10.10.27 -224.10.10.28 -224.10.10.29 -224.10.10.30 -224.10.10.31 -224.10.10.32 -224.10.10.33 diff --git a/testcases/network/multicast/mc_member/datafiles/Makefile b/testcases/network/multicast/mc_member/datafiles/Makefile new file mode 100644 index 0000000..f61386e --- /dev/null +++ b/testcases/network/multicast/mc_member/datafiles/Makefile @@ -0,0 +1,30 @@ +################################################################################ +## network/multicast/mc_member/datafiles Makefile. ## +## ## +## Copyright (C) 2009, Cisco Systems Inc. ## +## ## +## This program is free software; you can redistribute it and/or modify ## +## it under the terms of the GNU General Public License as published by ## +## the Free Software Foundation; either version 2 of the License, or ## +## (at your option) any later version. ## +## ## +## This program is distributed in the hope that it will be useful, ## +## but WITHOUT ANY WARRANTY; without even the implied warranty of ## +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## +## GNU General Public License for more details. ## +## ## +## You should have received a copy of the GNU General Public License along ## +## with this program; if not, write to the Free Software Foundation, Inc., ## +## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ## +## ## +################################################################################ + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_DIR := testcases/data/mc_member + +INSTALL_TARGETS := *ManyGroups + +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/network/multicast/mc_member/datafiles/ManyGroups b/testcases/network/multicast/mc_member/datafiles/ManyGroups new file mode 100644 index 0000000..185ccdc --- /dev/null +++ b/testcases/network/multicast/mc_member/datafiles/ManyGroups @@ -0,0 +1,20 @@ +224.10.10.11 +224.10.10.12 +224.10.10.13 +224.10.10.14 +224.10.10.15 +224.10.10.16 +224.10.10.17 +224.10.10.18 +224.10.10.19 +224.10.10.20 +224.10.10.21 +224.10.10.22 +224.10.10.23 +224.10.10.24 +224.10.10.25 +224.10.10.26 +224.10.10.27 +224.10.10.28 +224.10.10.29 +224.10.10.30 diff --git a/testcases/network/multicast/mc_member/datafiles/TooManyGroups b/testcases/network/multicast/mc_member/datafiles/TooManyGroups new file mode 100644 index 0000000..3884fb3 --- /dev/null +++ b/testcases/network/multicast/mc_member/datafiles/TooManyGroups @@ -0,0 +1,23 @@ +224.10.10.11 +224.10.10.12 +224.10.10.13 +224.10.10.14 +224.10.10.15 +224.10.10.16 +224.10.10.17 +224.10.10.18 +224.10.10.19 +224.10.10.20 +224.10.10.21 +224.10.10.22 +224.10.10.23 +224.10.10.24 +224.10.10.25 +224.10.10.26 +224.10.10.27 +224.10.10.28 +224.10.10.29 +224.10.10.30 +224.10.10.31 +224.10.10.32 +224.10.10.33 diff --git a/testcases/network/multicast/mc_member/mc_member b/testcases/network/multicast/mc_member/mc_member index 3ffdc99..00930a7 100755 --- a/testcases/network/multicast/mc_member/mc_member +++ b/testcases/network/multicast/mc_member/mc_member @@ -33,188 +33,124 @@ unset LIBPATH # -Ported # #****************************************************************************** -#Uncomment the line below for debug output -#trace_logic=${trace_logic:-"set -x"} -$trace_logic TC=mc_member TCsrc=${TCsrc:-`pwd`} -TCtmp=${TCtmp:-$TCsrc/$TC$$} -CLEANUP=${CLEANUP:-ON} -EXECUTABLES=${EXECUTABLES:-"member"} -NUMLOOPS=${NUMLOOPS:-2} -INTERFACE=${INTERFACE:-$(mc_gethost `hostname`| grep address |awk '{ print $2 }')} -GLIST=${GLIST:-$TCsrc/ManyGroups} -TooManyGLIST=${TooManyGLIST:-$TCsrc/TooManyGroups} -ERRFILE=${ERRFILE:-$TCtmp/errors} +INTERFACE=${INTERFACE:-$(mc_gethost `hostname`|grep address|awk '{ print $2 }')} +GLIST=${GLIST:-$LTPROOT/testcases/data/mc_member/ManyGroups} +TooManyGLIST=${TooManyGLIST:-$LTPROOT/testcases/data/mc_member/TooManyGroups} +ERRFILE=${ERRFILE:-errors} export TCID=$TC export TST_TOTAL=1 export TST_COUNT=1 -this_file=${0##*/} -trap "interrupt_test" 2 +. test.sh setup() { - mkdir -p $TCtmp -} - -get_address() -{ - DIGIT=`ps -ef | grep mc_member | grep -v grep | wc -l` - ADDRESS=$DIGIT.$DIGIT.$DIGIT.$DIGIT -} + tst_check_cmds netstat -#****************************************************************************** -# -# FUNCTION: do_test -# PURPOSE: Executes the testcases. -# INPUT: Number of iterations -# OUTPUT: Error messages are logged when any verification test -# fails. -# -#----------------------------------------------------------------------- - -do_test() -{ - $trace_logic - echo "$this_file: doing $0." - - COUNT=1 - while [ $COUNT -le $NUMLOOPS ] - do - # Run setsockopt test with bogus network - get_address - echo "Running mc_member_e on $ADDRESS" - $TCsrc/$EXECUTABLES -j -g $GLIST -s 30 -i $ADDRESS >/dev/null 2>&1 - - # Run setsockopt/getsockopt test - - $TCsrc/$EXECUTABLES -g $GLIST -s 80 -i $INTERFACE > $ERRFILE 2>&1 & - - # Join twice and leave once and see if the groups are still joined on - # all specified interfaces. - - for agroup in `cat $GLIST` - do - echo "Running (1st) member on $INTERFACE" - $TCsrc/$EXECUTABLES -j -g $GLIST -s 30 -i $INTERFACE > $ERRFILE 2>&1 & - sleep 5 - grep "cannot join group" $ERRFILE - [ $? = 0 ] && end_testcase "MC group could NOT join $INTERFACE" - - echo "Running (2nd) member on $INTERFACE" - $TCsrc/$EXECUTABLES -g $GLIST -s 60 -i $INTERFACE > $ERRFILE 2>&1 & - sleep 5 - grep "cannot join group" $ERRFILE - [ $? = 0 ] && end_testcase "MC group could NOT join $INTERFACE" - done - - # See if the groups are joined - - for agroup in `cat $GLIST` - do - netstat -gn | grep $agroup - [ $? = 0 ] || end_testcase "$agroup NOT joined to $INTERFACE" - - # See if they respond to a ping. - #ping -c 3 -I $INTERFACE $agroup - #[ $? != 0 ] && { echo "Error - $TC: $agroup NOT responding over $INTERFACE" ;} - - done - - echo "Waiting 60 seconds! Do not interrupt!" - sleep 60 # Make sure the first process has stopped - - for agroup in `cat $GLIST` - do - netstat -gn | grep $agroup - if [ $? != 1 ]; then - end_testcase "$agroup still joined on $INTERFACE" + if [ -z $INTERFACE ]; then + tst_brkm TCONF "$(hostname) is not found in /etc/hosts" fi - done - - # Test the membership boundaries - - echo "Running member on too many groups over $INTERFACE" - $TCsrc/$EXECUTABLES -j -g $TooManyGLIST -i $INTERFACE > $ERRFILE 2>&1 & - - count=`grep 105 $ERRFILE | wc -l` - - [ $count -gt 3 ] && end_testcase "Could not join members!" - COUNT=$(( $COUNT + 1 )) - - done # end of while numloop + tst_tmpdir } -#----------------------------------------------------------------------- -# -# FUNCTION: do_cleanup -# PURPOSE: Called when the testcase is interrupted by the user -# or by interrupt_testcase() when time limit expired -# INPUT: None. -# OUTPUT: None. -# -#----------------------------------------------------------------------- - -do_cleanup() +get_address() { - $trace_logic - echo "$this_file: doing $0." - - rm -rf $TCtmp + DIGIT=`ps -ef | grep mc_member | grep -v grep | wc -l` + ADDRESS=$DIGIT.$DIGIT.$DIGIT.$DIGIT } -#============================================================================= -# FUNCTION NAME: end_testcase -# -# FUNCTION DESCRIPTION: Clean up -# -# PARAMETERS: string, IF AND ONLY IF the testcase fails -# -# RETURNS: None. -#============================================================================= - -end_testcase() +do_test() { - $trace_logic - echo "$this_file: doing $0." - - # Call other cleanup functions - [ $CLEANUP = "ON" ] && do_cleanup - - [ $# = 0 ] && { tst_resm TPASS "Test Successful"; exit 0; } - tst_resm TFAIL "Test Failed: $@" - exit 1 + tst_resm TINFO "doing test." + + COUNT=1 + while [ $COUNT -le 2 ] + do + # Run setsockopt test with bogus network + get_address + tst_resm TINFO "Running mc_member_e on $ADDRESS" + mc_member_test -j -g $GLIST -s 30 -i $ADDRESS >/dev/null 2>&1 + + # Run setsockopt/getsockopt test + mc_member_test -g $GLIST -s 80 -i $INTERFACE > $ERRFILE 2>&1 & + + # Join twice and leave once and see if the groups are still + # joined on all specified interfaces. + for agroup in `cat $GLIST` + do + tst_resm TINFO "Running (1st) member on $INTERFACE" + mc_member_test -j -g $GLIST -s 30 -i $INTERFACE \ + > $ERRFILE 2>&1 & + sleep 5 + grep "cannot join group" $ERRFILE + if [ $? -eq 0 ]; then + tst_brkm TFAIL "MC group could NOT join "\ + "$INTERFACE" + fi + + tst_resm TINFO "Running (2nd) member on $INTERFACE" + mc_member_test -g $GLIST -s 60 -i $INTERFACE \ + > $ERRFILE 2>&1 & + sleep 5 + grep "cannot join group" $ERRFILE + if [ $? -eq 0 ]; then + tst_brkm TFAIL "MC group could NOT join "\ + "$INTERFACE" + fi + done + + # See if the groups are joined + for agroup in `cat $GLIST` + do + netstat -gn | grep $agroup + if [ $? -ne 0 ]; then + tst_brkm TFAIL "$agroup NOT joined to $INTERFACE" + fi + done + + tst_resm TINFO "Waiting 60 seconds! Do not interrupt!" + sleep 60 # Make sure the first process has stopped + + for agroup in `cat $GLIST` + do + netstat -gn | grep $agroup + if [ $? -ne 1 ]; then + tst_brkm TFAIL "$agroup still joined on "\ + "$INTERFACE" + fi + done + + # Test the membership boundaries + tst_resm TINFO "Running member on too many groups over "\ + "$INTERFACE" + mc_member_test -j -g $TooManyGLIST -i $INTERFACE \ + > $ERRFILE 2>&1 & + + count=`grep 105 $ERRFILE | wc -l` + if [ $count -gt 3 ]; then + tst_brkm TFAIL "Could not join members!" + fi + + COUNT=$(( $COUNT + 1 )) + + done + + tst_resm TPASS "Test Successful" + tst_exit } -#****************************************************************************** -# -# FUNCTION: interrupt_test -# PURPOSE: Handle process interrupts set by trap. -# INPUT: none -# OUTPUT: none -# -#****************************************************************************** - -interrupt_test() +do_cleanup() { - echo "test interrupted" - end_testcase + tst_rmdir } -#****************************************************************************** -# -# FUNCTION: MAIN -# PURPOSE: To invoke functions that perform the tasks as described in -# the design in the prolog above. -# INPUT: See SETUP in the prolog above. -# OUTPUT: Logged run results written to testcase run log -# -#****************************************************************************** setup +TST_CLEANUP=do_cleanup + do_test -end_testcase diff --git a/testcases/network/multicast/mc_member/mc_member_test.c b/testcases/network/multicast/mc_member/mc_member_test.c new file mode 100644 index 0000000..f61e3f6 --- /dev/null +++ b/testcases/network/multicast/mc_member/mc_member_test.c @@ -0,0 +1,184 @@ +#include <arpa/inet.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <netdb.h> +#include <unistd.h> + +static char *prog; +static int errors; + +static int join_group(int, char *, struct ip_mreq *); +static int leave_group(int, char *, struct ip_mreq *); +static void usage(void); + +int main(int argc, char *argv[]) +{ + int s; + struct ip_mreq imr; + + char *group_list = NULL, *interface = NULL; + unsigned i1, i2, i3, i4; + struct hostent *hp, *gethostbyname(); + int c; + int lflg = 0, jflg = 0, sflg = 0; + + prog = argv[0]; + if (argc == 1) + usage(); + + while ((c = getopt(argc, argv, "jlg:s:i:")) != EOF) + switch (c) { + case 'j': + if (lflg) + usage(); + else + jflg++; + break; + case 'l': + if (jflg) + usage(); + else + lflg++; + break; + case 'g': + group_list = optarg; + break; + case 's': + sflg = atoi(optarg); + break; + case 'i': + interface = optarg; + break; + case '?': + usage(); + } + + if (optind != argc) + usage(); + + if (access(group_list, R_OK) != 0) { + printf("Unabled to read group file %s\n", group_list); + exit(1); + } + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s == -1) { + perror("can not open socket"); + exit(1); + } + + hp = gethostbyname(interface); + if (hp != NULL) { + memcpy(&imr.imr_interface.s_addr, hp->h_addr, hp->h_length); + } else if (sscanf(interface, "%u.%u.%u.%u", &i1, &i2, &i3, &i4) != 4) { + fprintf(stderr, "bad group address\n"); + exit(1); + } else { + imr.imr_interface.s_addr = + htonl((i1 << 24) | (i2 << 16) | (i3 << 8) | i4); + } + /* verify socket options */ + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, + &imr.imr_interface.s_addr, + sizeof(imr.imr_interface.s_addr)) != 0) { + fprintf(stderr, + "Error: unable to set socket option IP_MULTICAST_IF\n"); + errors++; + } else + printf("Socket set for Multicasting on: %s\n", interface); + + if ((!jflg && !lflg) || jflg) + join_group(s, group_list, &imr); + + sleep(sflg); + + if ((!jflg && !lflg) || lflg) + leave_group(s, group_list, &imr); + + close(s); + if (errors) + exit(1); + return 0; +} + +static int join_group(int s, char *glist, struct ip_mreq *imr) +{ + char buf[40]; + unsigned g1, g2, g3, g4; + FILE *fd; + char group[40], itf[40]; + + fd = fopen(glist, "r"); + if (fd == NULL) + printf("Error: unable to open %s\n", glist); + + while (fgets(buf, sizeof(buf), fd) != NULL) { + if (sscanf(buf, "%u.%u.%u.%u", &g1, &g2, &g3, &g4) != 4) { + fprintf(stderr, "bad group address\n"); + exit(1); + } + + imr->imr_multiaddr.s_addr = + htonl((g1 << 24) | (g2 << 16) | (g3 << 8) | g4); + + if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, + imr, sizeof(struct ip_mreq)) == -1) { + fprintf(stderr, "errno is %d\n", errno); + perror("can't join group"); + errors++; + } else { + strcpy(group, inet_ntoa(imr->imr_multiaddr)); + strcpy(itf, inet_ntoa(imr->imr_interface)); + printf("IPM group: %s added to interface: %s\n", group, + itf); + } + } + return 0; +} + +static int leave_group(int s, char *glist, struct ip_mreq *imr) +{ + char buf[40]; + unsigned g1, g2, g3, g4; + FILE *fd; + char group[40], itf[40]; + + fd = fopen(glist, "r"); + if (fd == NULL) + printf("Error: unable to open %s\n", glist); + + while (fgets(buf, sizeof(buf), fd) != NULL) { + if (sscanf(buf, "%u.%u.%u.%u", &g1, &g2, &g3, &g4) != 4) { + fprintf(stderr, "leave_group: bad group address\n"); + exit(1); + } + + imr->imr_multiaddr.s_addr = + htonl((g1 << 24) | (g2 << 16) | (g3 << 8) | g4); + + if (setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, + imr, sizeof(struct ip_mreq)) == -1) { + perror("can't leave group"); + errors++; + } else { + strcpy(group, inet_ntoa(imr->imr_multiaddr)); + strcpy(itf, inet_ntoa(imr->imr_interface)); + printf("IPM group: %s dropped from interface: %s\n", + group, itf); + } + } + return 0; +} + +static void usage(void) +{ + fprintf(stderr, + "usage: %s [ -j -l ] -g group_list [-s time_to_sleep] -i interface_name (or i.i.i.i)\n", + prog); + exit(1); +} diff --git a/testcases/network/multicast/mc_member/member.c b/testcases/network/multicast/mc_member/member.c deleted file mode 100644 index 5b51dbe..0000000 --- a/testcases/network/multicast/mc_member/member.c +++ /dev/null @@ -1,187 +0,0 @@ -#include <arpa/inet.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <netdb.h> -#include <unistd.h> - -char *prog; -int errors = 0; -int ttl_no = 255; - -int join_group(int, char *, struct ip_mreq *); -int leave_group(int, char *, struct ip_mreq *); -void usage(void); - -int main(argc, argv) -int argc; -char *argv[]; -{ - int s; - struct ip_mreq imr; - - char *group_list = NULL, *interface = NULL; - unsigned i1, i2, i3, i4; - struct hostent *hp, *gethostbyname(); - int c, n; - /*int errors=0; */ - int lflg = 0, jflg = 0, sflg = 0; - - extern int optind; - extern char *optarg; - prog = argv[0]; - if (argc == 1) - usage(); - - while ((c = getopt(argc, argv, "jlg:s:i:")) != EOF) - switch (c) { - case 'j': - if (lflg) - usage(); - else - jflg++; - break; - case 'l': - if (jflg) - usage(); - else - lflg++; - break; - case 'g': - group_list = optarg; - break; - case 's': - sflg = atoi(optarg); - break; - case 'i': - interface = optarg; - break; - case '?': - usage(); - } - - if (optind != argc) - usage(); - - if (access(group_list, R_OK) != 0) { - printf("Unabled to read group file %s\n", group_list); - exit(1); - } - - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - perror("can not open socket"); - exit(1); - } - - if ((hp = gethostbyname(interface))) { - memcpy(&imr.imr_interface.s_addr, hp->h_addr, hp->h_length); - } else - if ((n = - sscanf(interface, "%u.%u.%u.%u", &i1, &i2, &i3, &i4)) != 4) { - fprintf(stderr, "bad group address\n"); - exit(1); - } else - imr.imr_interface.s_addr = - htonl((i1 << 24) | (i2 << 16) | (i3 << 8) | i4); - /* verify socket options */ - if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, - &imr.imr_interface.s_addr, - sizeof(imr.imr_interface.s_addr)) != 0) { - fprintf(stderr, - "Error: unable to set socket option IP_MULTICAST_IF\n"); - errors++; - } else - printf("Socket set for Multicasting on: %s\n", interface); - - if ((!jflg && !lflg) || jflg) - join_group(s, group_list, &imr); - - sleep(sflg); - - if ((!jflg && !lflg) || lflg) - leave_group(s, group_list, &imr); - - close(s); - if (errors) - exit(1); - return (0); -} - -int join_group(int s, char *glist, struct ip_mreq *imr) -{ - char buf[40]; - unsigned g1, g2, g3, g4; - FILE *fd; - char group[40], itf[40]; - - if ((fd = fopen(glist, "r")) == NULL) - printf("Error: unable to open %s\n", glist); - - while (fgets(buf, sizeof(buf), fd) != NULL) { - if (sscanf(buf, "%u.%u.%u.%u", &g1, &g2, &g3, &g4) != 4) { - fprintf(stderr, "bad group address\n"); - exit(1); - } - - imr->imr_multiaddr.s_addr = - htonl((g1 << 24) | (g2 << 16) | (g3 << 8) | g4); - - if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, - imr, sizeof(struct ip_mreq)) == -1) { - fprintf(stderr, "errno is %d \n", errno); - perror("can't join group"); - errors++; - } else { - strcpy(group, inet_ntoa(imr->imr_multiaddr)); - strcpy(itf, inet_ntoa(imr->imr_interface)); - printf("IPM group: %s added to interface: %s\n", group, - itf); - } - } - return (0); -} - -int leave_group(int s, char *glist, struct ip_mreq *imr) -{ - char buf[40]; - unsigned g1, g2, g3, g4; - FILE *fd; - char group[40], itf[40]; - - if ((fd = fopen(glist, "r")) == NULL) - printf("Error: unable to open %s\n", glist); - - while (fgets(buf, sizeof(buf), fd) != NULL) { - if (sscanf(buf, "%u.%u.%u.%u", &g1, &g2, &g3, &g4) != 4) { - fprintf(stderr, "leave_group: bad group address\n"); - exit(1); - } - - imr->imr_multiaddr.s_addr = - htonl((g1 << 24) | (g2 << 16) | (g3 << 8) | g4); - - if (setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, - imr, sizeof(struct ip_mreq)) == -1) { - perror("can't leave group"); - errors++; - } else { - strcpy(group, inet_ntoa(imr->imr_multiaddr)); - strcpy(itf, inet_ntoa(imr->imr_interface)); - printf("IPM group: %s dropped from interface: %s\n", - group, itf); - } - } - return (0); -} - -void usage() -{ - fprintf(stderr, - "usage: %s [ -j -l ] -g group_list [-s time_to_sleep] -i interface_name (or i.i.i.i)\n", - prog); - exit(1); -} -- 1.9.3 ------------------------------------------------------------------------------ Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list