PRNetAddr 编辑

Type used with Socket Manipulation Functions to specify a network address.

Syntax

#include <prio.h>

union PRNetAddr {
  struct {
     PRUint16 family;
     char data[14];
  } raw;
  struct {
     PRUint16 family;
     PRUint16 port;
     PRUint32 ip;
     char pad[8];
  } inet;
#if defined(_PR_INET6)
  struct {
     PRUint16 family;
     PRUint16 port;
     PRUint32 flowinfo;
     PRIPv6Addr ip;
  } ipv6;
#endif /* defined(_PR_INET6) */
};

typedef union PRNetAddr PRNetAddr;

Fields

The structure has the following fields:

family
Address family: PR_AF_INET|PR_AF_INET6 for raw.family, PR_AF_INET for inet.family, PR_AF_INET6 for ipv6.family.
data
Raw address data.
port
Port number of TCP or UDP, in network byte order.
ip
The actual 32 (for inet.ip) or 128 (for ipv6.ip) bits of IP address. The inet.ip field is in network byte order.
pad
Unused.
flowinfo
Routing information.

Description

The union PRNetAddr represents a network address. NSPR supports only the Internet address family. By default, NSPR is built to support only IPv4, but it's possible to build the NSPR library to support both IPv4 and IPv6. Therefore, the family field can be PR_AF_INET only for default NSPR, and can also be PR_AF_INET6 if the binary supports IPv6.

PRNetAddr is binary-compatible with the socket address structures in the familiar Berkeley socket interface, although this fact should not be relied upon. The raw member of the union is equivalent to struct sockaddr, the inet member is equivalent to struct sockaddr_in, and if the binary is built with IPv6 support, the ipv6 member is equivalent to struct sockaddr_in6. (Note that PRNetAddr does not have the length field that is present in struct sockaddr_in on some Unix platforms.)

The macros PR_AF_INET, PR_AF_INET6, PR_INADDR_ANY, PR_INADDR_LOOPBACK are defined if prio.h is included. PR_INADDR_ANY and PR_INADDR_LOOPBACK are special IPv4 addresses in host byte order, so they must be converted to network byte order before being assigned to the inet.ip field.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:59 次

字数:3046

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文