/*----------------------------------------------------------------* |client.cpp | |@version: 2.1 | |Last Modification: Oct 1st, 2003 , by Fei | | A simple SRTP client for testing | | The client works as a quiet receiver | *----------------------------------------------------------------*/ /*----------------------------------------------------------------* | Copyright 2001-2003 Networking and Simulation Laboratory | | George Mason University, Fairfax, Virginia | | | | Permission to use, copy, modify, and distribute this | | software and its documentation for academic purposes is hereby | | granted without fee, provided that the above copyright notice | | and this permission appear in all copies and in supporting | | documentation, and that the name of George Mason University | | not be used in advertising or publicity pertaining to | | distribution of the software without specific, written prior | | permission. GMU makes no representations about the suitability | | of this software for any purposes. It is provided "AS IS" | | without express or implied warranties. All risk associated | | with use of this software is expressly assumed by the user. | *----------------------------------------------------------------*/ #include #include "srtp_api.h" //#define mca "226.78.2.10" #define mca "224.0.0.100" unsigned long int mcg; void sigterm_handler(int sig); /* command line: client [udp_port] * where, udp_port is the udp port that SRTP daemon is listening on * for the request from local client * if the udp_port is not specified, 8001 is used */ int main(int argc, char* argv[]) { int dataid; int udp_port; char buffer[128000]; int len; int i; unsigned int message_byte; /* Install the signal handler */ if( signal(SIGINT, sigterm_handler) == SIG_ERR ) printf("Failed to initialize signal_handler\n"); /* parse the udp_port argument, which is the udp port that local * SRTP daemon listening on for client request */ udp_port=0; if(argc>1) udp_port=atoi(argv[1]); /* init the client */ if(srmp_init(udp_port) < 0) { fprintf(stderr, "Client init error\n"); return -1; } printf("Client initiated\n"); if ((mcg = inet_addr(mca)) == NULL) return(-1); /* subscribe the multicast group */ if(srmp_subscribe_mca(mcg)<0) { printf("srtp_subscribe_dataid failed for %s\n", mca); return -1; } printf("Client subscribe sucessfully: mca=%s, port=%d\n", mca, sock_port); while(1) { /* receive a message */ if(srmp_recv(buffer, &len, &dataid, &mcg)<0) { printf("receive error\n"); continue; } if(dataid>0) printf("message received: mode=1, dataid=%d, len=%d\n", dataid, len); else printf("message received: mode=0, len=%d\n", len); /* print out the content of the received message */ for ( i=0; i