1 /*****************************************************************************
2 * announce.c : Session announcement
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
6 * Authors: Christophe Massiot <massiot@via.ecp.fr>
7 * Laurent Aimar <fenrir@via.ecp.fr>
8 * Eric Petit <titer@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* free() */
29 #include <stdio.h> /* sprintf() */
30 #include <string.h> /* strerror() */
40 #define SAP_ADDR "224.2.127.254"
43 /*****************************************************************************
44 * sout_SAPNew: Creates a SAP Session
45 *****************************************************************************/
46 sap_session_t * sout_SAPNew ( sout_instance_t *p_sout , char * psz_url_arg , char * psz_name_arg )
50 network_socket_t socket_desc;
52 struct sockaddr_in addr;
55 p_new = (sap_session_t *)malloc( sizeof ( sap_session_t ) ) ;
57 sprintf ( p_new->psz_url , "%s" , psz_url_arg );
58 sprintf ( p_new->psz_name , "%s" , psz_name_arg );
60 msg_Dbg (p_sout , "Creating SAP Socket" );
62 socket_desc.i_type = NETWORK_UDP;
63 socket_desc.psz_bind_addr = SAP_ADDR;
64 socket_desc.i_bind_port = SAP_PORT;
65 socket_desc.psz_server_addr = "";
66 socket_desc.i_server_port = 0;
67 socket_desc.i_handle = 0;
69 sprintf ( psz_network,"ipv4" );
71 p_sout->p_private=(void*) &socket_desc;
73 if( !( p_network = module_Need( p_sout, "network", psz_network ) ) )
75 msg_Warn( p_sout, "failed to open a connection (udp)" );
78 module_Unneed( p_sout, p_network );
80 p_new->socket = socket_desc.i_handle;
82 memset( &addr , 0 , sizeof(addr) );
83 addr.sin_family = AF_INET;
84 addr.sin_addr.s_addr = inet_addr(SAP_ADDR);
85 addr.sin_port = htons( SAP_PORT );
87 setsockopt( p_new->socket, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl) );
89 p_new->addr=(struct sockaddr_in)addr;
94 /*****************************************************************************
95 * sout_SAPDelete: Deletes a SAP Session
96 *****************************************************************************/
97 void sout_SAPDelete( sap_session_t * p_this )
99 shutdown(p_this->socket,0);
103 /*****************************************************************************
104 * sout_SAPSend: Sends a SAP packet
105 *****************************************************************************/
106 void sout_SAPSend( sout_instance_t *p_sout, sap_session_t * p_this )
109 char *user="VideoLAN";
110 char *machine="VideoLAN";
111 char *site="VideoLAN";
114 if(p_this->sendnow == 24)
116 sprintf(sap_msg," ***øv=0 \n\
117 o=%s 3247692199 3247895918 IN IP4 %s \n\
120 t=3247691400 3250117800 \n\
122 m=audio 1234 udp 14 \n\
124 xxxxxxxxxxxxxxxxxxxxx \n ",user,machine,p_this->psz_name,site,p_this->psz_url);
126 i_send_result = sendto( p_this->socket , sap_msg , strlen(sap_msg) , 0 , (struct sockaddr *)&p_this->addr , sizeof(p_this->addr) );
128 if(i_send_result == -1)
130 msg_Warn(p_sout , "SAP Send failed on socket %i. " , p_this->socket );