The skill of quickly locating header file in linux Programming powerful grep command

Keywords: Linux network C

This skill comes from my actual development:

This function is used to convert ip address into network byte order. Its prototype is in addr INET addr (const char * CP);

The return value is an in ﹣ addr ﹣ T type. Obviously, this is not a standard data type of c language. If you want to find out what type it is, you must find the header file. On the linux system, the header file is usually placed under / usr/include, but there are many header files below, so you don't know which one is at all

1. The first time: grep in ﹣ addr ﹣ T / usr/include / *. H has no result, indicating that it is not in the first level directory of / usr/include

2. The second time: grep "in" addr "t" / usr / include / * / *. H, this time there are many results

/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  */
/usr/include/netinet/in.h:#define INADDR_UNSPEC_GROUP    ((in_addr_t) 0xe0000000) /* */
/usr/include/netinet/in.h:#define INADDR_ALLHOSTS_GROUP    ((in_addr_t) 0xe0000001) /* */
/usr/include/netinet/in.h:#define INADDR_ALLRTRS_GROUP    ((in_addr_t) 0xe0000002) /* */
/usr/include/netinet/in.h:#define INADDR_MAX_LOCAL_GROUP  ((in_addr_t) 0xe00000ff) /* */

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 must be the alias definition of standard type. The following data appears, which is the alias of uint32? Data type

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

4. The next step is to find the definition type grep "uint32" / usr / include / * / *. H | grep "typedef" of uint32 ". The result is as follows:

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

This is 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;
/usr/include/stdint.h:typedef unsigned int        uint32_t;

That's what I want. Uint32 ˊ t is actually of type unsigned int

6. Grep - n "uint32" / usr / include / stdint. H find out the row number of the data definition

50:#ifndef __uint32_t_defined
51:typedef unsigned int        uint32_t;
52:# define __uint32_t_defined

Posted by alsouno on Tue, 05 May 2020 01:02:17 -0700