关于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 )实体,它保存某个影片什么时候租出及还回来,以及滞纳金等, ...
随机推荐
- 一步一步学EF系列【6、IOC 之AutoFac】
前言 之前的前5篇作为EF方面的基础篇,后面我们将使用MVC+EF 并且使用IOC ,Repository,UnitOfWork,DbContext来整体来学习.因为后面要用到IOC,所以本篇先单独先 ...
- UltraEdit 中的常用正则表达式
正则表达式 (UltraEdit Syntax): % 匹配行首 - 表明要搜索的字符串一定在行首. $ 匹配行尾 - 表明要搜索的字符串一定在行尾 ? 匹配除换行符外的任一单个字符. ...
- Openjudge-计算概论(A)-统计字符数
描述: 判断一个由a-z这26个字符组成的字符串中哪个字符出现的次数最多输入第1行是测试数据的组数n,每组测试数据占1行,是一个由a-z这26个字符组成的字符串每组测试数据之间有一个空行,每行数据不超 ...
- bkViewer V4.9k(数码照片浏览工具)中文免费版
软件名称: bkViewer 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 990KB 图片预览: 软件简介: 专为 ...
- Mac 下office 2013制作组合表
1.选择所有数据,插入图表→柱状图.2.选中柱状图中得某一数据,如栏目量.这个在柱状图上单击一次橙色柱子就能全部选中.3.更改图表类型,改为饼状图,再单击饼状图改为折线图.
- 微信web开发工具
http://mp.weixin.qq.com/wiki/10/e5f772f4521da17fa0d7304f68b97d7e.html#.E4.B8.8B.E8.BD.BD.E5.9C.B0.E5 ...
- sql语句判断两个时间段是否有交集
场景: 数据库有有两个字段.开始时间<startTime>,和结束时间<endTime>,指定一个时间段(a,b),a表示开始时间,b表示结束时间.看数据库中有没有与(a,b ...
- 实现apk 调用framework java JNI中方法
首先整个实现需要有Android源码编译环境.这里我用的是froyo2.2. 1.JNI层--C++代码部分 在目录frameworks/base/core/jni 下创建android_jnidem ...
- js导入插件注意事项.txt
网上收集的答案如下:==============================================1)确认js真的被引用到2)确认js引用顺序没问题3)确认js代码里的括号等都匹配,不会 ...
- ios导航栏又按钮添加图片后使其保持原色
UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStyl ...