summaryrefslogtreecommitdiff
path: root/gdhcp/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdhcp/server.c')
-rwxr-xr-x[-rw-r--r--]gdhcp/server.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/gdhcp/server.c b/gdhcp/server.c
index 0171b5f..83132a7 100644..100755
--- a/gdhcp/server.c
+++ b/gdhcp/server.c
@@ -56,7 +56,7 @@ struct _GDHCPServer {
char *interface;
uint32_t start_ip;
uint32_t end_ip;
- uint32_t server_nip;
+ uint32_t server_nip; /* our address in network byte order */
uint32_t lease_seconds;
int listener_sockfd;
guint listener_watch;
@@ -65,6 +65,7 @@ struct _GDHCPServer {
GHashTable *nip_lease_hash;
GHashTable *option_hash; /* Options send to client */
GDHCPSaveLeaseFunc save_lease_func;
+ GDHCPLeaseAddedCb lease_added_cb;
GDHCPSaveACKLeaseFunc save_ack_lease_func;
GDHCPDebugFunc debug_func;
gpointer debug_data;
@@ -214,6 +215,9 @@ static struct dhcp_lease *add_lease(GDHCPServer *dhcp_server, uint32_t expire,
g_hash_table_insert(dhcp_server->nip_lease_hash,
GINT_TO_POINTER((int) lease->lease_nip), lease);
+ if (dhcp_server->lease_added_cb)
+ dhcp_server->lease_added_cb(lease->lease_mac, yiaddr);
+
return lease;
}
@@ -452,7 +456,7 @@ static void init_packet(GDHCPServer *dhcp_server, struct dhcp_packet *packet,
packet->gateway_nip = client_packet->gateway_nip;
packet->ciaddr = client_packet->ciaddr;
dhcp_add_option_uint32(packet, DHCP_SERVER_ID,
- dhcp_server->server_nip);
+ ntohl(dhcp_server->server_nip));
}
static void add_option(gpointer key, gpointer value, gpointer user_data)
@@ -669,7 +673,8 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
server_id_option = dhcp_get_option(&packet, DHCP_SERVER_ID);
if (server_id_option) {
- uint32_t server_nid = get_be32(server_id_option);
+ uint32_t server_nid =
+ get_unaligned((const uint32_t *) server_id_option);
if (server_nid != dhcp_server->server_nip)
return TRUE;
@@ -832,6 +837,15 @@ void g_dhcp_server_set_save_lease(GDHCPServer *dhcp_server,
dhcp_server->save_lease_func = func;
}
+void g_dhcp_server_set_lease_added_cb(GDHCPServer *dhcp_server,
+ GDHCPLeaseAddedCb cb)
+{
+ if (!dhcp_server)
+ return;
+
+ dhcp_server->lease_added_cb = cb;
+}
+
void g_dhcp_server_set_save_ack_lease(GDHCPServer *dhcp_server,
GDHCPSaveACKLeaseFunc func, gpointer user_data)
{