Commit bddb3c84 authored by Damien Lucas's avatar Damien Lucas

Code cleaning (and tabs removing)

parent 856e9942
......@@ -2,7 +2,7 @@
* broadcast.cpp : SAP Broadcast class
****************************************************************************
* Copyright (C) 1998-2003 VideoLAN
* $Id: broadcast.cpp,v 1.5 2003/06/18 13:48:22 sam Exp $
* $Id: broadcast.cpp,v 1.6 2003/07/24 17:09:22 nitrox Exp $
*
* Authors: Damien Lucas <nitrox@videolan.org>
*
......@@ -67,8 +67,8 @@ int Broadcast::Initv4(void)
if(setsockopt( fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl) ))
{
perror("setsockopt");
return(-1);
perror("setsockopt");
return(-1);
}
return 0;
}
......@@ -76,12 +76,12 @@ int Broadcast::Initv4(void)
int Broadcast::Initv6(char scope)
{
group=(char *)malloc(32 * sizeof(char)); /* Size of an IPv6 address */
if(!group)
{
perror("malloc");
return(-1);
}
perror("malloc");
return(-1);
}
sprintf( group , "%s%c%s" , SAP_IPV6_ADDR_1 , scope , SAP_IPV6_ADDR_2);
unsigned char ip_address[sizeof(addr_v6.sin6_addr.s6_addr)];
......@@ -92,23 +92,23 @@ int Broadcast::Initv6(char scope)
}
/* XXX: under Win32, use _getaddrinfo and memcpy instead */
int i_status = inet_pton(AF_INET6,group,ip_address);
int i_status = inet_pton(AF_INET6,group,ip_address);
if(i_status < 0 )
{
perror("inet_pton");
return(-1);
perror("inet_pton");
return(-1);
}
else if(i_status == 0)
{
fprintf(stderr,"Adresse de diffusion SAP invalide\n");
return(-1);
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_port = htons(port);
addr_v6.sin6_family = AF_INET6;
addr_v6.sin6_flowinfo = 0;
addr_v6.sin6_port = htons(port);
memcpy( &addr_v6.sin6_addr.s6_addr, ip_address,
sizeof(addr_v6.sin6_addr.s6_addr) );
......@@ -141,10 +141,10 @@ int Broadcast::Send(Message* m,int version)
return (-1);
}
if(version == 6)
i_status=sendto(fd,message,length,0,
i_status=sendto(fd,message,length,0,
(struct sockaddr *) &addr_v6,sizeof(addr_v6));
else
else
i_status=sendto(fd,message,length,0,
(struct sockaddr *) &addr,sizeof(addr));
......@@ -155,6 +155,5 @@ int Broadcast::Send(Message* m,int version)
return(-1);
}
return 0;
}
......@@ -2,7 +2,7 @@
* message.cpp : SAP Message class
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: message.cpp,v 1.5 2003/06/16 10:26:47 zorglub Exp $
* $Id: message.cpp,v 1.6 2003/07/24 17:09:22 nitrox Exp $
*
* Authors: Damien Lucas <nitrox@videolan.org>
* Philippe Van Hecke <philippe.vanhecke@belnet.be>
......@@ -146,11 +146,11 @@ void Message::AddProgram(Program *p)
fprintf(stderr, "Announcing permanent session instead\n");
}
string m="m=audio "+p->GetPort()+" udp 14\n";
string c;
if(p->GetIPVersion() == 6)
c="c=IN IP6 ["+p->GetAddress()+"]/"+p->GetTTL()+"\n";
c="c=IN IP6 ["+p->GetAddress()+"]/"+p->GetTTL()+"\n";
else
c="c=IN IP4 "+p->GetAddress()+"/"+p->GetTTL()+"\n";
// TODO ttl type should be specified
......
/*****************************************************************************
* parser.h : SAP configuration file parser definition
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: parser.h,v 1.3 2003/06/16 10:26:47 zorglub Exp $
* Copyright (C) 1998-2003 VideoLAN
* $Id: parser.h,v 1.4 2003/07/24 17:09:22 nitrox Exp $
*
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* program.cpp : SAP Program class
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: program.cpp,v 1.6 2003/06/20 12:07:41 zorglub Exp $
* $Id: program.cpp,v 1.7 2003/07/24 17:09:22 nitrox Exp $
*
* Authors: Damien Lucas <nitrox@videolan.org>
* Philippe Van Hecke <philippe.vanhecke@belnet.be>
......@@ -36,12 +36,12 @@ using namespace std;
Program::Program()
{
/* Set default Values */
permanent = true;
program_ipversion = 4;
program_ttl = "15";
machine = "localhost";
user = "VideoLAN";
site = "http://www.videolan.org";
permanent = true;
program_ipversion = 4;
program_ttl = "15";
machine = "localhost";
user = "VideoLAN";
site = "http://www.videolan.org";
return;
}
Program::~Program() {return;}
......@@ -66,10 +66,10 @@ void Program::SetAddress(char* a){address=a;}
void Program::SetPort(char* p)
{
int i_port=atoi(p);
char psz_port[12];
sprintf(psz_port,"%i",i_port);
port +=psz_port;
int i_port=atoi(p);
char psz_port[12];
sprintf(psz_port,"%i",i_port);
port +=psz_port;
}
......
......@@ -2,7 +2,7 @@
* program.h : SAP programs classes definition
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: program.h,v 1.5 2003/06/16 15:30:12 zorglub Exp $
* $Id: program.h,v 1.6 2003/07/24 17:09:22 nitrox Exp $
*
* Authors: Damien Lucas <nitrox@videolan.org>
*
......@@ -28,7 +28,7 @@ class Program
Program(string, string, string, string, string,string);
Program();
~Program();
/* Functions to get the values */
string GetName();
string GetUser();
......@@ -48,7 +48,7 @@ class Program
void SetPort(char *);
void SetTTL(char *);
void SetIPVersion(char *);
bool IsPermanent();
private:
......
......@@ -2,7 +2,7 @@
* sapserver.cpp : SAP discovery service mini-server
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: sapserver.cpp,v 1.12 2003/06/16 10:26:47 zorglub Exp $
* $Id: sapserver.cpp,v 1.13 2003/07/24 17:09:22 nitrox Exp $
*
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
......@@ -51,10 +51,11 @@ using namespace std;
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" \
"-s: Display a dot for each packet sent\n",DEFAULT_CONF);
" -d Use this to daemonize the process (run in the background)\n" \
" -f Use this to give a configuration file (default is %s)\n" \
" -c Same as -f\n" \
" -h Display this help\n" \
" -s Display a dot for each packet sent\n",DEFAULT_CONF);
}
/*************************************************
......@@ -75,23 +76,25 @@ int main(int argc, char *argv[])
/* Parse the command line */
sprintf(getopt_string,"dhsf:c:");
while(result !=-1)
while((result = getopt(argc,argv,getopt_string))>0)
{
result=getopt(argc,argv,getopt_string);
if(result=='c' || result=='f')
switch(result)
{
config->SetFile(optarg);
}
if(result=='s')
config->SetDotMode(true);
if(result=='d')
{
config->SetDaemonMode(true);
}
if(result=='h')
{
help();
return(0);
case 'c':
case 'f':
config->SetFile(optarg);
break;
case 's':
config->SetDotMode(true);
break;
case 'd':
config->SetDaemonMode(true);
break;
case 'h':
help();
return ( 0 );
default:
return ( -1 );
}
}
......@@ -114,20 +117,20 @@ int main(int argc, char *argv[])
broadcast = new Broadcast(config->GetTTL());
if(config->GetIPVersion() == 6)
{
fprintf(stdout,"+ Using IPv6\n");
i_init_status=broadcast->Initv6(config->GetScope());
fprintf(stdout,"+ Using IPv6\n");
i_init_status=broadcast->Initv6(config->GetScope());
}
else
{
fprintf(stdout,"+ Using IPv4\n");
i_init_status=broadcast->Initv4();
}
fprintf(stdout,"+ Using IPv4\n");
i_init_status=broadcast->Initv4();
}
if(i_init_status)
{
fprintf(stderr,"- Network initialization failed. Aborting\n");
return -1;
fprintf(stderr,"- Network initialization failed. Aborting\n");
return -1;
}
/* Forking if necessary */
......@@ -150,14 +153,14 @@ int main(int argc, char *argv[])
message->AddProgram(config->Programs[i]);
/* Send the message */
if(broadcast->Send( message , config->GetIPVersion() ))
fprintf(stderr,"- Message send failed\n");
fprintf(stderr,"- Message send failed\n");
/* Delete the message */
delete message;
if(config->GetDotMode())
fprintf(stdout,".");
if(config->GetDotMode())
fprintf(stdout,".");
}
fflush(stdout);
fflush(stdout);
/* Wait for next sending */
sleep(SAP_DELAY);
}
......
/*****************************************************************************
* sapserver.cpp : SAP discovery service classes definition
* sapserver.h : SAP discovery service classes definition
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: sapserver.h,v 1.5 2003/06/20 11:44:49 alexis Exp $
* $Id: sapserver.h,v 1.6 2003/07/24 17:09:22 nitrox Exp $
*
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
......@@ -30,7 +30,7 @@
#define MSGBUFSIZE 256
#define DEFAULT_CONF "/etc/sap.cfg"
#define DEFAULT_CONF "/etc/sap.cfg"
#define DEFAULT_TTL 10
#define DEFAULT_SCOPE "8"
#define DEFAULT_PORT "1234"
......
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