Libuv库(探讨)---第四节:网络相关

索引目录:https://blog.csdn.net/knowledgebao/article/details/84776754


目录

系列目录:

Stream基类相关

TTY

PIPE

TCP

UDP

Networking in libuv is not much different from directly using the BSD socket interface, some things are easier, all are non-blocking, but the concepts stay the same. In addition libuv offers utility functions to abstract the annoying, repetitive and low-level tasks like setting up sockets using the BSD socket structures, DNS lookup, and tweaking various socket parameters.The uv_tcp_t and uv_udp_t structures are used for network I/O.

libuv中的网络与直接使用BSD套接字接口没什么不同,有些东西更容易,都是非阻塞的,但概念保持不变。此外,libuv还提供实用程序功能来抽象恼人的,重复的和低级别的任务,例如使用BSD套接字结构设置套接字,DNS查找以及调整各种套接字参数。这里网络相关的主要涉及TCP和UDP,由于TCP是Stream流,而PIPE和TTY也是Stream类,所以他们有共同的结构体,libuv将TCP、PIPE、TTY归为Stream流所以这里一并对PIPE和TTY的相关API也做一个简单介绍。

下边是TCP、PIPE、TTY的结构体。他们有相同的结构  UV_HANDLE_FIELDS,UV_STREAM_FIELDS,所以TCP、PIPE、TTY可以强制转换成Stream类型。

/* uv_stream_t is a subclass of uv_handle_t.
 * uv_stream is an abstract class.
 * uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t and uv_tty_t. */
struct uv_stream_s {
  UV_HANDLE_FIELDS
  UV_STREAM_FIELDS
};
/*uv_pipe_t is a subclass of uv_stream_t.
 * Representing a pipe stream or pipe server. On Windows this is a Named
 * Pipe. On Unix this is a Unix domain socket.*/
struct uv_pipe_s {
  UV_HANDLE_FIELDS
  UV_STREAM_FIELDS
  int ipc; /* non-zero if this pipe is used for passing handles */
  UV_PIPE_PRIVATE_FIELDS
};
/*
 * uv_tty_t is a subclass of uv_stream_t.
 * Representing a stream for the console.
 */
struct uv_tty_s {
  UV_HANDLE_FIELDS
  UV_STREAM_FIELDS
  UV_TTY_PRIVATE_FIELDS
};
/*
 * uv_tcp_t is a subclass of uv_stream_t.
 * Represents a TCP stream or TCP server.
 */
struct uv_tcp_s {
  UV_HANDLE_FIELDS
  UV_STREAM_FIELDS
  UV_TCP_PRIVATE_FIELDS
};

Stream基类相关

这里边的函数可以被PIPE、TTY、TCP调用,不同的类型可能会有一些差异,但是表示的功能相同。官网API:http://docs.libuv.org/en/v1.x/stream.html

int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb)

int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb);
int uv_accept(uv_stream_t* server, uv_stream_t* client);

int uv_read_start(uv_stream_t*,uv_alloc_cb alloc_cb,uv_read_cb read_cb);
int uv_read_stop(uv_stream_t*);

int uv_is_readable(const uv_stream_t* handle);
int uv_is_writable(const uv_stream_t* handle);
int uv_stream_set_blocking(uv_stream_t* handle, int blocking);

int uv_write(uv_write_t* req,uv_stream_t* handle,const uv_buf_t bufs[],unsigned int nbufs,uv_write_cb cb);
int uv_write2(uv_write_t* req,uv_stream_t* handle,const uv_buf_t bufs[],unsigned int nbufs,uv_stream_t* send_handle,uv_write_cb cb);
int uv_try_write(uv_stream_t* handle,const uv_buf_t bufs[],unsigned int nbufs);

size_t uv_stream_get_write_queue_size(const uv_stream_t* stream);

http://docs.libuv.org/en/v1.x/stream.html

uv_shutdown关闭连接,此关闭会等待写操作完成

uv_listen开始监听,backlog表示监听个数。同linuxlisten(2)

