gethostbyname调用失败解决方法

问题描述:版本升级后未做出厂设置时,无法查询成功(gethostbyname无法获取到正确结果)。

问题原因:

        gethostbyname这个DNS解析器系统调用,其查询的信息来自于系统DNS解析缓存( 库函数只读一次存储dns的文件,放到缓存里),当之前存在过错误的解析或者说解析错误时,系统DNS解析缓存不会被更新,因此之后再调用就会一直失败。

因此当DNS SERVER信息更新后,gethostbyname就会解析不出地址了。

解决方法:更新解析缓存,当出现gethostbyname调用失败时使用res_init()函数来更新DNS缓存,然后再调用gethostbyname。

解决结果:成功解决。

示例代码:

gethostbyname调用失败解决方法》有5个想法

  1. Hey there 🙂

    Your wordpress site is very sleek – hope you don’t mind me asking what theme you’re using?

    (and don’t mind if I steal it? :P)

    I just launched my site –also built in wordpress like yours– but the theme slows (!) the site down quite a bit.

    In case you have a minute, you can find it by searching for “royal cbd” on Google (would appreciate any feedback) –
    it’s still in the works.

    Keep up the good work– and hope you all take care of yourself during
    the coronavirus scare!

  2. Long time reader, first time commenter — so, thought I’d drop a comment..
    — and at the same time ask for a favor.

    Your wordpress site is very simplistic – hope you don’t mind me asking what theme
    you’re using? (and don’t mind if I steal it? :P)

    I just launched my small businesses site –also built in wordpress like yours– but the theme slows
    (!) the site down quite a bit.

    In case you have a minute, you can find it by searching for “royal cbd” on Google (would
    appreciate any feedback)

    Keep up the good work– and take care of yourself during the coronavirus scare!

    ~Justin

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注