当前位置 : 主页 > 手机开发 > harmonyos >

Linux C socket编程中几个常见的结构体定义

来源:互联网 收集:自由互联 发布时间:2023-10-08
● sockaddr #includesys/socket.hstruct sockaddr{sa_family_t sa_family;char sa_data[14];}; ● in_addr_t #includenetinet/in.h/* Internet address. */typedef uint32_t in_addr_t;struct in_addr{in_addr_t s_addr;}; ● in_port_t #includenetinet/


● sockaddr

#include	<sys/socket.h>
struct sockaddr
{
	sa_family_t sa_family;
	char sa_data[14];
};




● in_addr_t


#include	<netinet/in.h>
/* Internet address.  */
typedef uint32_t in_addr_t;
struct in_addr
{
	in_addr_t s_addr;
};



● in_port_t


#include	<netinet/in.h>
/* Type to represent a port.  */
typedef uint16_t in_port_t;



● sockaddr_in


#include	<netinet/in.h>
struct sockaddr_in
{
	sa_family_t sin_family;
	in_port_t sin_port;
	struct in_addr sin_addr;


	unsigned char sin_zero[sizeof (struct sockaddr) -
		(sizeof (unsigned short int)) -
		sizeof (in_port_t) -
		sizeof (struct in_addr)];
};



● addrinfo, servent, protoent, netent, hostent


/* Structure to contain information about address of a service provider.  */
struct addrinfo
{
	int ai_flags;			/* Input flags.  */
	int ai_family;		/* Protocol family for socket.  */
	int ai_socktype;		/* Socket type.  */
	int ai_protocol;		/* Protocol for socket.  */
	socklen_t ai_addrlen;		/* Length of socket address.  */
	struct sockaddr *ai_addr;	/* Socket address for socket.  */
	char *ai_canonname;		/* Canonical name for service location.  */
	struct addrinfo *ai_next;	/* Pointer to next in list.  */
};


/* Description of data base entry for a single service.  */
struct servent
{
	char *s_name;			/* Official service name.  */
	char **s_aliases;		/* Alias list.  */
	int s_port;			/* Port number.  */
	char *s_proto;		/* Protocol to use.  */
};


/* Description of data base entry for a single service.  */
struct protoent
{
	char *p_name;			/* Official protocol name.  */
	char **p_aliases;		/* Alias list.  */
	int p_proto;			/* Protocol number.  */
};




/* Description of data base entry for a single network.  NOTE: here a
   poor assumption is made.  The network number is expected to fit
   into an unsigned long int variable.  */
struct netent
{
	char *n_name;			/* Official name of network.  */
	char **n_aliases;		/* Alias list.  */
	int n_addrtype;		/* Net address type.  */
	uint32_t n_net;		/* Network number.  */
};




/* Description of data base entry for a single host.  */
struct hostent
{
	char *h_name;			/* Official name of host.  */
	char **h_aliases;		/* Alias list.  */
	int h_addrtype;		/* Host address type.  */
	int h_length;			/* Length of address.  */
	char **h_addr_list;		/* List of addresses from name server.  */
#if defined __USE_MISC || defined __USE_GNU
# define	h_addr	h_addr_list[0] /* Address, for backward compatibility.*/
#endif
};









上一篇:WordPress的几款代码高亮插件比较
下一篇:没有了
网友评论