這個技巧來自於我的實際開發碰到的: inet_addr這個函數用於把ip地址轉成網路位元組序,他的原型:in_addr_t inet_addr(const char *cp); 返回值為一個in_addr_t的類型,很顯然這不是一個c語言的標準數據類型,想搞清楚他到底是什麼類型,肯定要找到頭文件,在l ...
這個技巧來自於我的實際開發碰到的:
inet_addr這個函數用於把ip地址轉成網路位元組序,他的原型:in_addr_t inet_addr(const char *cp);
返回值為一個in_addr_t的類型,很顯然這不是一個c語言的標準數據類型,想搞清楚他到底是什麼類型,肯定要找到頭文件,在linux系統上,頭文件一般放在/usr/include下麵,但是這下麵非常多的頭文件,根本不知道是哪個,所以:
1,第一次:grep in_addr_t /usr/include/*.h 沒有結果,說明不在/usr/include的第一層目錄中
2,第二次: grep "in_addr_t" /usr/include/*/*.h, 這一次出現很多結果
/usr/include/arpa/inet.h:extern in_addr_t inet_addr (const char *__cp) __THROW; /usr/include/arpa/inet.h:extern in_addr_t inet_lnaof (struct in_addr __in) __THROW; /usr/include/arpa/inet.h:extern struct in_addr inet_makeaddr (in_addr_t __net, in_addr_t __host) /usr/include/arpa/inet.h:extern in_addr_t inet_netof (struct in_addr __in) __THROW; /usr/include/arpa/inet.h:extern in_addr_t inet_network (const char *__cp) __THROW; /usr/include/arpa/inet.h:extern char *inet_neta (in_addr_t __net, char *__buf, size_t __len) __THROW; /usr/include/netinet/in.h:typedef uint32_t in_addr_t; /usr/include/netinet/in.h: in_addr_t s_addr; /usr/include/netinet/in.h:#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0) /usr/include/netinet/in.h:#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) /usr/include/netinet/in.h:#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) /usr/include/netinet/in.h:#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) /usr/include/netinet/in.h:#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) /usr/include/netinet/in.h:#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) /usr/include/netinet/in.h:#define INADDR_ANY ((in_addr_t) 0x00000000) /usr/include/netinet/in.h:#define INADDR_BROADCAST ((in_addr_t) 0xffffffff) /usr/include/netinet/in.h:#define INADDR_NONE ((in_addr_t) 0xffffffff) /usr/include/netinet/in.h:# define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) /* Inet 127.0.0.1. */ /usr/include/netinet/in.h:#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) /* 224.0.0.0 */ /usr/include/netinet/in.h:#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) /* 224.0.0.1 */ /usr/include/netinet/in.h:#define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) /* 224.0.0.2 */ /usr/include/netinet/in.h:#define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
3,過濾,grep "in_addr_t" /usr/include/*/*.h | grep "typedef"
用typedef過濾一次,或者用define等關鍵字, 這種數據類型肯定是標準類型的別名定義,出現下麵這條數據,他是uint32_t這個數據類型的別名
/usr/include/netinet/in.h:typedef uint32_t in_addr_t;
4,下一步,肯定是找uint32_t的定義類型 grep "uint32_t" /usr/include/*/*.h | grep "typedef",出現結果:
/usr/include/drm/drm.h:typedef uint32_t __u32; /usr/include/netinet/in.h:typedef uint32_t in_addr_t;
這不是我想要的
5,grep "uint32_t" /usr/include/*.h | grep "typedef"
/usr/include/elf.h:typedef uint32_t Elf32_Word; /usr/include/elf.h:typedef uint32_t Elf64_Word; /usr/include/elf.h:typedef uint32_t Elf32_Addr; /usr/include/elf.h:typedef uint32_t Elf32_Off; /usr/include/stdint.h:typedef unsigned int uint32_t;
這才是我想要的, uint32_t其實是unsigned int類型
6,grep -n "uint32_t" /usr/include/stdint.h 查出數據定義所在的行號
50:#ifndef __uint32_t_defined 51:typedef unsigned int uint32_t; 52:# define __uint32_t_defined