Skip to content

Commit

Permalink
Add reading dns info from /etc/resolv.conf
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Feb 4, 2014
1 parent e63d742 commit 86b4ceb
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/usb_moded-network.c
Expand Up @@ -24,6 +24,8 @@

/*============================================================================= */

#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -131,7 +133,40 @@ static void clean_usb_ip_forward(void)
*/
static int resolv_conf_dns(struct ipforward_data *ipforward)
{
/* TODO: implement */
FILE *resolv;
int i = 0, count = 0;
char *line = NULL, **tokens;
size_t len = 0;
ssize_t read;


resolv = fopen("/etc/resolv.conf", "r");
if (resolv == NULL)
return(1);

/* we don't expect more than 10 lines in /etc/resolv.conf */
for (i=0; i < 10; i++)
{
read = getline(&line, &len, resolv);
if(read)
{
if(strstr(line, "nameserver") != NULL)
{
tokens = g_strsplit(line, " ", 2);
if(count == 0)
ipforward->dns1 = strdup(tokens[1]);
else
ipforward->dns2 = strdup(tokens[1]);
count++;
g_strfreev(tokens);
}
}
if(count == 2)
goto end;
}
end:
free(line);
fclose(resolv);
return(0);
}
#endif
Expand Down Expand Up @@ -462,7 +497,8 @@ int usb_network_set_up_dhcpd(struct mode_list_elem *data)
goto end;
}
#else
resolv_conf_dns(ipforward);
if(resolv_conf_dns(ipforward))
goto end;
#endif /*CONNMAN */
}
/* ipforward can be NULL here, which is expected and handled in this function */
Expand Down

0 comments on commit 86b4ceb

Please sign in to comment.