mirror of
https://github.com/Silicondust/libhdhomerun
synced 2025-08-21 05:53:29 -07:00
support initializing ip info for winrt from string set by higher layer
This commit is contained in:
parent
476568c2da
commit
7671e9862b
3 changed files with 52 additions and 2 deletions
|
@ -205,6 +205,9 @@ static bool_t hdhomerun_discover_send_target_ip(struct hdhomerun_discover_t *ds,
|
|||
unsigned int i;
|
||||
for (i = 1; i < ds->sock_count; 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)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -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 void hdhomerun_local_ip_info_set_str(const char *ip_info_str); /* WinRT only */
|
||||
|
||||
struct hdhomerun_sock_t;
|
||||
|
||||
|
|
|
@ -28,11 +28,57 @@ struct hdhomerun_sock_t {
|
|||
};
|
||||
|
||||
#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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
PIP_ADAPTER_INFO AdapterInfo;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue