BlinkenArea - GitList
Repositories
Blog
Wiki
BlinkenLib
Code
Commits
Branches
Tags
Search
Tree:
d33aef3
Branches
Tags
master
v0.1
v0.2
v0.3
v0.3.1
v0.4
v0.4.1
v0.5
v0.5.1
v0.5.2
v0.5.3
v0.5.4
v0.5.5
v0.6.0
v0.6.1
v0.6.2
v0.6.3
v0.6.4
v0.6.5
v0.6.6
v0.6.7
v0.6.8
v0.6.9
v0.7.0
v0.7.1
v0.7.10
v0.7.2
v0.7.3
v0.7.4
v0.7.5
v0.7.6
v0.7.7
v0.7.8
v0.7.9
v0.8.0
v0.8.1
BlinkenLib
BlinkenSend.c
BlinkenLib v.0.4 (2005-07-02)
Christian Heimke
commited
d33aef3
at 2011-07-15 09:02:58
BlinkenSend.c
Blame
History
Raw
/* BlinkenLib * version 0.4 date 2005-07-02 * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html * a blinkenarea.org project * powered by eventphone.de */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include "BlinkenLib.h" int main( int argCnt, char * * args ) { int i, udpSocket, connected; etBlinkenProto proto; char txt[64]; unsigned short port; struct sockaddr_in addr; stBlinkenMovie * pMovie; //print info printf( "BlinkenLib - BlinkenSend\n" "version 0.4 date 2005-07-02\n" "Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info>\n" "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" "a blinkenarea.org project\n" "powered by eventphone.de\n\n" ); //print syntax if( argCnt <= 1 ) { printf( "syntax: %s <parameter> [...]\n\n" "parameters:\n" " -s [<ip>:]<port>\n" " source address (defaults to 0.0.0.0:0)\n" " must occur before -d and -i, may only occur once\n" " -d <ip>[:<port>]\n" " destination addess (defaults to 127.0.0.1:2323)\n" " -p [BLP|EBLP|MCUF]\n" " protocol to use (defaults to MCUF)\n" " -i <file>\n" " read movie from file (*.blm, *.bmm, *.bml, *.bbm) and send it\n\n", args[0] ); return 0; } //create udp socket udpSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); if( udpSocket == -1 ) { printf( "cannot create UDP socket\n" ); return -1; } connected = 0; //process parameters proto = BlinkenProtoMcuf; for( i = 1; i < argCnt; i++ ) { //source address if( strcmp( args[i], "-s" ) == 0 ) { if( i + 1 < argCnt ) { i++; if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 ) { addr.sin_family = AF_INET; addr.sin_port = htons( port ); addr.sin_addr.s_addr = inet_addr( txt ); if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) printf( "could not set source address to \"%s\"\n", args[i] ); } else if( sscanf( args[i], "%hu", &port ) == 1 ) { addr.sin_family = AF_INET; addr.sin_port = htons( port ); addr.sin_addr.s_addr = htonl( INADDR_ANY ); if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) printf( "could not set source address to \"%s\"\n", args[i] ); } else printf( "invalid source address \"%s\"\n", args[i] ); } else printf( "missing source address for \"-s\"\n" ); } //destination address else if( strcmp( args[i], "-d" ) == 0 ) { if( i + 1 < argCnt ) { i++; if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 ) { addr.sin_family = AF_INET; addr.sin_port = htons( port ); addr.sin_addr.s_addr = inet_addr( txt ); if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) printf( "could not set destination address to \"%s\"\n", args[i] ); else connected = 1; } else if( sscanf( args[i], "%32[0-9.]", txt ) == 1 ) { addr.sin_family = AF_INET; addr.sin_port = htons( 2323 ); addr.sin_addr.s_addr = inet_addr( txt ); if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) printf( "could not set destination address to \"%s\"\n", args[i] ); else connected = 1; } else printf( "invalid destination address \"%s\"\n", args[i] ); } else printf( "missing destination address for \"-d\"\n" ); } //protocol to use else if( strcmp( args[i], "-p" ) == 0 ) { if( i + 1 < argCnt ) { i++; if( strcasecmp( args[i], "BLP" ) == 0 ) proto = BlinkenProtoBlp; else if( strcasecmp( args[i], "EBLP" ) == 0 ) proto = BlinkenProtoEblp; else if( strcasecmp( args[i], "MCUF" ) == 0 ) proto = BlinkenProtoMcuf; else printf( "unknown protocol \"%s\"\n", args[i] ); } else printf( "missing protocol for \"-p\"\n" ); } //read movie and sent it else if( strcmp( args[i], "-i" ) == 0 ) { if( i + 1 < argCnt ) { i++; if( ! connected ) //try to connect if not yet connected { printf( "no destination address to sent movie \"%s\" to,\n" " using default destination address \"127.0.0.1:2323\"\n", args[i] ); addr.sin_family = AF_INET; addr.sin_port = htons( 2323 ); addr.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) printf( "could not set destination address to \"127.0.0.1:2323\"\n" ); else connected = 1; } if( connected ) { pMovie = BlinkenMovieLoad( args[i] ); if( pMovie == NULL ) printf( "could not read movie \"%s\"\n", args[i] ); else { printf( "movie \"%s\" read - sending...\n", args[i] ); BlinkenMovieSend( pMovie, udpSocket, proto ); printf( "movie \"%s\" sent\n", args[i] ); BlinkenMovieFree( pMovie ); } } else printf( "no destination address to sent movie \"%s\" to\n", args[i] ); } else printf( "missing input filename for \"-i\"\n" ); } //unknown parameter else printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] ); } //for( i ... //close socket close( udpSocket ); return 0; }