Re: Why put the structures in a structure when assembling a TCP/IP Packet?
On Oct 8, 7:04 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article <1191893579.696576.127...@k79g2000hse.googlegroups .com>,
>
> grocery_stocker <cdal...@gmail.com> wrote:
> > Is there anykind of significance to putting a structure inside another
> > stucture when assembling a TCP/IP packet by hand? In the following
> > code snippet, struct iphdr and struct tcphdr are inside another
> > stucture. The only thing I can think of is that it's to ensure some
> > kind of memory alignmen
>
> > struct tpack{
> > struct iphdr ip;
> > struct tcphdr tcp;
> > }tpack; /*Why put the structures inside another structure?*/
>
> Because that's how the packet is actually laid out. It also allows
> applications that want to do stuff with the whole header to use a single
> variable rather than two.
>
> --
I would like to take the time to point out that "googling" for
examples of building TCP/IP packets isn't always a good thing. Half
the sites I found had something like
struct tpack{
struct iphdr ip;
struct tcphdr tcp;
}tpack;
And the other half had something like
struct iphdr ip;
struct tcphdr tcp;
I figured the former, Ie
struct tpack{
struct iphdr ip;
struct tcphdr tcp;
}tpack;
was a little bit more politically correct since it was taken from the
Phrack, while the latter was take someone's personal blog.
|