Commit 8942735a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

* netsync module no longer IPv4-specific

parent 3f2e13bc
...@@ -147,31 +147,28 @@ static void Run( intf_thread_t *p_intf ) ...@@ -147,31 +147,28 @@ static void Run( intf_thread_t *p_intf )
#define MAX_MSG_LENGTH (2 * sizeof(int64_t)) #define MAX_MSG_LENGTH (2 * sizeof(int64_t))
vlc_bool_t b_master = config_GetInt( p_intf, "netsync-master" ); vlc_bool_t b_master = config_GetInt( p_intf, "netsync-master" );
char *psz_master = config_GetPsz( p_intf, "netsync-master-ip" ); char *psz_master;
struct sockaddr_in master_addr;
char p_data[MAX_MSG_LENGTH]; char p_data[MAX_MSG_LENGTH];
int i_socket; int i_socket;
if( !psz_master || inet_addr( psz_master ) == INADDR_NONE ) if( !b_master )
{ {
if( !b_master ) psz_master = config_GetPsz( p_intf, "netsync-master-ip" );
if( psz_master == NULL )
{ {
if( psz_master ) free( psz_master ); msg_Err( p_intf, "master address not specified" );
msg_Err( p_intf, "invalid master address." );
return; return;
} }
if( !psz_master ) psz_master = strdup("");
} }
memset( &master_addr, 0, sizeof( struct sockaddr_in ) ); i_socket = net_OpenUDP( p_intf, NULL,
master_addr.sin_family = AF_INET; b_master ? NETSYNC_PORT_MASTER : NETSYNC_PORT_SLAVE,
master_addr.sin_port = htons( (uint16_t)NETSYNC_PORT_MASTER ); b_master ? NULL : psz_master,
master_addr.sin_addr.s_addr = inet_addr( psz_master ); b_master ? 0 : NETSYNC_PORT_MASTER );
free( psz_master );
i_socket = net_OpenUDP( p_intf, NULL, b_master ? NETSYNC_PORT_MASTER : if( !b_master )
NETSYNC_PORT_SLAVE, NULL, 0 ); free( psz_master );
if( i_socket < 0 ) if( i_socket < 0 )
{ {
msg_Err( p_intf, "failed opening UDP socket." ); msg_Err( p_intf, "failed opening UDP socket." );
...@@ -218,7 +215,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -218,7 +215,7 @@ static void Run( intf_thread_t *p_intf )
if( b_master ) if( b_master )
{ {
struct sockaddr_in from; struct sockaddr_storage from;
mtime_t i_date, i_clockref, i_master_clockref; mtime_t i_date, i_clockref, i_master_clockref;
int i_struct_size, i_read, i_ret; int i_struct_size, i_read, i_ret;
...@@ -233,12 +230,10 @@ static void Run( intf_thread_t *p_intf ) ...@@ -233,12 +230,10 @@ static void Run( intf_thread_t *p_intf )
} }
/* We received something */ /* We received something */
i_struct_size = sizeof(struct sockaddr_in); i_struct_size = sizeof( from );
i_read = recvfrom( i_socket, p_data, MAX_MSG_LENGTH, 0, i_read = recvfrom( i_socket, p_data, MAX_MSG_LENGTH, 0,
(struct sockaddr*)&from, &i_struct_size ); (struct sockaddr*)&from, &i_struct_size );
from.sin_port = htons( (uint16_t)NETSYNC_PORT_SLAVE );
i_clockref = ntoh64(*(int64_t *)p_data); i_clockref = ntoh64(*(int64_t *)p_data);
i_date = mdate(); i_date = mdate();
...@@ -249,11 +244,13 @@ static void Run( intf_thread_t *p_intf ) ...@@ -249,11 +244,13 @@ static void Run( intf_thread_t *p_intf )
/* Reply to the sender */ /* Reply to the sender */
sendto( i_socket, p_data, 2 * sizeof(int64_t), 0, sendto( i_socket, p_data, 2 * sizeof(int64_t), 0,
(struct sockaddr *)&from, sizeof(struct sockaddr_in) ); (struct sockaddr *)&from, i_struct_size );
msg_Dbg( p_intf, "Master clockref: "I64Fd" -> "I64Fd", from %s " msg_Dbg( p_intf, "Master clockref: "I64Fd" -> "I64Fd", from %s "
"(date: "I64Fd")", i_clockref, i_master_clockref, "(date: "I64Fd")", i_clockref, i_master_clockref,
inet_ntoa(from.sin_addr), i_date ); from.ss_family == AF_INET
? inet_ntoa(((struct sockaddr_in *)&from)->sin_addr)
: "non-IPv4", i_date );
} }
else else
{ {
...@@ -266,9 +263,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -266,9 +263,7 @@ static void Run( intf_thread_t *p_intf )
*(int64_t *)p_data = hton64( i_clockref ); *(int64_t *)p_data = hton64( i_clockref );
i_send_date = mdate(); i_send_date = mdate();
i_sent = sendto( i_socket, p_data, sizeof(int64_t), 0, i_sent = send( i_socket, p_data, sizeof(int64_t), 0 );
(struct sockaddr *)&master_addr,
sizeof(struct sockaddr_in) );
if( i_sent <= 0 ) if( i_sent <= 0 )
{ {
/* Wait a bit */ /* Wait a bit */
......
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