宏和函数
1、ssize_t:
--typedef signed long ssize_t--在tools/include/noblic中有定义
--In short, ssize_t
is the same as size_t
, but is a signed type - read ssize_t
as “signed size_t
”. ssize_t
is able to represent the number -1
, which is returned by several system calls and library functions as a way to indicate error. For example, the read
and write
system calls:
#include <sys/types.h>
#include <unistd.h>
ssize_t read(int fildes, void *buf, size_t nbyte);
ssize_t write(int fildes, const void *buf, size_t nbyte);
2、sprintf
在stdio.h中--
int sprintf ( char * str, const char * format, ... );
功能是往str中写字符串
example:
|
|
output:
[5 plus 3 is 8] is a string 13 chars long.
3、inet_aton
int inet_aton(const char *cp, struct in_addr *inp);
将点分四段式的IP地址转为地址结构in_addr值
4、inet_pton
int inet_pton(int af, const char *src, void *dst)
安全的协议无关的地址转换函数,将字符串类型的IP地址转化为二级制类型,ad表示网络协议族,AF_INET--IPv4
4、__be16
--types.h--typedef __u16 __bitwise __be16
--__bitwise属性表示GCC编译器需要对指定大小端格式的变量运算时进行检查,提示一些可能导致数据泄露和数据错误的操作
--
be表示big endian,大端,le表示小端
__be32,__le32都是一样的,其实就是__u32,具体是什么端数据又系统决定的。
网络协议也是采用大端数据。
目前主要是用来发现大小端不匹配的错误。比如往big-endian的寄存器里面写入little-endian的数据
5、size_t
--Unsigned integral type
Alias of one of the fundamental unsigned integer types.
It is a type able to represent the size of any object in bytes:size_t is the type returned by the sizeof
operator and is widely used in the standard library to represent sizes and counts.
In <cstring>, it is used as the type of the parameter num in the functions memchr, memcmp, memcpy, memmove, memset, strncat, strncmp, strncpy and strxfrm, which in all cases it is used to specify the maximum number of bytes or characters the function has to affect.
It is also used as the return type for strcspn, strlen, strspn and strxfrm to return sizes and lengths
6、gethostbyname,getprotobyname
--举例:getprotobyname("icmp"),通过人们容易记住的标识(icmp),返回计算机可以读取的结构(protoent)
--gethostbyname_r()
gethostbyname_r() is a reentrant version of gethostbyname() that searches the network host database for a host name match.
The gethostbyname_r() function shall search the network host database for an entry with name name.
The application must provide a buffer for the gethostbyname_r() to use during the lookup process. The buffer is referenced by buf, and is of size buflen. If the buffer is not of sufficient size, gethostbyname_r() may fail and return ERANGE. If a matching entry is found in the database, gethostbyname_r() shall copy the relevant information to the application supplied hostent structure referenced by result_buf, and return a pointer to this structure in *result. If no matching entry is found, *result shall be set to a null pointer. Additional error information shall be set in the variable referenced by h_errnop
7、inet_addr
--The inet_addr function converts a string containing an IPv4 dotted-decimal address into a proper address for the IN_ADDR structure
-- IN_ADDR:The in_addr structure represents an IPv4 Internet address