Skip to content

Commit

Permalink
We should not open browser if the request is coming from us!
Browse files Browse the repository at this point in the history
  • Loading branch information
LocutusOfBorg committed Sep 19, 2013
1 parent e4dfa96 commit 85098e2
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion plug-ins/remote_browser/remote_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static int remote_browser_init(void *);
static int remote_browser_fini(void *);
static void remote_browser(struct packet_object *po);
static int good_page(char *str);
int ip_addr_is_ours(struct ip_addr *ip);

/* plugin operations */

Expand Down Expand Up @@ -94,8 +95,13 @@ static void remote_browser(struct packet_object *po)
int i = 0, k = 0;

/* the client is making a request */
char tmp2[MAX_ASCII_ADDR_LEN];
if (po->DATA.disp_len != 0 && strstr((const char*)po->DATA.disp_data, "GET")) {

/* I'm the sender, opening a browser with a request coming by me will trigger a loop in this function! */
if(ip_addr_is_ours(&po->L3.src) == EFOUND || ip_addr_is_ours(&po->L3.src) == EBRIDGE)
return;

/* I'm not the sender, I can safely open the browser, the GET triggered by it shouldn't cause bad effects */
tmp = strdup((const char*)po->DATA.disp_data);

/* get the Host: directoive */
Expand Down Expand Up @@ -212,6 +218,30 @@ static int good_page(char *str)
return 0;
}

int ip_addr_is_ours(struct ip_addr *ip)
{
struct net_list *i;
switch(ntohs(ip->addr_type)) {
case AF_INET:
if(!ip_addr_cmp(ip, &GBL_IFACE->ip))
return EFOUND;
else if(!ip_addr_cmp(ip, &GBL_BRIDGE->ip))
return EBRIDGE;
else
return -ENOTFOUND;
break;

case AF_INET6:
LIST_FOREACH(i, &GBL_IFACE->ip6_list, next) {
if(!ip_addr_cmp(ip, &i->ip))
return EFOUND;
}
return -ENOTFOUND;
}

return -EINVALID;
}


/* EOF */

Expand Down

0 comments on commit 85098e2

Please sign in to comment.