了解结构 sockaddr [英] Understanding struct sockaddr

查看:18
本文介绍了了解结构 sockaddr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

struct sockaddr {
    unsigned short sa_family;   // address family, AF_xxx
    char           sa_data[14]; // 14 bytes of protocol address
};

在这个结构中,sa_family所描述的address family究竟是什么意思?

In this structure what exactly is the meaning address family depicted by sa_family?

这是否意味着像 TCP/UDP 这样的协议有地址"?好吧,我认为协议可以是识别号而不是地址.

Does it mean that protocols like TCP/UDP have "addresses"? Well, the protocols can be identification numbers not addresses, I think.

无论如何,如果是,那么他们的家庭是根据什么划分的?

Anyway, if yes, then on what basis have their families been divided?

推荐答案

地址的格式和大小通常是特定于协议的.

The format and size of the address is usually protocol specific.

sockaddr 用作一组地址结构的基础,这些地址结构的作用类似于可区分的联合,请参阅 Beej 网络指南.你一般看sa_family,然后转换成合适的地址族的具体地址结构.

sockaddr is used as the base of a set of address structures that act like a discriminated union, see the Beej guide to networking. You generally look at the sa_family and then cast to the appropriate address family's specific address structure.

TCP 和 UDP 本身并没有特定的地址,而是 IP 级别对于 IPv4 和 IPv6 有不同大小的地址.

TCP and UDP do not have addresses specific to them as such, rather the IP level has different sizes of address for IPv4 and IPv6.

另见:

这篇关于了解结构 sockaddr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