Commit 3f1c8016 authored by Clément Stenac's avatar Clément Stenac

* broadcast.h , broadcast.cpp , parser.cpp , parser.h ,

  sapserver.cpp,sap.cfg

IPv6 SAP support. Not very useful at the moment since VLC doesn't
support it, however.
It will only work for link-local streaming at the moment,since the SAP
address depends on the prefix, but it will be the more likely case.
You now have the ipversion= configuration option (6 for IPv6,anything
else for ipv4).

* Makefile: Use intelligent compilation and compilation options

* all: check system calls and take the appropriate action

* parser.cpp , parser.h , sapserver.cpp: -s option to display dots.
parent 100f4acc
......@@ -19,6 +19,5 @@ 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
VERSION=0.2.0
CFLAGS= -Wall -Wstrict-prototypes
FILES=program message parser broadcast
FILES_O=$(FILES:%=%.o)
GPP= g++ $(CFLAGS)
default: all
all:
g++ -Wall -c -o program.o program.cpp
g++ -Wall -c -o message.o message.cpp
g++ -Wall -c -o parser.o parser.cpp
g++ -Wall -c -o broadcast.o broadcast.cpp
g++ -Wall -o sapserver sapserver.cpp message.o parser.o program.o broadcast.o -DVERSION=\"$(VERSION)\"
# Main target. Build .o files from every.cpp files and build the final
# executable
all: $(FILES_O)
$(GPP) -o sapserver $(FILES_O) sapserver.cpp -DVERSION=\"$(VERSION)\"
# Target that builds a .o from each .cpp
$(FILES_O): %.o: %.cpp %.h
$(GPP) -c $*.cpp
# Delete the .o files and the executable
clean:
rm -f sapserver message.o program.o parser.o broadcast.o
rm -f $(FILES_O)
rm -f sapserver
# Cleans and remove the dists
distclean: clean
rm -f miniSAPserver-${VERSION}.tar.bz2
rm -f miniSAPserver-${VERSION}.tar.gz
# Makes the dists.
dist:
-# Check that tmp isn't in the way
@if test -e tmp; then \
......
......@@ -2,7 +2,7 @@
* broadcast.cpp : SAP Broadcast class
****************************************************************************
* Copyright (C) 1998-2003 VideoLAN
* $Id: broadcast.cpp,v 1.1 2003/05/22 02:22:45 nitrox Exp $
* $Id: broadcast.cpp,v 1.2 2003/06/14 21:45:12 zorglub Exp $
*
* Authors: Damien Lucas <nitrox@videolan.org>
*
......@@ -41,7 +41,6 @@ using namespace std;
Broadcast::Broadcast(unsigned int t)
{
group=HELLO_GROUP;
port=HELLO_PORT;
ttl=t;
return;
......@@ -51,8 +50,9 @@ Broadcast::Broadcast(unsigned int t)
Broadcast::~Broadcast(){return;}
int Broadcast::Init(void)
int Broadcast::Initv4(void)
{
group=SAP_IPV4_ADDR;
if ((fd=socket(AF_INET,SOCK_DGRAM,0)) < 0)
{
perror("socket");
......@@ -60,34 +60,88 @@ int Broadcast::Init(void)
}
/* set up destination address */
memset(&addr,0,sizeof(addr));
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=inet_addr(group);
addr.sin_port=htons(port);
setsockopt( fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl) );
memset( &addr , 0 , sizeof(addr) );
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(group);
addr.sin_port = htons(port);
if(setsockopt( fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl) ))
{
perror("setsockopt");
return(-1);
}
return 0;
}
int Broadcast::Initv6(void)
{
group = SAP_IPV6_LOCAL_ADDR;
unsigned char ip_address[16];
if ((fd=socket(AF_INET6,SOCK_DGRAM,0)) < 0)
{
perror("socket");
return(-1);
}
int i_status = inet_pton(AF_INET6,group,ip_address);
if(i_status < 0 )
{
perror("inet_pton");
return(-1);
}
else if(i_status == 0)
{
fprintf(stderr,"Adresse de diffusion SAP invalide\n");
return(-1);
}
/* set up destination address */
memset(&addr_v6,0,sizeof(addr_v6));
addr_v6.sin6_family = AF_INET6;
addr_v6.sin6_flowinfo = 0;
addr_v6.sin6_addr.s6_addr = ip_address;
addr_v6.sin6_port = htons(port);
if(setsockopt( fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl) ))
{
perror("setsockopt");
return(-1);
}
return 0;
}
int Broadcast::Send(Message* m)
int Broadcast::Send(Message* m,int version)
{
/* Create the final message */
m->CreateFinalMessage();
int i_status;
/* Get the message and the length */
char* message=m->GetFinalMessage();
unsigned int length=m->GetFinalMessageLen();
char* message = m->GetFinalMessage();
unsigned int length = m->GetFinalMessageLen();
if(message==NULL)
{
fprintf(stderr, "Bad message, skipping\n");
return (-1);
}
if(version == 6)
i_status=sendto(fd,message,length,0,
(struct sockaddr *) &addr_v6,sizeof(addr_v6));
if (sendto(fd,message,length,0,
(struct sockaddr *) &addr,sizeof(addr)) < 0)
else
i_status=sendto(fd,message,length,0,
(struct sockaddr *) &addr,sizeof(addr));
if(i_status < 0 )
{
perror("sendto");
return(-1);
}
return 0;
}
......@@ -2,7 +2,7 @@
* broacast.h : SAP Broadcast Class definition
****************************************************************************
* Copyright (C) 1998-2003 VideoLAN
* $Id: broadcast.h,v 1.1 2003/05/22 02:22:45 nitrox Exp $
* $Id: broadcast.h,v 1.2 2003/06/14 21:45:12 zorglub Exp $
*
* Authors: Damien Lucas <nitrox@videolan.org>
*
......@@ -22,19 +22,22 @@
*****************************************************************************/
#define HELLO_PORT 9875
#define HELLO_GROUP "224.2.127.254"
#define SAP_IPV4_ADDR "224.2.127.254"
#define SAP_IPV6_LOCAL_ADDR "FF02:0:0:0:0:0:2:7FFE"
class Broadcast {
public:
Broadcast(unsigned int t);
~Broadcast();
int Init(void);
int Send(Message*);
int Initv4(void);
int Initv6(void);
int Send(Message*,int);
private:
int fd; /* File descriptor on the socket */
struct sockaddr_in addr; /* IP Address to broadcast to */
struct sockaddr_in6 addr_v6; /* IPv6 Address to broadcast to */
char* group;
uint16_t port;
unsigned int ttl;
......
......@@ -2,7 +2,7 @@
* message.cpp : SAP Message class
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: message.cpp,v 1.3 2003/05/25 21:41:19 alexis Exp $
* $Id: message.cpp,v 1.4 2003/06/14 21:45:12 zorglub Exp $
*
* Authors: Damien Lucas <nitrox@videolan.org>
* Philippe Van Hecke <philippe.vanhecke@belnet.be>
......@@ -179,8 +179,11 @@ void Message::CreateFinalMessage(void)
{
msg[i]=sdp[i-header_len];
}
}
char* Message::GetFinalMessage(){return msg;}
unsigned int Message::GetFinalMessageLen(){return msg_len;}
......@@ -2,7 +2,7 @@
* parser.cpp : SAP configuration file parser
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: parser.cpp,v 1.2 2003/05/25 21:41:19 alexis Exp $
* $Id: parser.cpp,v 1.3 2003/06/14 21:45:12 zorglub Exp $
*
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
......@@ -76,10 +76,27 @@ void Config::SetDaemonMode(bool d)
daemon=true;
}
bool Config::GetDotMode(void)
{
return dot;
}
void Config::SetDotMode(bool d)
{
dot=true;
}
void Config::SetFile(char* s)
{
file=s;
}
int Config::GetIPVersion()
{
return ipversion;
}
/**********************************************************
* Gets what is before delim in source. Puts it into dest *
**********************************************************/
......@@ -155,6 +172,11 @@ int Config::Parse()
ttl=atoi(tline);
}
if(strstr(line,"ipversion="))
{
strgeta(line,tline,'=');
ipversion=atoi(tline);
}
if(strstr(line,"[program]"))
......
......@@ -2,7 +2,7 @@
* parser.h : SAP configuration file parser definition
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: parser.h,v 1.1 2003/05/22 02:22:45 nitrox Exp $
* $Id: parser.h,v 1.2 2003/06/14 21:45:12 zorglub Exp $
*
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
......@@ -34,13 +34,18 @@ class Config
void SetTTL(unsigned int);
bool GetDaemonMode(void);
void SetDaemonMode(bool);
void SetDotMode(bool);
bool GetDotMode(void);
void SetFile(char*);
int GetIPVersion();
vector<Program*> Programs;
private:
string file;
int ttl;
int ipversion;
bool daemon;
bool dot;
void strgetb(char *source,char *dest,char delim);
void strgeta(char *source,char *dest,char delim);
};
# sap.cfg - Configuration file of the mini SAP server
[global]
ttl=15 # TTL (Time To Live) of the SAP announces
ttl=255 # TTL (Time To Live) of the SAP announces. You should put 255
ipversion=4 # Version of IP Protocol to use: 4 for IPv4, 6 for IPv6
# Then you should have one "[program]" section per program announced
......
......@@ -2,7 +2,7 @@
* sapserver.cpp : SAP discovery service mini-server
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: sapserver.cpp,v 1.10 2003/05/25 22:08:48 alexis Exp $
* $Id: sapserver.cpp,v 1.11 2003/06/14 21:45:12 zorglub Exp $
*
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
......@@ -53,7 +53,8 @@ void help(void)
printf("Options:\n" \
"-d : Use this to daemonize the process (run in the background)\n" \
"-f or -c: Use this to give a configuration file (default is %s)\n" \
"-h: Display this help\n" ,DEFAULT_CONF);
"-h: Display this help\n" \
"-s: Display a dot for each packet sent\n",DEFAULT_CONF);
}
/*************************************************
......@@ -62,6 +63,7 @@ void help(void)
int main(int argc, char *argv[])
{
int result=0;
int i_init_status=0;
char getopt_string[128];
Broadcast* broadcast;
Message *message;
......@@ -72,7 +74,7 @@ int main(int argc, char *argv[])
config=new Config(DEFAULT_CONF);
/* Parse the command line */
sprintf(getopt_string,"dhf:c:");
sprintf(getopt_string,"dhsf:c:");
while(result !=-1)
{
result=getopt(argc,argv,getopt_string);
......@@ -80,6 +82,8 @@ int main(int argc, char *argv[])
{
config->SetFile(optarg);
}
if(result=='s')
config->SetDotMode(true);
if(result=='d')
{
config->SetDaemonMode(true);
......@@ -99,16 +103,32 @@ int main(int argc, char *argv[])
fprintf(stderr, "+ Parsing failed\n");
return(-1);
}
//TODO check configuration
/*TODO check configuration */
fprintf(stdout, "+ %d programs loaded\n",(int)config->Programs.size());
fprintf(stdout, "+ Packet TTL set to %i\n",config->GetTTL());
if(config->GetDaemonMode()) fprintf(stdout, "+ Running as daemon.\n");
else fprintf(stdout, "+ Running as program.\n");
/* Creating the broadcast object */
/* Create the broadcast object */
/* IPv4 is the default behavior */
broadcast = new Broadcast(config->GetTTL());
broadcast->Init();
if(config->GetIPVersion() == 6)
{
fprintf(stdout,"+ Using IPv6\n");
i_init_status=broadcast->Initv6();
}
else
{
fprintf(stdout,"+ Using IPv4\n");
i_init_status=broadcast->Initv4();
}
if(i_init_status)
{
fprintf(stderr,"- Network initialization failed. Aborting\n");
return -1;
}
/* Forking if necessary */
if(config->GetDaemonMode())
......@@ -129,10 +149,15 @@ int main(int argc, char *argv[])
/* Add the program */
message->AddProgram(config->Programs[i]);
/* Send the message */
broadcast->Send(message);
if(broadcast->Send( message , config->GetIPVersion() ))
fprintf(stderr,"- Message send failed\n");
/* Delete the message */
delete message;
if(config->GetDotMode())
fprintf(stdout,".");
}
fflush(stdout);
/* Wait for next sending */
sleep(SAP_DELAY);
}
......
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