关于glibc中的res_init()函数
/*
* 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()函数的更多相关文章
- Linux中的入口函数main
main()函数,想必大家都不陌生了,从刚开始写程序的时候,大家便开始写main(),我们都知道main是程序的入口.那main作为一个函数,又是谁调用的它,它是怎么被调用的,返回给谁,返回的又是什么 ...
- Linux 编程中的API函数和系统调用的关系【转】
转自:http://blog.chinaunix.net/uid-25968088-id-3426027.html 原文地址:Linux 编程中的API函数和系统调用的关系 作者:up哥小号 API: ...
- glibc中malloc()的空间overhead
在linux下调用malloc()分配内存的时候,实际占用的内存与请求的内存尺寸的关系是什么呢,这个需要研究一下glibc中malloc()的实现.现在常见linux发行版中带的glibc中采用的都是 ...
- glibc中malloc的详细解释_转
glibc中的malloc实现: The main properties of the algorithms are:* For large (>= 512 bytes) requests, i ...
- GLIBC中的库函数fflush究竟做了什么?
目录 目录 1 1. 库函数fflush原型 1 2. FILE结构体 1 3. fflush函数实现 2 4. fclose函数实现 4 附1:强弱函数名 5 附2:属性__visibility__ ...
- House of apple 一种新的glibc中IO攻击方法
目录 House of apple 一种新的glibc中IO攻击方法 前言 利用条件 利用原理 利用思路 思路一:修改tcache线程变量 思路二:修改mp_结构体 思路三:修改pointer_gua ...
- Python3中的字符串函数学习总结
这篇文章主要介绍了Python3中的字符串函数学习总结,本文讲解了格式化类方法.查找 & 替换类方法.拆分 & 组合类方法等内容,需要的朋友可以参考下. Sequence Types ...
- Entity Framework 6 Recipes 2nd Edition(10-5)译 -> 在存储模型中使用自定义函数
10-5. 在存储模型中使用自定义函数 问题 想在模型中使用自定义函数,而不是存储过程. 解决方案 假设我们数据库里有成员(members)和他们已经发送的信息(messages) 关系数据表,如Fi ...
- Entity Framework 6 Recipes 2nd Edition(11-9)译 -> 在LINQ中使用规范函数
11-9. 在LINQ中使用规范函数 问题 想在一个LINQ查询中使用规范函数 解决方案 假设我们已经有一个影片租赁(MovieRental )实体,它保存某个影片什么时候租出及还回来,以及滞纳金等, ...
随机推荐
- flex安装debug
1.解决 不是最新版本的问题: cmd-->regedit-->HKEY_LOCAL_MATCHING-->SOFTWARE-->MACROMEDIA -->FLASHP ...
- 不完善的css怦然心动,有待改进...
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- solr与tomcat整合
一.准备工作:我使用的是tomcat7.0,solr-4.8.1 solr-4.8.1解压后是这样的. 二.开始配置了 1.首先要创建两个文件夹.home和server.我是创建在与solr-4.8. ...
- 移动端日历控件 mobiscroll 的简单使用、参数设置
mobiscroll 在性能方面比较好,可选用多种效果,滑动效果也比较顺畅. 提供样式文件和js文件,直接点击下载,该版本是 mobiscroll 2.13的 官方地址 :https://docs ...
- js添加div
有这样一段div布局 <div class="clearfix"> <p class="left c"> <s ...
- msdn我告诉你
http://msdn.itellyou.cn/ 微软旗下所有的msdn订阅软件资源 均为ed2k资源 Business Solutions MSDN Library 工具和资源 应用程序 开发人员工 ...
- QTP连接MYSQL数据库方法
1.首先安装mysql数据驱动,qtp在windows系统下操作连接mysql,所以下载mysql-connector-odbc- 5.1.8-win32.msi 下载地址:http://mysq ...
- Asp.net中,点击GridView表头实现数据的排序
一.实现该功能的基本工作. 1. 先添加一个GridView,取名为gvData. 2. 设置该控件的属性: 操作步骤如下 设置属性: 这4个属性,还要设置该控件AllowSorting=&quo ...
- 第二十节,基本数据类型,集合set、综合应用新数据更新老数据
基本数据类型,集合set.综合应用新数据更新老数据 创建两个字典新数据,更新原始数据,a为原始数据,b为新数据 1,分别获取到a字典和b字典的key(键),将两个字典的键分别转换成两个集合 2,找出a ...
- html 框架属性
<html> <head> <title></title> </head> <frameset col ...