struct {
uint16 msg_length;
uint8 msg_type;
ProtocolVersion version;
uint16 cipher_spec_length;
uint16 session_id_length;
uint16 challenge_length;
V2CipherSpec cipher_specs[V2ClientHello.cipher_spec_length];
opaque session_id[V2ClientHello.session_id_length];
opaque challenge[V2ClientHello.challenge_length;
} V2ClientHello;
是否可以做类似上面的事情(https://www.rfc-editor.org/rfc/rfc5246)?如果是这样,我该如何在 C 中对此进行编码?
更具体地说,结构中的这一行:
V2CipherSpec cipher_specs[V2ClientHello.cipher_spec_length];
用途:
> V2ClientHello.cipher_spec_length
这是在同一个结构体中定义的,用来设置数组的长度。
最佳答案
C 不支持动态大小的数组。为实现您的目标,您可以使用 V2CipherSpec
类型的指针作为结构变量,并在稍后阶段使用 V2ClientHello.cipher_spec_length
值分配内存。
关于c - 在 C 中,使用同一结构内的另一个值设置结构内数组的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25763343/