Linux system Programming Quick Location header file Tips for powerful grep commands

Source: Internet
Author: User

This technique comes from my actual development:

Inet_addr This function is used to turn the IP address into a network byte order, his prototype: in_addr_t inet_addr (const char *CP);

The return value is a in_addr_t type, it is clear that this is not a C language standard data type, want to figure out what he is exactly what type, certainly to find the header file, on the Linux system, the header file is generally placed under/usr/include, but this very many header files, There is no knowing which, so:

1, first: grep in_addr_t/usr/include/*.h no results, stating that it is not in the first level directory of/usr/include

2, Second: grep "in_addr_t"/usr/include/*/*.h, this time there are many results

/usr/include/arpa/inet.h:externin_addr_t inet_addr (Const Char*__cp) __throw;/usr/include/arpa/inet.h:externin_addr_t inet_lnaof (structin_addr __in) __throw;/usr/include/arpa/inet.h:extern structin_addr inet_makeaddr (in_addr_t __net, in_addr_t __host)/usr/include/arpa/inet.h:externin_addr_t Inet_netof (structin_addr __in) __throw;/usr/include/arpa/inet.h:externin_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/inch. H:typedef uint32_t in_addr_t;/usr/include/netinet/inch. h:in_addr_t s_addr;/usr/include/netinet/inch. h:#defineIn_classa (A) ((((in_addr_t) (a) & 0x80000000) = = 0)/usr/include/netinet/inch. h:#defineIN_CLASSB (A) ((((in_addr_t) (a) & 0xc0000000) = = 0x80000000)/usr/include/netinet/inch. h:#defineIN_CLASSC (A) ((((in_addr_t) (a) & 0xe0000000) = = 0xc0000000)/usr/include/netinet/inch. h:#defineIN_CLASSD (A) ((((in_addr_t) (a) & 0xf0000000) = = 0xe0000000)/usr/include/netinet/inch. h:#defineIn_experimental (A) ((((in_addr_t) (a) & 0xe0000000) = = 0xe0000000)/usr/include/netinet/inch. h:#defineIn_badclass (A) ((((in_addr_t) (a) & 0xf0000000) = = 0xf0000000)/usr/include/netinet/inch. h:#defineInaddr_any ((in_addr_t) 0x00000000)/usr/include/netinet/inch. h:#defineInaddr_broadcast ((in_addr_t) 0xFFFFFFFF)/usr/include/netinet/inch. h:#defineInaddr_none ((in_addr_t) 0xFFFFFFFF)/usr/include/netinet/inch. h:# define Inaddr_loopback (in_addr_t)0x7f000001)/*Inet 127.0.0.1. *//usr/include/netinet/inch. h:#defineInaddr_unspec_group ((in_addr_t) 0xe0000000)/* 224.0.0.0 *//usr/include/netinet/inch. h:#defineInaddr_allhosts_group ((in_addr_t) 0xe0000001)/* 224.0.0.1 *//usr/include/netinet/inch. h:#defineInaddr_allrtrs_group ((in_addr_t) 0xe0000002)/* 224.0.0.2 *//usr/include/netinet/inch. h:#defineInaddr_max_local_group ((in_addr_t) 0xe00000ff)/* 224.0.0.255 */

3, filter, grep "in_addr_t"/usr/include/*/*.h | grep "typedef"

Use typedef to filter once, or use define and other keywords, this data type is definitely the standard type of alias definition, the following data appears, he is uint32_t this data type alias

/usr/include/netinet/in.h:typedef uint32_t in_addr_t;

4, Next, must be looking for uint32_t definition type grep "uint32_t"/usr/include/*/*.h | grep "typedef", the result:

/usr/include/drm/drm.h:typedef uint32_t __u32; /usr/include/netinet/in. H:typedef uint32_t in_addr_t;

It's not what I want.

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; int        uint32_t;

That's what I want, uint32_t is actually unsigned int type

6,grep-n "uint32_t"/usr/include/stdint.h identifying the line number where the data definition resides

 - : #ifndef __uint32_t_defined Wuyi int         uint32_t; define: # __uint32_t_defined

Linux system Programming Quick Location header file Tips for powerful grep commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.