IP4ループバックアドレス値
IP4のループバックアドレスは、先頭が0x7f=127という事です。
static inline bool ipv4_is_loopback(__be32 addr) { return (addr & htonl(0xff000000)) == htonl(0x7f000000); } #define htonl(x) ___htonl(x) #define ___htonl(x) __cpu_to_be32(x) include/linux/byteorder/big_endian.h #define __cpu_to_be32(x) ((__force __be32)(__u32)(x)) include/linux/byteorder/little_endian.h #define __cpu_to_be32(x) ((__force __be32)__swab32((x)))サンプル(CPUはlittle_endian)
[root@localhost lkm]# cat htonl.c #include <linux/module.h> static int __init babakaka_init(void) { printk("%lx:%lx\n", (unsigned long)0x11223344, (unsigned long)htonl(0x11223344)); return -1; } module_init(babakaka_init) [root@localhost lkm]# insmod htonl.ko insmod: error inserting 'htonl.ko': -1 Operation not permitted [root@localhost lkm]# dmesg : [ 4854.584807] 11223344:44332211
[root@localhost c]# cat ipaddr.c #include <stdio.h> void main(int argc, char **argv) { int ip1, ip2, ip3, ip4; sscanf(argv[1],"%d.%d.%d.%d",&ip4,&ip3,&ip2,&ip1); printf("%08lx:%08lx\n", (long)inet_addr(argv[1]), (long)ip1*0x100*0x100*0x100 + (long)ip2*0x100*0x100 + (long)ip3*0x100 + (long)ip4); } [root@localhost c]# ./a.out 127.0.0.0 0000007f:0000007f [root@localhost c]# ./a.out 127.1.0.0 0000017f:0000017f [root@localhost c]# ./a.out 127.0.1.0 0001007f:0001007f [root@localhost c]# ./a.out 127.0.0.1 0100007f:0100007f