Network
Basic Concepts
The network module implements basic functions of the TCP/IP protocol stack and provides the standard POSIX socket interfaces.
NOTE: Currently, the OS uses lwIP to provide network capabilities.
When to Use
For user-space development, the OpenHarmony kernel provides a set of APIs for you to implement network functionalities, including creating and disabling sockets, transmitting and receiving data, and setting network attributes, in addition to standard POSIX socket functions provided by the C library.
Description
Table 1 Standard APIs in the C library
Details on API differences:
-
sendmsg
Function prototype:
ssize_t sendmsg(int s, const struct msghdr *message, int flags)
Function description: sends a message on a socket.
Parameter description:
Indicates the pointer to the message to be sent. The ancillary message is not supported.
Indicates the socket flags for sending the message. The options are as follows:
Return values:
- Returns the number of bytes that have been sent if the operation is successful.
- Returns -1 and sets errno if the operation fails.
-
recvmsg
Function prototype:
ssize_t recvmsg(int s, struct msghdr *message, int flags)
Function description: receives a message from a socket.
Parameter description:
Indicates the pointer to the address to receive the message. The ancillary message is not supported.
Indicates the socket flags for receiving the message. The options are as follows:
Return values:
- Returns the number of bytes that have been received if the operation is successful.
- Returns -1 and sets errno if the operation fails.
-
ioctl
Function prototype:
int ioctl(int s, int request, ...)
Function description: obtains or sets socket options.
Parameter description:
Indicates the operation to perform on the socket options. The options are as follows:
Return values:
- Returns 0 if the operation is successful.
- Returns -1 and sets errno if the operation fails.