uv_accept

接收请求,一般在uv_connection_cb回调中调用,只允许调用一次。多次会失败。

此接口只能在bind的回调里边处理。server and client must be handles running on the same loop.

uv_read_start:

Read data from an incoming stream. The uv_read_cb callback will be made several times until there is no more data to read or uv_read_stop() is called.

开始读数据

uv_read_stop:

Stop reading data from the stream. The uv_read_cb callback will no longer be called.

This function is idempotent and may be safely called on a stopped stream.

停止读数据

uv_is_readable

Returns 1 if the stream is readable, 0 otherwise.

uv_is_writable

Returns 1 if the stream is writable, 0 otherwise.

uv_stream_set_blocking

Enable or disable blocking mode for a stream.

block被设置为1后,所有的操作都会被置为同步,windowpipe支持,不要过度依赖此接口,将来libuv可能废弃此接口。

uv_stre此接口在开始位置就应该被设置,当有reg在队列中时,设置可能失效。

am_get_write_queue_size

Returns stream->write_queue_size.

uv_write

Write data to stream. Buffers are written in order. Example:

NoteThe memory pointed to by the buffers must remain valid until the callback gets called. This also holds foruv_write2().

写数据,buffer空间在回调之前必须保持有效。

uv_write2

Extended write function for sending handles over a pipe. The pipe must be initialized with ipc == 1.

Note send_handle must be a TCP socket or pipe, which is a server or a connection (listening or connected state). Bound sockets or pipes will be assumed to be servers.

uv_write的扩展,多一个handle参数。通过pipe发送一个handle,此pipe必须使用ipc==1初始化。hand必须是tcp socket server或者是pipe

uv_try_write

Same as uv_write(), but won’t queue a write request if it can’t be completed immediately.

Will return either:

> 0: number of bytes written (can be less than the supplied buffer size).

< 0: negative error code (UV_EAGAIN is returned if no data can be sent immediately).

uv_write, 并且不关联req的同步写操作,类似于直接调用系统API

TTY

http://docs.libuv.org/en/v1.x/tty.html

TTY handles represent a stream for the console.

uv_tty_t is a ‘subclass’ of uv_stream_t.

Linux中,TTY也许是跟终端有关系的最为混乱的术语。TTY是TeleTYpe的一个老缩写。Teletypes,或者teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,和古老的电报机区别并不是很大。之后,当计算机只能以批处理方式运行时(当时穿孔卡片阅读器是唯一一种使程序载入运行的方式),电传打字机成为唯一能够被使用的“实时”输入/输出设备。最终,电传打字机被键盘和显示器终端所取代,但在终端或TTY接插的地方,操作系统仍然需要一个程序来监视串行端口。一个getty“Get TTY”的处理过程是:一个程序监视物理的TTY/终端接口。对一个虚拟网络控制台(VNC)来说,一个伪装的TTY(Pseudo-TTY,即假冒的TTY,也叫做“PTY”)是等价的终端。当你运行一个xterm(终端仿真程序)或GNOME终端程序时,PTY对虚拟的用户或者如xterm一样的伪终端来说,就像是一个TTY在运行。“Pseudo”的意思是“duplicating in a fake way”(用伪造的方法复制),它相比“virtual”或“emulated”更能真实的说明问题。而在的计算中,它却处于被放弃的阶段。

串行端口终端(Serial Port Terminal)是使用计算机串行端口连接的终端设备。计算机把每个串行端口都看作是一个字符设备。有段时间这些串行端口设备通常被称为终端设备,因为那时它的最大用途就是用来连接终端。这些串行端口所对应的设备名称是/dev/tts/0(或/dev/ttyS0),/dev/tts/1(或/dev/ttyS1)等,设备号分别是(4,0),(4,1)等,分别对应于DOS系统下的COM1、COM2等。若要向一个端口发送数据,可以在命令行上把标准输出重定向到这些特殊文件名上即可。例如,在命令行提示符下键入:echo test > /dev/ttyS1会把单词”test”发送到连接在ttyS1(COM2)端口的设备上。

