⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 network.txt

📁 Linux C 语言函数
💻 TXT
📖 第 1 页 / 共 2 页
字号:
accept

SYNOPSIS
int accept(int s, struct sockaddr *addr, int *addrlen); 


PARAMETERS
s: [in] the socket connections are accepted from. 

addr: [out] contains the address of the the buffer that will be filled with the address of 
connecting entity. 

addrlen: [out] on input contains the maximum length of addr in bytes, on output contains the
length of addr in bytes. 


DESCRIPTION
If connections are pending on the socket s, the first connection in the queue is dequeued 
and opened and a new socket with the same properties of s is returned. If no connection is 
pending and the socket is blocking, then the call blocks until a connection is requested 
on s. Otherwise the call returns an error code. The socket s remains open for future 
connections. The address of the connecting entity is returned in addr. The format of the 
address depends on the type of network on through which the socket communicates. accept does
not send a confirmation at the connecting entity. 


RETURN VALUE
On success, the call returns a positive value that is the file descriptor of the new socket.
 On errror, the call returns -1 and sets errno to one of the following error values: 


EOPNOTSUPP: The referenced socket is not of type SOCK_STREAM. 
EWOULDBLOCK: The socket is marked non-blocking and no connection is pending. 
EBADF, ENOTSOCK or EFAULT 


*************************************************************************************
bind

SYNOPSIS
int bind(int sockfd, struct sockaddr *my_addr, int addrlen); 


PARAMETERS
sockfd: [in] the socket to bind. 

my_addr: [in] the address to bind the socket to. 

addrlen: [in] the length of addr (in bytes). 


DESCRIPTION
Binds the socket sockfd to the local address my_addr. The format of the address is network 
dependent. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 


EINVAL: the socket is already bound to an address, or addrlen is invalid or the socket is 
	not in the AF_UNIX family. 
EACCESS: the address is reserved for super-user usage and the calling task has not 
	super-user privileges or the taks does not have enough access rights on the path. 
ENAMETOOLONG: my_addr is too long. 
EBADF, EROFS, EFAULT, ENOENT, ENOMEM, ENOTDIR or ELOOP. 



*************************************************************************************
connect

SYNOPSIS
int connect(int sockfd, struct sockaddr *serv_addr, int addrlen); 


PARAMETERS
sockfd: [in] the socket to connect. 

serv_addr: [in] the remote address to connect to. 

addrlen: [in] the lenght (in bytes) of serv_addr. 


DESCRIPTION
If the socket is of type SOCK_DGRAM, it connects the socket sockfd to a remote address 
specified by serv_addr. A datagram socket can call connect multiple times to change the 
remote address. If the socket is of type SOCK_STREAM, it connects the socket to another 
socket. In that case, the format of serv_addr depends on the communication space of the 
socket. A stream socket may only call connect once. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 


EINVAL: the socket is in some kind of limbo state: neither connected nor unconnected!!! 
EBADF, ENOTSOCK, EISCONN, EALREADY, EAGAIN, EOPNOTSUPP, EINPROGRESS, ERESTARTSYS. 


*************************************************************************************
getdomainname and setdomainname

SYNOPSIS
int getdomainname(char *name, size_t len); 

int setdomainname(const char *name, size_t len); 


PARAMETERS
name: (For getdomainname) [out] points to a buffer where to save the domain name. (For 
setdomainname) [in] points to a buffer containing the new domain name. 

len: [in] the maximum length of name. 


DESCRIPTION
Those calls get or set the machine's domainname. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 

In the case of getdomainname: EINVAL: name is NULL or the domain name is longer than len. 

In the case of setdomainname: 


EPERM: the caller is not superuser. 
EINVAL: len is too long. 



*************************************************************************************
gethostid and sethostid

SYNOPSIS
long int gethostid(void); 

int sethostid(long int hostid); 


DESCRIPTION
gethostid returns the host id and sethostid sets it. The host id is usually the network 
address of the host. 


