ifcfg-eth0文件参数PREFIX 和 NETMASK的配置不一致问题
ifcfg-eth0文件参数PREFIX 和 NETMASK的配置不一致问题
2013年06月21日 23:57:26
搭建一个简单的网络测试环境,现有服务器ip配置为10.131.4.33 掩码为255.255.254.0网关为 10.131.5.254, 需要访问
-
133 expand_config ()
-
134 {
-
135 if [ -z "${NETMASK}" ]; then
-
136 eval `/bin/ipcalc --netmask ${IPADDR}`
-
137 fi
-
138
-
139 if [ -z "${PREFIX}" ]; then
-
140 eval `/bin/ipcalc --prefix ${IPADDR} ${NETMASK}`
-
141 fi
-
142
-
143 if [ -z "${BROADCAST}" ]; then
-
144 eval `/bin/ipcalc --broadcast ${IPADDR} ${NETMASK}`
-
145 fi
-
146
-
147 if [ -z "${NETWORK}" ]; then
-
148 eval `/bin/ipcalc --network ${IPADDR} ${NETMASK}`
-
149 fi
-
150 }
-
/* vi: set sw=4 ts=4: */
-
/*
-
* Mini ipcalc implementation for busybox
-
*
-
* By Jordan Crouse <jordan@cosmicpenguin.net>
-
* Stephan Linz <linz@li-pro.net>
-
*
-
* This is a complete reimplementation of the ipcalc program
-
* from Red Hat. I didn't look at their source code, but there
-
* is no denying that this is a loving reimplementation
-
*
-
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
-
*/
-
#include "busybox.h"
-
#include <ctype.h>
-
#include <getopt.h>
-
#include <sys/socket.h>
-
#include <arpa/inet.h>
-
#define CLASS_A_NETMASK ntohl(0xFF000000)
-
#define CLASS_B_NETMASK ntohl(0xFFFF0000)
-
#define CLASS_C_NETMASK ntohl(0xFFFFFF00)
-
static unsigned long get_netmask(unsigned long ipaddr)
-
{
-
ipaddr = htonl(ipaddr);
-
if ((ipaddr & 0xC0000000) == 0xC0000000)
-
return CLASS_C_NETMASK;
-
else if ((ipaddr & 0x80000000) == 0x80000000)
-
return CLASS_B_NETMASK;
-
else if ((ipaddr & 0x80000000) == 0)
-
return CLASS_A_NETMASK;
-
else
-
return 0;
-
}
-
#ifdef CONFIG_FEATURE_IPCALC_FANCY
-
static int get_prefix(unsigned long netmask)
-
{
-
unsigned long msk = 0x80000000;
-
int ret = 0;
-
netmask = htonl(netmask);
-
while (msk) {
-
if (netmask & msk)
-
ret++;
-
msk >>= 1;
-
}
-
return ret;
-
}
-
#else
-
int get_prefix(unsigned long netmask);
-
#endif
-
#define NETMASK 0x01
-
#define BROADCAST 0x02
-
#define NETWORK 0x04
-
#define NETPREFIX 0x08
-
#define HOSTNAME 0x10
-
#define SILENT 0x20
-
#if ENABLE_FEATURE_IPCALC_LONG_OPTIONS
-
static const struct option long_options[] = {
-
{ "netmask", no_argument, NULL, 'm' },
-
{ "broadcast", no_argument, NULL, 'b' },
-
{ "network", no_argument, NULL, 'n' },
-
# if ENABLE_FEATURE_IPCALC_FANCY
-
{ "prefix", no_argument, NULL, 'p' },
-
{ "hostname", no_argument, NULL, 'h' },
-
{ "silent", no_argument, NULL, 's' },
-
# endif
-
{ NULL, 0, NULL, 0 }
-
};
-
#endif
-
int ipcalc_main(int argc, char **argv)
-
{
-
unsigned opt;
-
int have_netmask = 0;
-
in_addr_t netmask, broadcast, network, ipaddr;
-
struct in_addr a;
-
char *ipstr;
-
#if ENABLE_FEATURE_IPCALC_LONG_OPTIONS
-
applet_long_options = long_options;
-
#endif
-
opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs"));
-
argc -= optind;
-
argv += optind;
-
if (opt & (BROADCAST | NETWORK | NETPREFIX)) {
-
if (argc > 2 || argc <= 0)
-
bb_show_usage();
-
} else {
-
if (argc != 1)
-
bb_show_usage();
-
}
-
if (opt & SILENT)
-
logmode = LOGMODE_NONE; /* Suppress error_msg() output */
-
ipstr = argv[0];
-
if (ENABLE_FEATURE_IPCALC_FANCY) {
-
unsigned long netprefix = 0;
-
char *prefixstr;
-
prefixstr = ipstr;
-
while (*prefixstr) {
-
if (*prefixstr == '/') {
-
*prefixstr = (char)0;
-
prefixstr++;
-
if (*prefixstr) {
-
unsigned msk;
-
netprefix = xatoul_range(prefixstr, 0, 32);
-
netmask = 0;
-
msk = 0x80000000;
-
while (netprefix > 0) {
-
netmask |= msk;
-
msk >>= 1;
-
netprefix--;
-
}
-
netmask = htonl(netmask);
-
/* Even if it was 0, we will signify that we have a netmask. This allows */
-
/* for specification of default routes, etc which have a 0 netmask/prefix */
-
have_netmask = 1;
-
}
-
break;
-
}
-
prefixstr++;
-
}
-
}
-
ipaddr = inet_aton(ipstr, &a);
-
if (ipaddr == 0) {
-
bb_error_msg_and_die("bad IP address: %s", argv[0]);
-
}
-
ipaddr = a.s_addr;
-
if (argc == 2) {
-
if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) {
-
bb_error_msg_and_die("use prefix or netmask, not both");
-
}
-
netmask = inet_aton(argv[1], &a);
-
if (netmask == 0) {
-
bb_error_msg_and_die("bad netmask: %s", argv[1]);
-
}
-
netmask = a.s_addr;
-
} else {
-
/* JHC - If the netmask wasn't provided then calculate it */
-
if (!ENABLE_FEATURE_IPCALC_FANCY || !have_netmask)
-
netmask = get_netmask(ipaddr);
-
}
-
if (opt & NETMASK) {
-
printf("NETMASK=%sn", inet_ntoa((*(struct in_addr *) &netmask)));
-
}
-
if (opt & BROADCAST) {
-
broadcast = (ipaddr & netmask) | ~netmask;
-
printf("BROADCAST=%sn", inet_ntoa((*(struct in_addr *) &broadcast)));
-
}
-
if (opt & NETWORK) {
-
network = ipaddr & netmask;
-
printf("NETWORK=%sn", inet_ntoa((*(struct in_addr *) &network)));
-
}
-
if (ENABLE_FEATURE_IPCALC_FANCY) {
-
if (opt & NETPREFIX) {
-
printf("PREFIX=%in", get_prefix(netmask));
-
}
-
if (opt & HOSTNAME) {
-
struct hostent *hostinfo;
-
int x;
-
hostinfo = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET);
-
if (!hostinfo) {
-
bb_herror_msg_and_die("cannot find hostname for %s", argv[0]);
-
}
-
for (x = 0; hostinfo->h_name[x]; x++) {
-
hostinfo->h_name[x] = tolower(hostinfo->h_name[x]);
-
}
-
printf("HOSTNAME=%sn", hostinfo->h_name);
-
}
-
}
-
return EXIT_SUCCESS;
-
}
ifcfg-eth0文件参数PREFIX 和 NETMASK的配置不一致问题的更多相关文章
- Linux ifconfig-etho文件参数详解
1.ifcfg-eth0文件参数详解 DEVICE 网卡名称/网络接口的名称BOOTPROTO 系统启动地址协议 常用参数: none:不使用启动地址协议,none禁止DHCP bootp:BOOTP ...
- 一个比较强大的HTTP请求类,支持文本参数和文件参数。
一个 http 请求类 ,支持文件上传,从淘宝 top sdk 里面扣出来的,蛮好用的,做个记录而已. 调用代码: Dictionary<string, string> textParas ...
- Oracle 无备份情况下的恢复--密码文件/参数文件
13.1 恢复密码文件 密码文件(linux 为例)在$ORACLE_HOME/dbs目录下,文件名的前缀是orapw,后接数据库实例名. [oracle@DSI backup]$ cd /u01/a ...
- hadoop 文件参数配置
准备环境(省略) 上传实验所需的压缩包 配置网络信息 修改主机名 配置域名解析 关闭防火墙与SELinux(在所有节点上执行)代码如下: systemctl disable --now firewal ...
- springmvc 项目完整示例06 日志–log4j 参数详细解析 log4j如何配置
Log4j由三个重要的组件构成: 日志信息的优先级 日志信息的输出目的地 日志信息的输出格式 日志信息的优先级从高到低有ERROR.WARN. INFO.DEBUG,分别用来指定这条日志信息的重要程度 ...
- Flask小总结+实例化Flask参数以及对app的配置
Flask 小而精 三方组件全 稳定性相对较差 1.启动: from flask import Flask app = Flask(__name__) app.run("0.0.0.0&qu ...
- Flask的实例化参数及对app的配置
目录 1.调试模式初测 2.app.config中的其他配置参数详解 3.修改config配置的方式(from_object用法) 3.1直接对app.config进行修改: 3.2使用类的方式导入: ...
- Yarn&Mapreduce参数的具体含义和配置参考
Yarn & Mapreduce 参数的具体含义和配置 http://zh.hortonworks.com/blog/how-to-plan-and-configure-yarn-in-hdp ...
- [Linux实用工具]Windows下同步Linux文件(Linux安装Samba和配置)
场景需求: 安装了Ubuntu在虚拟机上,但是代码编辑或者其它更多的操作的时候,还是习惯在windows下进行.如果windows下编辑完再上传到服务器,再编译执行,就太繁琐了.一次两次还好说,这编译 ...
随机推荐
- vba打开excel文件遍历sheet的名字和指定单元格的值
今天项目上有个应用,获取指定Excel文件下的所有sheet的名称以及当前sheet中指定单元格的值,并把他们写到固定的sheet中去,看了下,文件比较多,而且每个文件sheet的个数比较多,也不一样 ...
- SublimeText3常用插件安装与使用
packagecontroller的安装 https://packagecontrol.io/ 安装了它就可以更好的进行插件的安装和管理 复制代码,打开控制面板[ctrl+·]将代码拷贝,即可进行安装 ...
- Linux环境变量从用户配置改为系统配置
部署了一个新的tomcat到一个新的用户下,发下启动失败了 /home/personal/apache-tomcat/bin/catalina.sh: line 434: /usr/lib/jvm/j ...
- Regex正则表达式
正则表达式 热身 正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串.将匹配的子串做替换或者从某个串中取出符合某个条件的子串等. 例如 g ...
- java里的MouseLisetener接口的使用过程==========需要用组件是来注册侦听器
总结:通过匿名类来实现鼠标的监听或者 通过实现接口的方法都可以的 从此是实现MouseListener接口的方式 package com.a.b; import java.awt.Color; im ...
- ByteBuf 类——Netty 的数据容器
1.堆缓冲区 2.直接缓冲区 3.复合缓冲区 —CompositeByteBuf——实现了这个模式,它提供了一 个将多个缓冲区表示为单个合并缓冲区的虚拟表示 适用于 JDK 所使用的一种称为分散/收集 ...
- file does not exist 阿里云OSS图片上传遇到的问题
./uploads\20171209/0497b8dd16e72c6fcf5bfd552f535a81.png file does not exist 原代码 function aliyun($sav ...
- 32位机,CPU是如何利用段寄存器寻址的
转自:http://blog.sina.com.cn/s/blog_640531380100xa15.html 32位cpu 地址线扩展成了32位,这和数据线的宽度是一致的.因此,在32位机里其实并不 ...
- jquery添加和删除多个同名的input输入框
<script type="text/javascript"> function del(obj){ $(obj).parents("li").re ...
- flask ---映射到数据库
在当前项目文件下:运行cmd指令(terminal中) (1)python manage.py db init ----初始化文件 (2)python manage.py db migrate-- ...