ip地址转化代码实例
- /*@author: lgh@
- *
- * */
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <netinet/in.h>//ntohl
- #include <arpa/inet.h> //inet_addr
- #include <sys/types.h>
- #ifdef UNICODE
- #define T(x) __TXT(x)
- #define __TXT(s) L ## s
- #else
- #define T(s) s
- #endif /* UNICODE */
- /*
- #if defined (DEBUG_DISABLE)
- #undef DEBUG_DISABLE
- #else
- #endif
- */
- /*********************************************************************/
- #ifndef DEBUG_DISABLE
- /*
- #define lprint(tag, fmt...) \
- do{if(tag)printf(fmt);}while(0)
- */
- #define lprint(x, ...) do{printf(x, ##__VA_ARGS__);}while(0)
- #else
- #define lprint(tag, fmt...)
- #endif
- /*********************************************************************/
- #ifdef CONFIG_DUAL_IMAGE
- #if defined (CONFIG_RT2880_FLASH_2M)
- #define IMAGE1_SIZE 0x100000
- #elif defined (CONFIG_RT2880_FLASH_4M)
- #define IMAGE1_SIZE 0x200000
- #elif defined (CONFIG_RT2880_FLASH_8M)
- #define IMAGE1_SIZE 0x400000
- #elif defined (CONFIG_RT2880_FLASH_16M)
- #define IMAGE1_SIZE 0x800000
- #elif defined (CONFIG_RT2880_FLASH_32M)
- #define IMAGE1_SIZE 0x1000000
- #else
- #define IMAGE_SIZE TEST
- #endif
- #endif//end #ifdef,否则会出现25:1: error: unterminated #ifdef,这样的错
- /*********************************************************************/
- typedef void* (*square_t)(int* x);
- void* square (int* x)
- {
- *x *= *x;
- return (void*)square;
- }
- int lt1224(void)
- {
- int x = ;
- ((square_t)((square_t)((square_t)square (&x)) (&x)) (&x)) (&x);
- printf ("%d\n", x);
- return ;
- }
- /*********************************************************************/
- #ifndef NIP4
- #define NIP4_FMT "%u.%u.%u.%u"
- #define NIP4(addr) \
- ((unsigned char *)&addr)[], \
- ((unsigned char *)&addr)[], \
- ((unsigned char *)&addr)[], \
- ((unsigned char *)&addr)[]
- #define HIP4_FMT "%u.%u.%u.%u"
- #define HIP4(addr) \
- ((unsigned char *)&addr)[], \
- ((unsigned char *)&addr)[], \
- ((unsigned char *)&addr)[], \
- ((unsigned char *)&addr)[]
- #endif
- #ifndef NIP6
- #define NIP6_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"
- #define NIP6(addr) \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[]), \
- (unsigned)((addr)[])
- #endif
- /*
- #ifdef __CHECKER__
- #define __bitwise__ __attribute__((bitwise))
- #else
- #define __bitwise__
- #endif
- #ifdef __CHECK_ENDIAN__
- #define __bitwise __bitwise__
- #else
- #define __bitwise
- #endif
- typedef __u16 __bitwise __le16;
- typedef __u16 __bitwise __be16;
- typedef __u32 __bitwise __le32;
- typedef __u32 __bitwise __be32;
- typedef __u64 __bitwise __le64;
- typedef __u64 __bitwise __be64;
- */
- typedef __signed__ char __s8;
- typedef unsigned char __u8;
- typedef __signed__ short __s16;
- typedef unsigned short __u16;
- typedef __signed__ int __s32;
- typedef unsigned int __u32;
- typedef __signed__ long __s64;
- typedef unsigned long __u64;
- union nf_inet_addr {
- __u32 all[];
- __u32 ip;// __be32 ip;
- // __be32 ip6[4];
- struct in_addr in;
- struct in6_addr in6;
- };
- /*********************************************************************/
- union endian{
- int i;
- char c;
- };
- int main(int argc, char *argv[])
- {
- char *s="";
- char *p;
- p=strpbrk(s,"a1 839"); /*1会最先在s字符串中找到*/
- lprint("%s\n",p);
- p=strpbrk(s,"");/*3 会最先在s 字符串中找到*/
- lprint("%s\n",p);
- lprint("%s\n", T("deling"));
- lprint("************************************************************************\n");
- lt1224();
- lprint("************************************************************************\n");
- if(argc != )
- {
- return ;
- }
- union endian le;
- le.i = 0x3456;/*16bit宽的数*/
- if(le.c == 0x56){
- lprint("little endian\n");
- }else lprint("big endian\n");
- printf("%0x, %0x\n", le.i, le.c);
- char ipdot[] = {};/*点分十进制*/
- long iphost = ;/*主机字节序,x86一般都是小端模式*/
- long ipnet = ;/*网络字节序,大端模式*/
- strncpy(ipdot, argv[], sizeof(ipdot));
- lprint("Get ipdot:%s\n", ipdot);
- ipnet = inet_addr(ipdot);
- lprint("Get ipnet:%ld:"NIP4_FMT"\n", ipnet, NIP4(ipnet));
- iphost = ntohl(ipnet);
- lprint("Get iphost:%ld:"NIP4_FMT"\n", iphost, NIP4(iphost));
- lprint("Get iphost:%ld:"HIP4_FMT"\n", iphost, HIP4(iphost));
- iphost++;
- lprint("Get iphost++:%ld:"HIP4_FMT"\n", iphost, HIP4(iphost));
- /*net --> host*/
- unsigned array[];
- array[] = (ntohl(ipnet) >> ) & 0xFF;
- array[] = (ntohl(ipnet) >> ) & 0xFF;
- array[] = (ntohl(ipnet) >> ) & 0xFF;
- array[] = ntohl(ipnet) & 0xFF;
- lprint(NIP4_FMT"\n", array[], array[], array[], array[]);
- lprint("%ld.%ld.%ld.%ld\n", ipnet & 0xff,
- ipnet>> & 0xff,
- ipnet>> & 0xff,
- ipnet>> & 0xff);
- lprint("************************************************************************\n");
- return ;
- }
ip地址转化代码实例的更多相关文章
- C#验证ip地址的代码
如下的代码是关于C#验证ip地址的代码. public Boolean CheckIPValid(String strIP) { char chrFullStop = '.'; string[] ar ...
- JSP 获取真实IP地址的代码
[转载]JSP 获取真实IP地址的代码 JSP 获取真实IP地址的代码 在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的. ...
- 【转载】JSP 获取真实IP地址的代码
JSP 获取真实IP地址的代码 在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的. 但是在通过了 Apache,Squid ...
- Linux下获取本机IP地址的代码
Linux下获取本机IP地址的代码,返回值即为互联网标准点分格式的字符串. #define ETH_NAME "eth0" //获得本机IP地址 char* GetLocalAdd ...
- js获取IP地址多种方法实例教程
js获取IP地址方法总结 js代码获取IP地址的方法,如何在js中取得客户端的IP地址.原文地址:js获取IP地址的三种方法 http://www.jbxue.com/article/11338. ...
- 将IP地址转化为整数
$ip = 'IP地址';echo $intip = sprintf('%u',ip2long($ip)); //转换为无符号整型echo long2ip($intip);//将整型转换为ip
- 获取Linux下的IP地址 java代码
/** * 获取Linux下的IP地址 * * @return IP地址 * @throws SocketException */ public static String getLinuxLocal ...
- C#获取本地IP地址[常用代码段]
获得当前机器的IP代码,假设本地主机为单网卡 string strHostName = Dns.GetHostName(); //得到本机的主机名 IPHostEntry ipEntry = Dns. ...
- openresty(nginx)中使用lua脚本获取请求IP地址的代码
人狠话不多,直接上代码:------------------------------------------------------------------------------------- lo ...
随机推荐
- C#局域网桌面共享软件制作(一)
很久没有写文章了,今天分享的内容是局域网桌面共享软件,相信很多人都做过,也可能遇到一些问题,这里我将一一测试. 涉及到的内容有:局域网文件传输.桌面截屏.图片压缩等.为了更直白的演示程序的功能所以没有 ...
- linux下vi的复制,黏贴,删除,撤销,跳转等命令
前言 在嵌入式linux开发中,进行需要修改一下配置文件之类的,必须使用vi,因此,熟悉 vi 的一些基本操作,有助于提高工作效率. 一,模式vi编辑器有3种模式:命令模式.输入模式.末行模式 ...
- Yii框架中使用PHPExcel导出Excel文件
最近在研究PHP的Yii框架,很喜欢,碰到导出Excel的问题,研究了一下,就有了下面的方法: 1.首先在config\main.php中添加对PHPExcel的引用,我的方式是这样: 1 2 3 4 ...
- caused by android.system.errnoexception open failed eacces (permission denied)解决方案,安卓6.0(API23)权限问题
在API23+以上,不止要在AndroidManifest.xml里面添加权限 <uses-permission android:name="android.permission.RE ...
- 9)Java内部类(Inner Class)
内部类:不可以有静态数据,静态方法或者又一个静态内部类 内部类的优点:隐藏类的细节,内部类可以声明为私有.内部类可以访问外部类的对象(包括private) 静态内部类:可以有静态数据,静 ...
- masterha_check_repl报错汇总
[root@DBMysql ~]#masterha_check_repl --conf=/etc/masterha/app1.cnf 导致如下报错的原因主要有两类: 1.mysql的安装时用源码安装, ...
- 第十六章 调试及安全性(In .net4.5) 之 调试程序
1. 概述 本章内容包括 如何选择合适的构建类型.创建和管理编译指令.管理程序数据文件(pdb)和指令. 2. 主要内容 2.1 构建类型 .net中默认的两种生成模式是 发布(Release)模式 ...
- 正确打印含unicode字符的dict
python中,dict 对象转换为类似为 \UXXXX 的格式:这种格式英文称为 code point,完全看不懂:当然,也可以通过这个网站来转换 http://rishida.net/tools/ ...
- WebService到底是什么?(转)
一.序言 大家或多或少都听过WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成分.但是不得不承认的是Web ...
- 利用HttpModule开发asp.net页面、ashx等访问时session失效的统一处理入口
web程序时,当使用session时总会出现失效而报“未将对象引用设置到对象的实例”的http 500错误,本人比较懒,不想每个地方都用try catch处理,就找到个用httpModule统一处理的 ...