Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes after @adamsutton suggested using the safer
getsockname method of determining IP used for the server
Appears to work fine after other code removed
  • Loading branch information
andyb2000 committed Jan 2, 2013
1 parent 63c4c42 commit d6f54a3
Showing 1 changed file with 5 additions and 49 deletions.
54 changes: 5 additions & 49 deletions src/htsp_server.c
Expand Up @@ -29,9 +29,6 @@
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <ifaddrs.h>
#include <linux/if_link.h>
#include <netdb.h>

#include "tvheadend.h"
#include "channels.h"
Expand Down Expand Up @@ -204,44 +201,6 @@ typedef struct htsp_file {
* Support routines
* *************************************************************************/

/*
* Find adapter IP addresses
*/
static char *returnIpAddress()
{
struct ifaddrs *ifaddr;
char *tmp1, *tmp2 = NULL;

if (getifaddrs(&ifaddr) == -1) {
return NULL;
}

struct ifaddrs *ifa = ifaddr;
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr != NULL) {
int family = ifa->ifa_addr->sa_family;
if (family == AF_INET) {
char ip_addr[NI_MAXHOST];
int s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in),
ip_addr, sizeof(ip_addr), NULL, 0, NI_NUMERICHOST);
if (s != 0) {
return NULL;
} else {
if (strcmp(ifa->ifa_name, "lo")) {
tmp1 = strdup(ip_addr);
tmp2 = strtok(tmp1, ".");
if (strcmp(tmp2, "192") || strcmp(tmp2, "10") || strcmp(tmp2, "172")) {
return strdup(ip_addr);
};
};
}
};
}
};
freeifaddrs(ifaddr);
return NULL;
}

/**
*
*/
Expand Down Expand Up @@ -497,15 +456,12 @@ htsp_build_channel(channel_t *ch, const char *method, htsp_connection_t *htsp)
if (htsp->htsp_version <= 7) {
strcpy(url, "http://");
p = 7;
char *ret_ip;
ret_ip = returnIpAddress();
if (ret_ip) {
snprintf(url, sizeof(url), "http://%s", ret_ip);
} else {
inet_ntop(AF_INET, &(htsp->htsp_peer->sin_addr), url+p, sizeof(url)-p);
};
struct sockaddr_in ss;
unsigned int len;
getsockname(htsp->htsp_fd,(struct sockaddr*)&ss,&len);
p = strlen(url);
p += snprintf(url+p, sizeof(url)-p, ":%hd", webui_port);
p += snprintf(url+p, sizeof(url)-p, "%s:%hd",
inet_ntoa(ss.sin_addr),webui_port);
}
if (tvheadend_webroot)
p += snprintf(url+p, sizeof(url)-p, "%s", tvheadend_webroot);
Expand Down

1 comment on commit d6f54a3

@adamsutton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andyb2000 I'm closing this, I'd already added the code myself. There is 1 caveat, current pvr.hts will not work as v7 clients are expected to deal with the relative URL rather than complete. So this means all Frodo stuff will not work until pvr.hts is updated.

However this is an optional feature (off by default) so it will not affect people unless they try to enable the feature.

Please sign in to comment.