/*
 * Set up default settings.  If the configuration file exist, the values
 * there will have precedence.  Otherwise, the server address is set to
 * INADDR_ANY and the default domain name comes from the gethostname().
 *
 * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
 * rather than INADDR_ANY ("0.0.0.0") as the default name server address
 * since it was noted that INADDR_ANY actually meant ``the first interface
 * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
 * it had to be "up" in order for you to reach your own name server.  It
 * was later decided that since the recommended practice is to always
 * install local static routes through 127.0.0.1 for all your network
 * interfaces, that we could solve this problem without a code change.
 *
 * The configuration file should always be used, since it is the only way
 * to specify a default domain.  If you are running a server on your local
 * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
 * in the configuration file.
 *
 * Return 0 if completes successfully, -1 on error
 */

安装默认设置。如果配置文件存在,这些值将会有优先级顺序。否则,服务器地址将被设置成INADDR_ANY(0.0.0.0)并且默认域名来自gethostname().这些代码的一个中间的过渡版本(BIND 4.9, pre-4.4BSD)使用127.0.0.1而不是INADDR_ANY(0.0.0.0)作为默认的域名服务器地址因为很显然INADDR_ANY总是意味着在启动阶段你ifconfig的第一个接口,并且如果他是一个SLIP或者PPP接口的话,他还必须是up的来让你访问到你自己的域名服务器。接下来决定了既然推荐的实践是总是通过127.0.0.1为所有你的网络接口安装本地静态路由,我们可以通过不改动代码来解决这个问题。

配置文件应该一直被使用,因为他是指定一个默认域名的唯一方法。如果你正在你的本地机器上运行一个服务器,你应该写nameserver 0.0.0.0或者nameserver 127.0.0.1在配置文件中。

完全正确返回0 错误返回-1

/*
     * These three fields used to be statically initialized.  This made
     * it hard to use this code in a shared library.  It is necessary,
     * now that we're doing dynamic initialization here, that we preserve
     * the old semantics: if an application modifies one of these three
     * fields of _res before res_init() is called, res_init() will not
     * alter them.  Of course, if an application is setting them to
     * _zero_ before calling res_init(), hoping to override what used
     * to be the static default, we can't detect it and unexpected results
     * will follow.  Zero for any of these fields would make no sense,
     * so one can safely assume that the applications were already getting
     * unexpected results.
     *
     * _res.options is tricky since some apps were known to diddle the bits
     * before res_init() was first called. We can't replicate that semantic
     * with dynamic initialization (they may have turned bits off that are
     * set in RES_DEFAULT).  Our solution is to declare such applications
     * "broken".  They could fool us by setting RES_INIT but none do (yet).
     */

这三个域被用来静态的初始化。这使得它很难在共享库中使用。这是必要的,既然我们正在做动态初始化那么我们,那我们就要保持旧的语义:如果应用程序在调用res_init()之前修改了这三个_res域的一个的话,res_init()将不会改变他们。当然,如果一个应用程序在调用 res_init()之前将他们设置成0,来希望覆盖静态默认的配置,那么我们将不会检测到并且意想不到的结果会发生。0对于这些域来说没有任何意义,所以你可以大胆的假设应用已经得到不可预料的结果。

_res.options有点棘手因为有些apps已知已经在调用res_init之前颠倒了这些bits。我们不能用动态初始化来复制这些语义(他们可能在RES_DEFAULT将这些位关闭了)。我们的解决方案是声明这些应用程序broken。他们可以愚弄我们通过设置RES_INIT,但是没有人这样做。

