support initializing ip info for winrt from string set by higher layer

This commit is contained in:
Nick Kelsey 2016-08-27 12:53:12 -07:00
commit 7671e9862b
3 changed files with 52 additions and 2 deletions

View file

@ -205,6 +205,9 @@ static bool_t hdhomerun_discover_send_target_ip(struct hdhomerun_discover_t *ds,
unsigned int i; unsigned int i;
for (i = 1; i < ds->sock_count; i++) { for (i = 1; i < ds->sock_count; i++) {
struct hdhomerun_discover_sock_t *dss = &ds->socks[i]; struct hdhomerun_discover_sock_t *dss = &ds->socks[i];
if (dss->subnet_mask == 0) {
continue;
}
if ((target_ip & dss->subnet_mask) != (dss->local_ip & dss->subnet_mask)) { if ((target_ip & dss->subnet_mask) != (dss->local_ip & dss->subnet_mask)) {
continue; continue;
} }

View file

@ -27,6 +27,7 @@ struct hdhomerun_local_ip_info_t {
}; };
extern LIBHDHOMERUN_API int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int max_count); extern LIBHDHOMERUN_API int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int max_count);
extern LIBHDHOMERUN_API void hdhomerun_local_ip_info_set_str(const char *ip_info_str); /* WinRT only */
struct hdhomerun_sock_t; struct hdhomerun_sock_t;

View file

@ -28,11 +28,57 @@ struct hdhomerun_sock_t {
}; };
#if defined(_WINRT) #if defined(_WINRT)
static const char *hdhomerun_local_ip_info_str = NULL;
/*
* String format: ip address '/' subnet mask bits <space> ...
* Example: "192.168.0.100/24 169.254.0.100/16"
*/
void hdhomerun_local_ip_info_set_str(const char *ip_info_str)
{
if (hdhomerun_local_ip_info_str) {
free(hdhomerun_local_ip_info_str);
}
hdhomerun_local_ip_info_str = strdup(ip_info_str);
}
int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int max_count) int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int max_count)
{ {
return 0; const char *ptr = hdhomerun_local_ip_info_str;
if (!ptr) {
return 0;
}
struct hdhomerun_local_ip_info_t *ip_info = ip_info_list;
int count = 0;
while (count < max_count) {
unsigned int a[4];
unsigned int mask_bitcount;
if (sscanf(ptr, "%u.%u.%u.%u/%u", &a[0], &a[1], &a[2], &a[3], &mask_bitcount) != 5) {
break;
}
ip_info->ip_addr = (uint32_t)((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | (a[3] << 0));
ip_info->subnet_mask = 0xFFFFFFFF << (32 - mask_bitcount);
ip_info++;
count++;
ptr = strchr(ptr, ' ');
if (!ptr) {
break;
}
ptr++;
}
return count;
} }
#else #endif
#if !defined(_WINRT)
int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int max_count) int hdhomerun_local_ip_info(struct hdhomerun_local_ip_info_t ip_info_list[], int max_count)
{ {
PIP_ADAPTER_INFO AdapterInfo; PIP_ADAPTER_INFO AdapterInfo;