From c7b4007c167f35e6a6b4e58ffd1aec83dae0b18a Mon Sep 17 00:00:00 2001 From: Julien Massot Date: Mon, 20 Dec 2010 16:24:01 +0000 Subject: [PATCH] gdhcp: Add netmask getter --- gdhcp/client.c | 24 ++++++++++++++++++++++++ gdhcp/gdhcp.h | 1 + 2 files changed, 25 insertions(+) diff --git a/gdhcp/client.c b/gdhcp/client.c index 3508b1e..107077a 100644 --- a/gdhcp/client.c +++ b/gdhcp/client.c @@ -1413,6 +1413,30 @@ char *g_dhcp_client_get_address(GDHCPClient *dhcp_client) return g_strdup(dhcp_client->assigned_ip); } +char *g_dhcp_client_get_netmask(GDHCPClient *dhcp_client) +{ + GList *option = NULL; + + switch (dhcp_client->state) { + case IPV4LL_DEFEND: + case IPV4LL_MONITOR: + return g_strdup("255.255.0.0"); + case BOUND: + case RENEWING: + case REBINDING: + option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET); + if (option != NULL) + return g_strdup(option->data); + case INIT_SELECTING: + case REQUESTING: + case RELEASED: + case IPV4LL_PROBE: + case IPV4LL_ANNOUNCE: + break; + } + return NULL; +} + GDHCPClientError g_dhcp_client_set_request(GDHCPClient *dhcp_client, unsigned char option_code) { diff --git a/gdhcp/gdhcp.h b/gdhcp/gdhcp.h index 63c395d..4f583ff 100644 --- a/gdhcp/gdhcp.h +++ b/gdhcp/gdhcp.h @@ -91,6 +91,7 @@ GDHCPClientError g_dhcp_client_set_send(GDHCPClient *client, const char *option_value); char *g_dhcp_client_get_address(GDHCPClient *client); +char *g_dhcp_client_get_netmask(GDHCPClient *client); GList *g_dhcp_client_get_option(GDHCPClient *client, unsigned char option_code); int g_dhcp_client_get_index(GDHCPClient *client); -- 2.7.4