1 /*****************************************************************************
2 * announce.c : Session announcement
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
6 * Authors: Clément Stenac <zorglub@via.ecp.fr>
7 * Damien Lucas <nitrox@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* free() */
29 #include <errno.h> /* ENOMEM */
30 #include <stdio.h> /* sprintf() */
40 # include <winsock2.h>
41 # include <ws2tcpip.h>
43 # define IN_MULTICAST(a) IN_CLASSD(a)
46 # include <sys/socket.h>
56 #define DEFAULT_PORT 1234
59 /*****************************************************************************
60 * sout_SLPBuildName: Builds a service name according to SLP standard
61 *****************************************************************************/
62 static char * sout_SLPBuildName(char *psz_url,char *psz_name)
67 /* name to build is: service:vlc.services.videolan://$(url) */
69 i_size = 8 + 12 + 12 + 5 + strlen(psz_url) + 1;
71 psz_service=(char *)malloc(i_size * sizeof(char));
73 snprintf( psz_service , i_size,
74 "service:vlc.services.videolan://udp:@%s",
78 psz_service[i_size]='\0'; /* Just to make sure */
84 /*****************************************************************************
85 * sout_SLPReport: Reporting function. Unused at the moment but needed
86 *****************************************************************************/
87 static void sout_SLPReport(SLPHandle slp_handle,SLPError slp_error,void* cookie)
92 /*****************************************************************************
93 * sout_SLPReg: Registers the program with SLP
94 *****************************************************************************/
95 int sout_SLPReg( sout_instance_t *p_sout, char * psz_url,
101 char *psz_service= sout_SLPBuildName(psz_url,psz_name);
103 if( SLPOpen( NULL, SLP_FALSE, &slp_handle ) != SLP_OK)
105 msg_Warn(p_sout,"Unable to initialize SLP");
109 msg_Info(p_sout , "Registering %s (name: %s) in SLP",
110 psz_service , psz_name);
112 slp_res = SLPReg ( slp_handle,
114 SLP_LIFETIME_MAXIMUM,
121 if( slp_res != SLP_OK )
123 msg_Warn(p_sout,"Error while registering service: %i", slp_res );
129 #else /* This function should never be called if this is false */
135 /*****************************************************************************
136 * sout_SLDePReg: Unregisters the program from SLP
137 *****************************************************************************/
138 int sout_SLPDereg( sout_instance_t *p_sout, char * psz_url,
143 SLPHandle slp_handle;
145 char *psz_service= sout_SLPBuildName(psz_url,psz_name);
147 if( SLPOpen( NULL, SLP_FALSE, &slp_handle ) != SLP_OK)
149 msg_Warn(p_sout,"Unable to initialize SLP");
153 msg_Info(p_sout , "Unregistering %s from SLP",
156 slp_res = SLPDereg ( slp_handle,
161 if( slp_res != SLP_OK )
163 msg_Warn(p_sout,"Error while registering service: %i", slp_res );
169 #else /* This function should never be called if this is false */