关于glibc中的res_init()函数的更多相关文章

  1. Linux中的入口函数main

    main()函数,想必大家都不陌生了,从刚开始写程序的时候,大家便开始写main(),我们都知道main是程序的入口.那main作为一个函数,又是谁调用的它,它是怎么被调用的,返回给谁,返回的又是什么 ...

  2. Linux 编程中的API函数和系统调用的关系【转】

    转自:http://blog.chinaunix.net/uid-25968088-id-3426027.html 原文地址:Linux 编程中的API函数和系统调用的关系 作者:up哥小号 API: ...

  3. glibc中malloc()的空间overhead

    在linux下调用malloc()分配内存的时候,实际占用的内存与请求的内存尺寸的关系是什么呢,这个需要研究一下glibc中malloc()的实现.现在常见linux发行版中带的glibc中采用的都是 ...

  4. glibc中malloc的详细解释_转

    glibc中的malloc实现: The main properties of the algorithms are:* For large (>= 512 bytes) requests, i ...

  5. GLIBC中的库函数fflush究竟做了什么?

    目录 目录 1 1. 库函数fflush原型 1 2. FILE结构体 1 3. fflush函数实现 2 4. fclose函数实现 4 附1:强弱函数名 5 附2:属性__visibility__ ...

  6. House of apple 一种新的glibc中IO攻击方法

    目录 House of apple 一种新的glibc中IO攻击方法 前言 利用条件 利用原理 利用思路 思路一:修改tcache线程变量 思路二:修改mp_结构体 思路三:修改pointer_gua ...

  7. Python3中的字符串函数学习总结

    这篇文章主要介绍了Python3中的字符串函数学习总结,本文讲解了格式化类方法.查找 & 替换类方法.拆分 & 组合类方法等内容,需要的朋友可以参考下. Sequence Types ...

  8. Entity Framework 6 Recipes 2nd Edition(10-5)译 -> 在存储模型中使用自定义函数

    10-5. 在存储模型中使用自定义函数 问题 想在模型中使用自定义函数,而不是存储过程. 解决方案 假设我们数据库里有成员(members)和他们已经发送的信息(messages) 关系数据表,如Fi ...

  9. Entity Framework 6 Recipes 2nd Edition(11-9)译 -> 在LINQ中使用规范函数

    11-9. 在LINQ中使用规范函数 问题 想在一个LINQ查询中使用规范函数 解决方案 假设我们已经有一个影片租赁(MovieRental )实体,它保存某个影片什么时候租出及还回来,以及滞纳金等, ...

随机推荐

  1. LeetCode OJ 84. Largest Rectangle in Histogram

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  2. poj 1411 Calling Extraterrestrial Intelligence Again

    题意:给你数m,a,b,假设有数p,q,满足p*q<=m同时a/b<=p/q<=1,求当p*q最大的p和q的值 方法:暴力枚举 -_-|| and 优化范围 我们可以注意到在某一个m ...

  3. 2015 ACM/ICPC Asia Regional Hefei Online

    1001 Monitor the Alpacas 1002 The Relationship in Club 1003 Difference of Clustering 两边离散化.暴力扫C就过了. ...

  4. SpringMvc之java文件下载

    首先强调,需要下载的文件只能放在项目中的webapp下 1.页面的一个超链接,链接到controller <a href="<%=path%>/download" ...

  5. Core Animation中的组动画

    实际开发中一个物体的运动往往是复合运动,单一属性的运动情况比较少,但恰恰属性动画每次进行动画设置时一次只能设置一个属性进行动画控制(不管是 基础动画还是关键帧动画都是如此),这样一来要做一个复合运动的 ...

  6. socket通信实例

    ref: http://www.cnblogs.com/xudong-bupt/archive/2013/12/29/3483059.html http://blog.csdn.net/love_ga ...

  7. linux yum安装mongodb

    1.yum -y install mongodb-server  mongodb 2.service mongod start                     #启动mongodb 服务 3. ...

  8. py执行系统命令

    1. os.system In [32]: run = os.system("date") Thu Jan 28 09:41:25 CST 2016 In [33]: run Ou ...

  9. Codeforces Round 371 Div2 B.Passwords

    原题: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  10. Android任务栈TaskStack

    Task:有多个Activity按顺序组成的一个完整的业务逻辑. 任务栈(TaskStack):新增的Activity放入栈中,点击back栈顶Activity从栈中退出. android:nohis ...