Skip to content

Commit 0637511

Browse files
mshawcroftTomasz Bursztyka
authored andcommitted
dhcpv4: Report address acquisition.
Use the network management interface to catch and report IPv4 address acquisition in the application. Change-Id: Idd1bcaac90fffbd617600a7713206599e547826f Signed-off-by: Marcus Shawcroft <[email protected]>
1 parent cdb8133 commit 0637511

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

samples/net/dhcpv4_client/prj_qemu_x86.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ CONFIG_SLIP_DEBUG=n
2323
CONFIG_SLIP_STATISTICS=n
2424
CONFIG_NET_DEBUG_ARP=y
2525
CONFIG_NET_DEBUG_L2_ETHERNET=y
26+
CONFIG_NET_MGMT=y
27+
CONFIG_NET_MGMT_EVENT=y

samples/net/dhcpv4_client/src/main.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <net/net_if.h>
3232
#include <net/net_core.h>
3333
#include <net/net_context.h>
34+
#include <net/net_mgmt.h>
3435

3536
static struct k_sem quit_lock;
3637

@@ -39,6 +40,18 @@ static inline void quit(void)
3940
k_sem_give(&quit_lock);
4041
}
4142

43+
static struct net_mgmt_event_callback mgmt_cb;
44+
45+
static void handler(struct net_mgmt_event_callback *cb,
46+
uint32_t mgmt_event,
47+
struct net_if *iface)
48+
{
49+
if (mgmt_event == NET_EVENT_IPV4_ADDR_ADD) {
50+
NET_INFO("NET_EVENT_IPV4_ADDR_ADD");
51+
quit();
52+
}
53+
}
54+
4255
static inline void init_app(void)
4356
{
4457
struct net_if *iface;
@@ -50,6 +63,10 @@ static inline void init_app(void)
5063
net_dhcpv4_start(iface);
5164

5265
k_sem_init(&quit_lock, 0, UINT_MAX);
66+
67+
net_mgmt_init_event_callback(&mgmt_cb, handler,
68+
NET_EVENT_IPV4_ADDR_ADD);
69+
net_mgmt_add_event_callback(&mgmt_cb);
5370
}
5471

5572
void main_fiber(void)
@@ -62,7 +79,5 @@ void main(void)
6279
{
6380
NET_INFO("In main");
6481

65-
init_app();
66-
6782
main_fiber();
6883
}

0 commit comments

Comments
 (0)