关于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 )实体,它保存某个影片什么时候租出及还回来,以及滞纳金等, ...
随机推荐
- 实现简单的手写涂鸦板(demo源码)
在一些软件系统中,需要用到手写涂鸦的功能,然后可以将涂鸦的结果保存为图片,并可以将"真迹"通过网络发送给对方.这种手写涂鸦功能是如何实现的了?最直接的,我们可以使用Windows提 ...
- webapi中的扩展点
Extension Points Web API provides extension points for some parts of the routing process. Interface ...
- Gentoo安装详解(五)-- 安装X桌面环境
安装X桌面环境: 安装Xorg: 检测显卡信息: dmesg | grep video lspci | grep -i VGA 配置INPUT_DEVICE.VIDEO_CARDS变量: 在安装Xor ...
- chapter 14_1 环境
Lua将其所有的全局变量保存在一个常规的table中,称为“global environment”. Lua将环境table自身保存在一个全局变量_G中,_G._G等于 _G . 比如下面的代码打印出 ...
- chapter11_2 Lua链表与队列
链表 由于table是动态的实体,所以在Lua中实现链表是很方便的.每个节点以一个table来表示,一个“链表”只是节点table中的一个字段. 该字段包含了对其他table的引用.例如,要实现一个基 ...
- 1.编写一个Java应用程序,该程序中有3个类:Ladder、Circle和主类A。具体要求如下:Ladder类具有类型为double的上底、下底、高、面积属性,具有返回面积的功能,包括一个构造方法对上底、下底、高进行初始化。Circle类具有类型为double的半径、周长和面积属性,具有返回周长、面积的功能,包括一个构造方法对半径进行初始化。主类A用来测试类Ladder和类Circle的功能。
Ladder package com.hanqi.test; public class Ladder { //属性 double shangdi,xiadi,gao,mianji; //构造方法 La ...
- UI----安健1 button lable textfiend
//按钮 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect ];//按钮形状 button.frame = CGR ...
- 【开发笔记】Spring的配置文件
factory-method竟然写成了destroy-method,害得我运行报错,找原因找了几分钟. 原来我按alt+/来提示代码的时候,有许多可选项,可能一时眼花选错了
- Day06 杂乱与4个对象
1.杂乱 -- 数据库的分页操作 -- 分页使用的是rownum 例1: select rownum,empno,ename from emp ; 结果: 例2: select r,empno,ena ...
- Alyona and flowers
Alyona and flowers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...