RETURN VALUE
gethostid returns the 32 bits host id.


*************************************************************************************
gethostname and sethostname

SYNOPSIS
int gethostname(char *name, size_t len); 

int sethostname(const char *name, size_t len); 


PARAMETERS
name: (For gethostname) [out] points to a buffer where to put the host name. (For 
sethostname) [in] points to the new host name. 

len: [in] the maximum length of name. 


DESCRIPTION
gethostname returns the host name of the current host and sethostname sets it. Only the 
superuser may call sethostname. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 

In the case of gethostname: EINVAL: name is NULL or the host name is longer than len. 

In the case of sethostname: 


EPERM: the caller is not superuser. 
EINVAL: len is too long.

*************************************************************************************
getpeername

SYNOPSIS
int getpeername(int s, struct sockaddr *name, int *namelen); 


PARAMETERS
s: [in] the socket. 

name: [out] points to the buffer where to store the name. 

namelen: [in out] the maximum length (in bytes) of name. 


DESCRIPTION
Returns the name of the peer machine connected to the remote end of a socket. If the buffer
is too small, the name is truncated. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 


EBADF, ENOSOCK, ENOTCONN, ENOBUFS and EFAULT. 

*************************************************************************************
getsockname

SYNOPSIS
int getsockname(int s, struct sockaddr *name, int * namelen); 


PARAMETERS
s: [in] the socket accessed. 

name: [out] the buffer where to put the name in. 

namelen: [in out] on entry, the maximum length of name. On return, it contains the actual 
length of the name. 


DESCRIPTION
Gets the local socket name. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 


EBADF, ENOTSOCK, ENOBUFS and EFAULT.

*************************************************************************************
getsockopt

SYNOPSIS
int getsockopt(int s, int level, int optname, void *optval, int *optlen); 

int setsockopt(int s, int level, int optname, const void *optval, int optlen); 


PARAMETERS
s: [in] the socket we want to work on. 

level: [in] the protocol level to access. 

optname: [in] the option to access. 

optval: for getsockopt, [out] points to the buffer where to save the option value. For 
	setsockopt, [in] points to the buffer containing the new option value. 

optlen: for getsockopt, [in out] on entry, the maximum length of optval, on return, the 
	actual length of the option. For setsockopt, the length of the new option. 


DESCRIPTION
The possible values of level are SOL_SOCKET and any valid protocol number. At socket level,
a value of zero for the options is boolean flase and a non-zero value is boolean true. The 
following options are recognized at socket level: 


SO_DEBUG 
Enable/disable the recording of the debug information by the underliying protocol modules. 
optval is an boolean value (int). 

SO_REUSEADDR 
Enable/disable local address reuse so that a bind call can reuse old addresses. optval is 
a boolean value (int). 

SO_KEEPALIVE 
Enable/disable the "keep connections alive" feature. Using this feature, periodic messages 
are sent to the remote connection. If the peer machine does not respond to those messages, 
the connection is broken and the processes using the socket receive a SIGPIPE signal. 
optval is a boolean value (int). 

SO_DONTROUTE 
Enable/disable the routing bypass for outgoing message. If enabled, the socket completely by
pass the routing facilities of the operating system. optval is a boolean value (int). 

SO_LINGER 
Linger on close if data present. Without this feature, a close on a socket is always 
performed in a quick non-blocking fashion. However, when this feature is enabled, the close
call will block for a while if the socket still has data enqueued on the send queue. 
The call will block until it is able to send the data or if a specified timeout value 
expire. optval is a struct linger structure. 

SO_BROADCAST 
Enable/disable the permission of broadcasting packets. optval is a boolean value (int). 

SO_OOBINLINE 
Enable/disable the reception of out-of-band data as in band data. optval is a boolean value
(int). 

SO_SNDBUF 
Set the buffer size for output. optval is an int. 

SO_RCVBUF 
Set the buffer size for input. optval is an int. 

SO_SNDLOWAT 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -