Commit 9b612d0e authored by Clément Stenac's avatar Clément Stenac

* AUTHORS: updated the list

* sapserver.cpp:
  * Use C-style comments
  * Added many comments
  * Fixed a stupid bug that prevented to use the -d option after the -c
  * Added a minimalistic help function.

* Makefile: use of "rm -f" for clean is better

* sap.cfg: restored the right file.
parent 1169b53c
......@@ -5,6 +5,11 @@
# The fields are: name (N), email (E), web-address (W), CVS account login (C),
# PGP key ID and fingerprint (P), description (D), and snail-mail address (S).
N: Fabrice Ollivier
E: cif@via.ecp.fr
D: Core
S: France
N: Arnaud Schauly
E: gitan@via.ecp.fr
C: gitan
......@@ -14,5 +19,6 @@ S: France
N: Clment Stenac
E: zorglub@via.ecp.fr
C: zorglub
P: A6C805B9 866D 7D6C C6B0 7DA8 2660 738C AD26 ED82 A6C8 05B9
D: Core
S: France
......@@ -4,6 +4,6 @@ all: sapserver
g++ -Wall -o sapserver sapserver.cpp
clean:
rm sapserver
rm -f sapserver
distclean: clean
......@@ -7,51 +7,16 @@ ttl=15 # TTL (Time To Live) of the SAP announces
# Then you should have one "[program]" section per program announced
[program]
name=M6
user=videolan
machine=vlcs.via.ecp.fr
site=www.videolan.org
address=239.255.12.12
[program]
name=France 5
user=videolan
machine=vlcs.via.ecp.fr
site=www.videolan.org
address=239.255.12.13
#[program]
#name=EuroNews
#user=videolan
#machine=vlcs.via.ecp.fr
#site=www.videolan.org
#address=239.255.12.14
[program]
name=Star Wars II
user=videolan
machine=vlcs.via.ecp.fr
site=www.videolan.org
address=239.255.12.15
[program]
name=Le Voyage de Chihiro
user=videolan
machine=vlcs.via.ecp.fr
site=www.videolan.org
address=239.255.12.16
name=TV1 # Name of the program (as will show up in the VLC playlist)
user=videolan# Name of the streaming entity
machine=vlcs.via.ecp.fr # Name of the streaming machine
site=www.videolan.org # Site of the streaming entity
address=239.255.12.12 # Multicast IP address of the program
[program]
name=Delicatessen
name=TV2
user=videolan
machine=vlcs.via.ecp.fr
site=www.videolan.org
address=239.255.12.17
[program]
name=Matrix
user=videolan
machine=vlcs.via.ecp.fr
site=www.videolan.org
address=239.255.12.18
address=239.255.12.13
/*****************************************************************************
* sapsend.cpp : SAP discovery service mini-server
* sapserver.cpp : SAP discovery service mini-server
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: sapserver.cpp,v 1.5 2003/05/18 11:58:59 zorglub Exp $
*
* Authors: Arnaud Schauly <gitan@via.ecp.fr>
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
* Clment Stenac <zorglub@via.ecp.fr>
*
*
*
* 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
......@@ -34,18 +36,23 @@
#include <stdio.h>
#include <pthread.h>
#define PROGRAM_NAME "mini-SAP-Server"
#define VERSION "0.1.2"
#define DELAY 1 /* wait DELAY seconds before each sending */
#define HELLO_PORT 9875
#define HELLO_GROUP "224.2.127.254"
#define MSGBUFSIZE 256
#define DEFAULT_CONF "/etc/sap.cfg"
#define DEFAULT_CONF "/etc/sap.cfg"
unsigned int ttl=10; // Default TTL
unsigned int ttl=10; /* Default TTL */
struct prog
{
char name[64];
char user[16];
char name[128];
char user[128];
char machine[128];
char site[128];
char address[128];
......@@ -94,7 +101,10 @@ void itemlist::add(prog *itemp)
nbr++;
}
void strgetb(char *source,char *dest,char delim) // Get what is before delim in source and puts it into dest
/**********************************************************
* Gets what is before delim in source. Puts it into dest *
**********************************************************/
void strgetb(char *source,char *dest,char delim)
{
unsigned long i = 0;
while(source[i] != delim && i < strlen(source))
......@@ -105,7 +115,10 @@ void strgetb(char *source,char *dest,char delim) // Get what is before delim in
dest[i]=0;
}
void strgeta(char *source,char *dest,char delim) // Get what is after delim in source and puts it into dest
/**********************************************************
* Gets what is before delim in source. Puts it into dest *
**********************************************************/
void strgeta(char *source,char *dest,char delim)
{
unsigned long i=0,j=0;
dest[0]=0;
......@@ -129,7 +142,7 @@ void strgeta(char *source,char *dest,char delim) // Get what is after delim in
/********************************************************************
Read the configuration file and fill the program list
Reads the configuration file and fills the program list
*********************************************************************/
int parse(char *path,itemlist *progs)
{
......@@ -155,12 +168,16 @@ int parse(char *path,itemlist *progs)
break;
}
strgetb(ligne,ligne,'#');
strgetb(ligne,ligne,'#'); /* Handle the comments */
if(strstr(ligne,"ttl=")) {strgeta(ligne,tligne,'=');ttl=atoi(tligne);}
if(strstr(ligne,"ttl="))
{
strgeta(ligne,tligne,'=');
ttl=atoi(tligne);
}
if(strstr(ligne,"[program]"))
{
if(something)
if(something) /* We were in a program with at least one field filled */
{
progs->add(pp);
pp=new prog;
......@@ -199,7 +216,8 @@ int parse(char *path,itemlist *progs)
if(strstr(ligne,"address="))
{
strgeta(ligne,tligne,'=');
something=1;strcpy(pp->address,tligne);
something=1;
strcpy(pp->address,tligne);
}
}
......@@ -207,6 +225,16 @@ int parse(char *path,itemlist *progs)
return(0);
}
/*************************************************
* Display the help
*************************************************/
void help(void)
{
printf("Options:
-d : Use this to daemonize the process (run in the background)
-f or -c: Use this to give a configuration file (default is %s)
-h: Display this help\n" ,DEFAULT_CONF);
}
/*************************************************
* The main function
*************************************************/
......@@ -221,18 +249,28 @@ int main(int argc, char *argv[])
bool godaemon;
itemlist *progs=new itemlist;
printf("SapSend.\n");
printf("%s Version %s\n",PROGRAM_NAME,VERSION);
sprintf(conffile,DEFAULT_CONF);
// Parse the command line
sprintf(getopt_string,"f:c:d");
/* Parse the command line */
sprintf(getopt_string,"dhf:c:");
while(result !=-1)
{
result=getopt(argc,argv,getopt_string);
if(result=='c' || result=='f') {sprintf(conffile,optarg);break;}
if(result=='d') godaemon=1;
if(result=='c' || result=='f')
{
sprintf(conffile,optarg);
}
if(result=='d')
{
godaemon=1;
}
if(result=='h')
{
help();return(0);
}
}
// Get the programs
/* Get the programs */
printf("Parsing configuration file\n");
if(parse(conffile,progs))
return(-1);
......@@ -240,7 +278,7 @@ int main(int argc, char *argv[])
printf("Packet TTL set to %i\n",ttl);
prog *pp;
// Prepare the socket
/* Prepare the socket */
printf("Setting up the socket\n");
if ((fd=socket(AF_INET,SOCK_DGRAM,0)) < 0)
{
......@@ -248,14 +286,14 @@ int main(int argc, char *argv[])
exit(1);
}
// set up destination address
/* set up destination address */
memset(&addr,0,sizeof(addr));
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=inet_addr(HELLO_GROUP);
addr.sin_port=htons(HELLO_PORT);
setsockopt( fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl) );
// Start sending
/* Begin sending */
printf("Socket ready, sending started\n");
if(godaemon)
{
......@@ -264,7 +302,7 @@ int main(int argc, char *argv[])
while(1)
{
pp=progs->getfirst();
// Navigate through programs
/* Navigate through program-list */
while(pp!=NULL)
{
if(!strlen(pp->name) || !strlen(pp->address))
......@@ -273,7 +311,7 @@ int main(int argc, char *argv[])
pp=pp->Next;
exit(1);
}
// Build the message
/* Build the message */
sprintf(message," ***øv=0 \n\
o=%s 3247692199 3247895918 IN IP4 %s \n\
s=%s\n\
......@@ -285,7 +323,7 @@ int main(int argc, char *argv[])
xxxxxxxxxxxxxxxxxxxxx \n ",pp->user,pp->machine,pp->name, \
pp->site,pp->address);
// Send it through the socket
/* Send it through the socket */
if (sendto(fd,message,strlen(message),0, \
(struct sockaddr *) &addr,sizeof(addr)) < 0)
{
......@@ -294,6 +332,6 @@ int main(int argc, char *argv[])
}
pp=pp->Next;
}
sleep(1); // Wait 1 second between each sending
sleep(DELAY); /* Wait DELAY second between each sending */
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment