netinet/in.h - Internet Protocol family

本文介绍了网络编程中重要的头文件<netinet/in.h>,详细解释了其中定义的数据类型、结构体和宏,包括in_port_t、in_addr_t、in_addr、sockaddr_in等,并列举了它们在网络编程中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

NAME
netinet/in.h - Internet Protocol family
SYNOPSIS


#include <netinet/in.h>

DESCRIPTION
When header file <netinet/in.h> is included, the following types are defined through typedef.

 

in_port_t
An unsigned integral type of exactly 16 bits.
in_addr_t
An unsigned integral type of exactly 32 bits.

The <netinet/in.h> header defines the in_addr structure that includes at least the following member:


in_addr_t      s_addr

The <netinet/in.h> header defines the sockaddr_in structure that includes at least the following member:


sa_family_t    sin_family
in_port_t      sin_port
struct in_addr sin_addr
unsigned char  sin_zero[8]

The sockaddr_in structure is used to store addresses for the Internet protocol family. Values of this type must be cast to struct sockaddr for use with the socket interfaces defined in this document.

The <netinet/in.h> header defines the type sa_family_t as described in <sys/socket.h>.

The <netinet/in.h> header defines the following macros for use as values of the level argument of getsockopt() and setsockopt():

IPPROTO_IP
Dummy for IP.
IPPROTO_ICMP
Control message protocol.
IPPROTO_TCP
TCP.
IPPROTO_UDP
User datagram protocol.

The <netinet/in.h> header defines the following macros for use as destination addresses for connect(), sendmsg() and sendto():

INADDR_ANY
Local host address.
INADDR_BROADCAST
Broadcast address.

ntohl(), ntohs(), htonl() and htons() as defined in the description of <arpa/inet.h> are available. Inclusion of the <netinet/in.h> header may also make visible all symbols from <arpa/inet.h>.

SEE ALSO

getsockopt(), setsockopt(). <sys/socket.h>.

http://pubs.opengroup.org/onlinepubs/007908799/xns/netinetin.h.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值