使用resolv.h [英] Use of resolv.h

查看:125
本文介绍了使用resolv.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过从resolv.h的_res结构中读取DNS服务器地址来查找它.根据man 3解析器的设置代码应该是.

I'm trying to find out my DNS server address by reading it from resolv.h's _res struct. According to man 3 resolver the setup code should be.

#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>

extern struct state _res;

然后我只要读出我需要的内容即可.我的问题是尝试编译此文件

and then I just read out whatever I need. My problem is that trying to compile this I get

resolver.c:5:21: error: conflicting types for '__res_state'
extern struct state _res;
                    ^
/usr/include/resolv.h:251:16: note: expanded from macro '_res'
#define _res (*__res_state())
               ^
/usr/include/resolv.h:249:28: note: previous declaration is here
extern struct __res_state *__res_state(void) __attribute__ ((__const__));
                           ^
1 error generated.

按c.

我在做什么错了?

推荐答案

您不应该自己声明_res-resolv.h包含正确的声明(尽管手册页有何含义).

You shouldn't declare _res yourself - resolv.h includes the right declaration (despite what the man page implies).

这篇关于使用resolv.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