typedef enum {
  /* Initial/normal terminal mode */
  UV_TTY_MODE_NORMAL,
  /* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
  UV_TTY_MODE_RAW,
  /* Binary-safe I/O mode for IPC (Unix-only) */
  UV_TTY_MODE_IO
} uv_tty_mode_t;

int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable);
int uv_tty_set_mode(uv_tty_t*, uv_tty_mode_t mode);
int uv_tty_reset_mode(void);
int uv_tty_get_winsize(uv_tty_t*, int* width, int* height);

uv_handle_type uv_guess_handle(uv_file file);

http://docs.libuv.org/en/v1.x/tty.html

uv_tty_init:

Initialize a new TTY stream with the given file descriptor. Usually the file descriptor will be:

0 = stdin

1 = stdout

2 = stderr

readable, specifies if you plan on calling uv_read_start() with this stream. stdin is readable, stdout is not.

On Unix this function will determine the path of the fd of the terminal using ttyname_r(3), open it, and use it if the passed file descriptor refers to a TTY. This lets libuv put the tty in non-blocking mode without affecting other processes that share the tty.

This function is not thread safe on systems that don’t support ioctl TIOCGPTN or TIOCPTYGNAME, for instance OpenBSD and Solaris.

Note: If reopening the TTY fails, libuv falls back to blocking writes for non-readable TTY streams.

Changed in version 1.9.0:: the path of the TTY is determined by ttyname_r(3). In earlier versions libuv opened /dev/ttyinstead.

Changed in version 1.5.0:: trying to initialize a TTY stream with a file descriptor that refers to a file returns UV_EINVAL on UNIX.

uv_tty_set_mode:

the mode is specified as a uv_tty_mode_t value.

Set the TTY using the specified terminal mode.

uv_tty_reset_mode:

To be called when the program exits. Resets TTY settings to default values for the next process to take over.

This function is async signal-safe on Unix platforms but can fail with error code UV_EBUSY if you call it when execution is inside uv_tty_set_mode().

uv_tty_get_winsize:

Gets the current Window size. On success it returns 0.

获取window大小。

PIPE

Pipe handles provide an abstraction over local domain sockets on Unix and named pipes on Windows.

uv_pipe_t is a ‘subclass’ of uv_stream_t.

int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc);
int uv_pipe_open(uv_pipe_t*, uv_file file);
int uv_pipe_bind(uv_pipe_t* handle, const char* name);
void uv_pipe_connect(uv_connect_t* req,
                               uv_pipe_t* handle,
                               const char* name,
                               uv_connect_cb cb);
int uv_pipe_getsockname(const uv_pipe_t* handle,
                                  char* buffer,
                                  size_t* size);
int uv_pipe_getpeername(const uv_pipe_t* handle,
                                  char* buffer,
                                  size_t* size);
void uv_pipe_pending_instances(uv_pipe_t* handle, int count);
int uv_pipe_pending_count(uv_pipe_t* handle);
uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle);
int uv_pipe_chmod(uv_pipe_t* handle, int flags);

uv_pipe_init

Initialize a pipe handle. The ipc argument is a boolean to indicate if this pipe will be used for handle passing between processes.

初始化一个pipeipc表示是否跨进程。

uv_pipe_open

Open an existing file descriptor or HANDLE as a pipe.

打开以及已经存在的handle

uv_pipe_bind

Bind the pipe to a file path (Unix) or a name (Windows).

绑定路径(Unix)或者名称(Windows)

uv_pipe_connect:

Connect to the Unix domain socket or the named pipe.

连接pipe

uv_pipe_getsockname

Get the name of the Unix domain socket or the named pipe.

获取pipe名字,buffer不含结束符,size不包含结束符。

uv_pipe_getpeername

Get the name of the Unix domain socket or the named pipe to which the handle is connected.

获取对方pipe的名称。

uv_pipe_pending_instances

Set the number of pending pipe instance handles when the pipe server is waiting for connections.

NoteThis setting applies to Windows only.

设置待处理句柄个数,仅适用于window

uv_pipe_pending_count

uv_pipe_pending_type

Used to receive handles over IPC pipes.

First - call uv_pipe_pending_count(), if it’s > 0 then initialize a handle of the given type, returned by uv_pipe_pending_type() and call uv_accept(pipe, handle).

Pipe待处理任务个数,uv_accept使用之前调用。

uv_pipe_chmod

Alters pipe permissions, allowing it to be accessed from processes run by different users. Makes the pipe writable or readable by all users. Mode can be UV_WRITABLE, UV_READABLE or UV_WRITABLE | UV_READABLE. This function is blocking.

此函数是同步的,设置pipe的权限。

TCP

http://docs.libuv.org/en/v1.x/tcp.html

TCP handles are used to represent both TCP streams and servers.

uv_tcp_t is a ‘subclass’ of uv_stream_t.

Server sockets proceed by:

  uv_tcp_init the TCP handle.

  uv_tcp_bind it.

  Call uv_listen on the handle to have a callback invoked whenever a new connection is   established by a client.

  Use uv_accept to accept the connection.

  Use stream operations to communicate with the client.

int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle);
int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, unsigned int flags);
int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock);
int uv_tcp_nodelay(uv_tcp_t* handle, int enable);
int uv_tcp_keepalive(uv_tcp_t* handle,
                               int enable,
                               unsigned int delay);
int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
int uv_tcp_bind(uv_tcp_t* handle,
const struct sockaddr* addr, unsigned int flags);
int uv_tcp_getsockname(const uv_tcp_t* handle,
struct sockaddr* name, int* namelen);
int uv_tcp_getpeername(const uv_tcp_t* handle,
struct sockaddr* name, int* namelen);
int uv_tcp_connect(uv_connect_t* req,uv_tcp_t* handle,
const struct sockaddr* addr, uv_connect_cb cb);

uv_tcp_init:Initialize the handle. No socket is created as of yet.

uv_tcp_init_ex:Initialize the handle with the specified flags. At the moment only the lower 8 bits of the flags parameter are used as the socket domain. A socket will be created for the given domain. If the specified domain is AF_UNSPEC no socket is created, just like uv_tcp_init().

flagsAF_UNIX域、AF_INET域、AF_UNSPEC域等。

uv_tcp_open:Open an existing file descriptor or SOCKET as a TCP handle.

Changed in version 1.2.1: the file descriptor is set to non-blocking mode.

Note The passed file descriptor or SOCKET is not checked for its type, but it’s required that it represents a valid stream socket.

打开句柄

uv_tcp_nodelay:Enable TCP_NODELAY, which disables Nagle’s algorithm.

https://www.cnblogs.com/wajika/p/6573014.html

uv_tcp_keepalive:Enable / disable TCP keep-alive. delay is the initial delay in seconds, ignored when enable is zero.

uv_tcp_simultaneous_accepts:Enable / disable simultaneous asynchronous accept requests that are queued by the operating system when listening for new TCP connections.

This setting is used to tune a TCP server for the desired performance. Having simultaneous accepts can significantly improve the rate of accepting connections (which is why it is enabled by default) but may lead to uneven load distribution in multi-process setups.

是否开启系统默认的同步接收。默认是开启的,同步接收accett

uv_tcp_bind:Bind the handle to an address and port. addr should point to an initialized struct sockaddr_in or struct sockaddr_in6.

When the port is already taken, you can expect to see an UV_EADDRINUSE error from either uv_tcp_bind()uv_listen()or uv_tcp_connect(). That is, a successful call to this function does not guarantee that the call to uv_listen() or uv_tcp_connect() will succeed as well.

flags可以包含UV_TCP_IPV6ONLY,在这种情况下,禁用双栈支持并且仅使用IPv6

uv_tcp_getsockname:Get the current address to which the handle is bound. addr must point to a valid and big enough chunk of memory, structsockaddr_storage is recommended for IPv4 and IPv6 support.

获取本地地址。

uv_tcp_getpeername:Get the address of the peer connected to the handle. addr must point to a valid and big enough chunk of memory, structsockaddr_storage is recommended for IPv4 and IPv6 support.

获取对方的地址。

uv_tcp_connect:Establish an IPv4 or IPv6 TCP connection. Provide an initialized TCP handle and an uninitialized uv_connect_taddrshould point to an initialized struct sockaddr_in or struct sockaddr_in6.

On Windows if the addr is initialized to point to an unspecified address (0.0.0.0 or ::) it will be changed to point to localhost. This is done to match the behavior of Linux systems.

客户端与tcpServer建立连接。

UDP

UDP handles encapsulate UDP communication for both clients and servers.

http://docs.libuv.org/en/v1.x/udp.html

int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, unsigned int flags);
int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
int uv_udp_bind(uv_udp_t* handle,
                          const struct sockaddr* addr,
                          unsigned int flags);
int uv_udp_send(uv_udp_send_t* req,uv_udp_t* handle, const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr* addr, uv_udp_send_cb send_cb);
int uv_udp_try_send(uv_udp_t* handle,const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr* addr);
size_t uv_udp_get_send_queue_size(const uv_udp_t* handle);
size_t uv_udp_get_send_queue_count(const uv_udp_t* handle);

int uv_udp_recv_start(uv_udp_t* handle,uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb);
int uv_udp_recv_stop(uv_udp_t* handle);

uv_udp_t:

/* uv_udp_t is a subclass of uv_handle_t. */

struct uv_udp_s {

  UV_HANDLE_FIELDS

  size_t send_queue_size;//待发送字节数

  size_t send_queue_count;//请求发送个数

  UV_UDP_PRIVATE_FIELDS

};

uv_udp_init:

Initialize a new UDP handle. The actual socket is created lazily. Returns 0 on success.

uv_udp_init_ex:

Initialize the handle with the specified flags. At the moment the lower 8 bits of the flags parameter are used as the socket domain. A socket will be created for the given domain. If the specified domain is AF_UNSPEC no socket is created, just like uv_udp_init().

uv_udp_open:

Opens an existing file descriptor or Windows SOCKET as a UDP handle.

Unix only: The only requirement of the sock argument is that it follows the datagram contract (works in unconnected mode, supports sendmsg()/recvmsg(), etc). In other words, other datagram-type sockets like raw sockets or netlink sockets can also be passed to this function.

Changed in version 1.2.1: the file descriptor is set to non-blocking mode.

Note:The passed file descriptor or SOCKET is not checked for its type, but it’s required that it represents a valid datagram socket.

打开init后的udp句柄

uv_udp_bind
Bind the UDP handle to an IP address and port.

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init().

addr – struct sockaddr_in or struct sockaddr_in6 with the address and port to bind to.

flags – Indicate how the socket will be bound, UV_UDP_IPV6ONLY and UV_UDP_REUSEADDR are supported.

Returns:0 on success, or an error code < 0 on failure.

uv_udp_send

Send data over the UDP socket. If the socket has not previously been bound with uv_udp_bind() it will be bound to 0.0.0.0 (the “all interfaces” IPv4 address) and a random port number.

On Windows if the addr is initialized to point to an unspecified address (0.0.0.0 or ::) it will be changed to point to localhost. This is done to match the behavior of Linux systems.

Parameters:req – UDP request handle. Need not be initializedmalloc.

handle – UDP handle. Should have been initialized with uv_udp_init().

bufs – List of buffers to send.

nbufs – Number of buffers in bufs.

addr – struct sockaddr_in or struct sockaddr_in6 with the address and port of the remote peer.

send_cb – Callback to invoke when the data has been sent out.

Returns:0 on success, or an error code < 0 on failure.

Changed in version 1.19.0: added 0.0.0.0 and :: to localhost mapping

uv_udp_try_send:

