sd-network: add _get_network_file api

This commit is contained in:
Tom Gundersen
2014-09-08 15:09:07 +02:00
parent b70c73fcf1
commit adc5b2e2eb
3 changed files with 29 additions and 0 deletions
+24
View File
@@ -120,6 +120,30 @@ _public_ int sd_network_link_get_setup_state(int ifindex, char **state) {
return 0;
}
_public_ int sd_network_link_get_network_file(int ifindex, char **filename) {
_cleanup_free_ char *s = NULL, *p = NULL;
int r;
assert_return(ifindex > 0, -EINVAL);
assert_return(filename, -EINVAL);
if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
return -ENOMEM;
r = parse_env_file(p, NEWLINE, "NETWORK_FILE", &s, NULL);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
*filename = s;
s = NULL;
return 0;
}
_public_ int sd_network_link_get_operational_state(int ifindex, char **state) {
_cleanup_free_ char *s = NULL, *p = NULL;
int r;
+2
View File
@@ -1785,6 +1785,8 @@ int link_save(Link *link) {
char **address, **domain;
bool space;
fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
fputs("DNS=", f);
space = false;
STRV_FOREACH(address, link->network->dns) {
+3
View File
@@ -93,6 +93,9 @@ int sd_network_link_get_setup_state(int ifindex, char **state);
*/
int sd_network_link_get_operational_state(int ifindex, char **state);
/* Get path to .network file applied to link */
int sd_network_link_get_network_file(int ifindex, char **filename);
/* Get DNS entries for a given link. These are string representations of
* IP addresses */
int sd_network_link_get_dns(int ifindex, char ***addr);