c - 如何解决C中不完整类型的解引用指针?

标签 c gdb hostapd

我尝试修改Hostapd的代码来读取nl_pid。我修改代码如下图并编译后。

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);

编译器说“取消引用指向不完整类型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

所以,我在第2449行注释并再次重新编译。然后使用 gdb 在第 2451 行中断并打印“bss->nl_mgmt 变量”。 gdb 可以知道并读取该结构。为什么gdb可以知道并读取结构,但我不能?我怎样才能解决这个问题并读取我想要的'nl_pid'?

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}

最佳答案

struct nl_sock 的定义必须存在于您正在编译的 .c 中(或包含的文件中)。该定义告诉编译器 s_local 所在的偏移量,这是编译该表达式需要知道的信息。

关于c - 如何解决C中不完整类型的解引用指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59573428/

相关文章:

c - 如何硬/中止关闭 TCP 连接?

c - 直接标准输入到 C 程序

c - C字符串文字作为参数等于在AVR-GCC中为-1?

c - 在 32 位机器上实现 64 位算术 - 汇编代码

Python:使用 gdb 调试(在 OSX 上)

linux - 核心转储仅显示一个堆栈帧

c - 使用 GDB 检查 C 指针

linux - 树莓派拒绝连接到瓶服务器