开发者

ANSI C How to get name server (DNS) address in linux? [duplicate]

开发者 https://www.devze.com 2023-03-07 23:07 出处:网络
This question already has an answer here: Programma开发者_开发问答tically obtain DNS servers of host
This question already has an answer here: Programma开发者_开发问答tically obtain DNS servers of host (1 answer) Closed 9 years ago.

I want to use in my code local DNS addresses and am looking for a library that would produce it. Is there anything like it or do I have to parse /etc/resolv.conf myself?

Thanks


You can use the resolver functions as described in the answer to this question or read the addresses of name servers from the file /etc/resolv.conf which is a simple text file, such as

# Generated by NetworkManager
nameserver x.x.x.x
nameserver y.y.y.y

where x.x.x.x and y.y.y.y are ip addresses.


Check http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=%2Fapis%2Fresninit.htm for some sample code.

0

精彩评论

暂无评论...
验证码 换一张
取 消