请帮助我理解最后一行的作用:
int PCKT_LEN = 8192;
char buffer[PCKT_LEN];
struct iphdr *ip = (struct iphdr *) buffer;
struct udphdr *udp = (struct udphdr *) (buffer + sizeof(struct iphdr));
我知道这个,我有点理解:
(struct udphdr *) -> Means cast to a udphdr "object"/instance or something like that.
这个我有疑问/不明白:
(buffer + sizeof(struct iphdr))
This one, I don't quite understand. Is it because it uses the ADDRESS being returned by buffer and then adds the actual size of the buffer until the last byte as an offset before starting to allocate udp memory range? I guess the it wants to start the address of udp right after the ip ?
如果我像下面这样执行最后一行,结果会一样吗?(我将缓冲区改为ip)
struct udphdr *udp = (struct udphdr *) (ip + sizeof(struct iphdr));
谢谢。
问候,
X
(我是 CPP 新手,刚刚开始学习指针和结构体。)