I tried to modify Hostapd's code to read the nl_pid. After I modified code as below image and compiled it.
wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
"handle %p", bss->nl_mgmt);
printf("%u", bss->nl_mgmt->s_local->nl_pid);
Compiler said "dereferencing pointer to incomplete type struct nl_sock".
../src/drivers/driver_nl80211.c: In function 'nl80211_mgmt_subscribe_ap':
../src/drivers/driver_nl80211.c:2449:30: error: dereferencing pointer to incomplete type 'struct nl_sock'
2449 | printf("%u", bss->nl_mgmt->s_local->nl_pid);
|
make: *** [Makefile:1293: ../src/drivers/driver_nl80211.o] Error 1
So, I commented at line 2449 and recompiled again. Then using gdb
to break at line 2451 and print 'bss->nl_mgmt variable'. gdb
could know and read the structure. Why gdb
could know and read the structure, but I couldn't? How could I solve this problem and read the 'nl_pid' I wanted?
Breakpoint 1, nl80211_mgmt_subscribe_ap (bss=0x4cdf60)
at ../src/drivers/driver_nl80211.c:2451
2451 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
(gdb) print *bss->nl_mgmt
$1 = {s_local = {nl_family = 16, nl_pad = 0, nl_pid = 2810203079, nl_groups = 0}, s_peer = {nl_family = 16, nl_pad = 0, nl_pid = 0, nl_groups = 0}, s_fd = 8, s_proto = 16, s_seq_next = 1578026322, s_seq_expect = 1578026322, s_flags = 0, s_cb = 0x4ce7b0, s_bufsize = 0}