Same as uv_udp_send(), but won’t queue a send request if it can’t be completed immediately.

Returns:>= 0: number of bytes sent (it matches the given buffer size). < 0: negative error code (UV_EAGAIN is returned when the message can’t be sent immediately).

没有send_cb,不会加入发送队列,直接发送,其他同vu_udp_send.

uv_udp_get_send_queue_size:

Returns handle->send_queue_size.

Number of bytes queued for sending. This field strictly shows how much information is currently queued.

 

uv_udp_get_send_queue_count:

Returns handle->send_queue_count.

Number of send requests currently in the queue awaiting to be processed.

队列中的req请求数目。

 

uv_udp_recv_start

Prepare for receiving data. If the socket has not previously been bound with uv_udp_bind() it is bound to 0.0.0.0 (the “all interfaces” IPv4 address) and a random port number.

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init().

alloc_cb – Callback to invoke when temporary storage is needed.

recv_cb – Callback to invoke with received data.

Returns:0 on success, or an error code < 0 on failure.

 

uv_udp_recv_stop

Stop listening for incoming datagrams.

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init().

Returns:0 on success, or an error code < 0 on failure.

int uv_udp_getsockname(const uv_udp_t* handle,struct sockaddr* name,int* namelen);
int uv_udp_set_membership(uv_udp_t* handle,const char* multicast_addr,const char* interface_addr,uv_membership membership);
int uv_udp_set_multicast_loop(uv_udp_t* handle, int on);
int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr);
int uv_udp_set_broadcast(uv_udp_t* handle, int on);
int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr);
int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr);
int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size);
int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size);
int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
int uv_inet_pton(int af, const char* src, void* dst);

uv_udp_getsockname

Get the local IP and port of the UDP handle.

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init() and bound.

name – Pointer to the structure to be filled with the address data. In order to support IPv4 and IPv6 struct sockaddr_storage should be used.

namelen – On input it indicates the data of the name field. On output it indicates how much of it was filled.

Returns:0 on success, or an error code < 0 on failure.

uv_udp_set_membership

Set membership for a multicast address

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init().

multicast_addr – Multicast address to set membership for.

interface_addr – Interface address.

membership – Should be UV_JOIN_GROUP or UV_LEAVE_GROUP.

Returns:0 on success, or an error code < 0 on failure.

uv_udp_set_multicast_loop

Set IP multicast loop flag. Makes multicast packets loop back to local sockets.

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init().

本机是否接收组播包

on – 1 for on, 0 for off.

Returns:0 on success, or an error code < 0 on failure.

 uv_udp_set_multicast_ttl

Set the multicast ttl Time To Live

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init().

ttl – 1 through 255.

Returns:0 on success, or an error code < 0 on failure.

uv_udp_set_multicast_interface

Set the multicast interface to send or receive data on.

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init().

interface_addr – interface address.

Returns:0 on success, or an error code < 0 on failure.

uv_udp_set_broadcast

Set broadcast on or off.

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init().

on – 1 for on, 0 for off.

Returns:0 on success, or an error code < 0 on failure.

uv_udp_set_ttl:

Set the time to live. Time To Live

Parameters:handle – UDP handle. Should have been initialized with uv_udp_init().

ttl – 1 through 255.

Returns:0 on success, or an error code < 0 on failure.

uv_ip4_addr:

Convert a string containing an IPv4 addresses to a binary structure.

ipaddr

uv_ip6_addr:

Convert a string containing an IPv6 addresses to a binary structure.

uv_ip4_name:

Convert a binary structure containing an IPv4 address to a string.

addrip

uv_ip6_name:

Convert a binary structure containing an IPv6 address to a string.

uv_inet_ntop://将点分十进制的ip地址转化为用于网络传输的数值格式

uv_inet_pton://将数值格式转化为点分十进制的ip地址格式

Cross-platform IPv6-capable implementation of inet_ntop(3) and inet_pton(3). On success they return 0. In case of error the target dst pointer is unmodified

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值