- char psz_msg[1000]; /* SDP content */
- char *psz_head; /* SAP header */
- char *psz_send; /* What we send */
- char *psz_type = "application/sdp";
- int i_header_size; /* SAP header size */
- int i_msg_size; /* SDP content size */
- int i_size; /* Total size */
- int i_ret = 0;
-
- /* We send a packet every 24 calls to the function */
- if( p_this->i_calls++ < 24 )
- {
- return;
- }
-
- i_header_size = 8 + strlen( psz_type ) + 1;
- psz_head = (char *) malloc( i_header_size * sizeof( char ) );
-
- if( ! psz_head )
- {
- msg_Err( p_sout, "out of memory" );
- return;
- }
-
- /* Create the SAP headers */
- psz_head[0] = 0x20; /* Means IPv4, not encrypted, not compressed */
- psz_head[1] = 0x00; /* No authentification */
- psz_head[2] = 0x42; /* Version */
- psz_head[3] = 0x12; /* Version */
-
- psz_head[4] = 0x01; /* Source IP FIXME: we should get the real address */
- psz_head[5] = 0x02; /* idem */
- psz_head[6] = 0x03; /* idem */
- psz_head[7] = 0x04; /* idem */
-
- strncpy( psz_head + 8, psz_type, 15 );
- psz_head[ i_header_size-1 ] = '\0';
-
- /* Create the SDP content */
- /* Do not add spaces at beginning of the lines ! */
- sprintf( psz_msg, "v=0\n"
- "o=VideoLAN 3247692199 3247895918 IN IP4 VideoLAN\n"
- "s=%s\n"
- "u=VideoLAN\n"
- "t=0 0\n"
- "m=audio %s udp 14\n"
- "c=IN IP4 %s/15\n"
- "a=type:test\n",
- p_this->psz_name, p_this->psz_port, p_this->psz_url );
-
- i_msg_size = strlen( psz_msg );
- i_size = i_msg_size + i_header_size;
-
- /* Create the message */
- psz_send = (char *) malloc( i_size*sizeof(char) );
- if( !psz_send )
- {
- msg_Err( p_sout, "out of memory" );
- return;
- }
-
- memcpy( psz_send, psz_head, i_header_size );
- memcpy( psz_send + i_header_size, psz_msg, i_msg_size );
-
- if( i_size < 1024 ) /* We mustn't send packets larger than 1024B */
- {
- if( p_this->i_ip_version == 6 )
- {
- i_ret = send( p_this->i_socket, psz_send, i_size, 0 );
- }
- else
- {
- i_ret = send( p_this->i_socket, psz_send, i_size, 0 );
- }
- }
-
- if( i_ret <= 0 )
- {
- msg_Warn( p_sout, "SAP send failed on socket %i (%s)",
- p_this->i_socket, strerror(errno) );
- }
-
- p_this->i_calls = 0;
-
- /* Free what we allocated */
- free( psz_send );
- free( psz_head );