‘sockaddr_in6_t’即使包含头文件也会出现未声明的错误

发布于 2024-12-21 20:22:27 字数 565 浏览 0 评论 0原文

我有以下简单的代码,它是一个大项目中 ipv6 处理模块的一部分。

#include <ctype.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/stat.h>

int main(){
  sockaddr_in6_t* pSadrIn6 = (sockaddr_in6_t*) malloc(sizeof sockaddr_in6_t);
  return 0;
}

它给了我以下而不是错误:

error: ‘sockaddr_in6_t’ undeclared (first use in this function)

是否有任何特殊的库安装或链接我需要访问该库?

I have following simple piece of code, which is a part of ipv6 handling module in a big project.

#include <ctype.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/stat.h>

int main(){
  sockaddr_in6_t* pSadrIn6 = (sockaddr_in6_t*) malloc(sizeof sockaddr_in6_t);
  return 0;
}

It gives me following not error:

error: ‘sockaddr_in6_t’ undeclared (first use in this function)

Is there any special library installation or linking that I need to access the library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惟欲睡 2024-12-28 20:22:27

看起来您是从 Linux IPv6 HOWTO< 复制了此代码/a> 但没有复制额外的 typedef:

/*
** Type definitions (for convenience).
*/
typedef enum { false = 0, true } boolean;
typedef struct sockaddr_in       sockaddr_in_t;
typedef struct sockaddr_in6      sockaddr_in6_t;

就个人而言,我会按原样使用类型(而不是额外的 typedefs 以避免输入 struct),但无论如何

It looks like you copied this code from the Linux IPv6 HOWTO but didn't copy the additional typedefs:

/*
** Type definitions (for convenience).
*/
typedef enum { false = 0, true } boolean;
typedef struct sockaddr_in       sockaddr_in_t;
typedef struct sockaddr_in6      sockaddr_in6_t;

Personally I would just use the types as they are (instead of extra typedefs to avoid typing struct), but whatever

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文