+
+/*****************************************************************************
+ * __net_CheckIP
+ *****************************************************************************
+ * Check that a given IP is within a set of IP/netmask.
+ *****************************************************************************/
+int __net_CheckIP( vlc_object_t *p_this, char *psz_ip, char **ppsz_hosts,
+ int i_hosts )
+{
+ struct in_addr ip;
+ int i;
+
+ if( !inet_aton( psz_ip, &ip ) )
+ {
+ return VLC_EGENERIC;
+ }
+
+ for( i = 0; i < i_hosts; i++ )
+ {
+ struct in_addr base, mask;
+ char *psz_host = strdup( ppsz_hosts[i] );
+ char *p = strchr( psz_host, '/' );
+
+ if( p != NULL )
+ {
+ int i_mask;
+ *p++ = '\0';
+ i_mask = atoi(p);
+ if( i_mask < 0 || i_mask > 32 )
+ {
+ msg_Err( p_this, "invalid netmask %s", p );
+ mask.s_addr = INADDR_NONE;
+ }
+ else if( i_mask == 0 )
+ mask.s_addr = INADDR_ANY;
+ else
+ mask.s_addr = htons( ntohs(INADDR_NONE) << (32 - i_mask) );
+ }
+ else
+ mask.s_addr = INADDR_NONE;
+
+ if( !inet_aton( psz_host, &base ) )
+ {
+ msg_Err( p_this, "invalid base address %s", psz_host );
+ free( psz_host );
+ continue;
+ }
+ free( psz_host );
+
+ if( !((ip.s_addr ^ base.s_addr) & mask.s_addr) )
+ return VLC_TRUE;
+ }
+
+ return VLC_FALSE;
+}
+