Afficher un message
Vieux 09/10/2007, 03h32   #1
grocery_stocker
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Why put the structures in a structure when assembling a TCP/IP Packet?

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?*/

struct sockaddr_in sin; /* IP address information */
/* Setup the sin struct with addressing
information */
sin.sin_family=AF_INET; /* Internet address family */
sin.sin_port=tcphp->dest; /* Source port */
sin.sin_addr.s_addr=iphp->saddr;/* Dest. address */

/* Packet assembly begins here */

/* Fill in all the TCP header
information */
tpack.tcp.source=tcphp->dest; /* 16-bit Source port number
*/
tpack.tcp.dest=tcphp->source; /* 16-bit Destination port */
tpack.tcp.seq=0; /* 32-bit Sequence Number */
tpack.tcp.ack_seq=htonl(ntohl(tcphp->seq)+1); /* 32-bit
Acknowledgement Number */
tpack.tcp.doff=5; /* Data offset */
tpack.tcp.res1=0; /* reserved */
tpack.tcp.res2=0; /* reserved */
tpack.tcp.urg=0; /* Urgent offset valid flag */
tpack.tcp.ack=1; /* Acknowledgement field valid
flag */
tpack.tcp.psh=0; /* Push flag */
tpack.tcp.rst=1; /* Reset flag */
tpack.tcp.syn=0; /* Synchronize sequence
numbers flag */
tpack.tcp.fin=0; /* Finish sending flag */
tpack.tcp.window=0; /* 16-bit Window size */
tpack.tcp.check=0; /* 16-bit checksum (to be
filled in below) */
tpack.tcp.urg_ptr=0; /* 16-bit urgent offset */

/* Fill in all the IP header
information */

tpack.ip.version=4; /* 4-bit Version */
tpack.ip.ihl=5; /* 4-bit Header Length */
tpack.ip.tos=0; /* 8-bit Type of service */
tpack.ip.tot_len=htons(IPHDR+TCPHDR); /* 16-bit Total length */
tpack.ip.id=0; /* 16-bit ID field */
tpack.ip.frag_off=0; /* 13-bit Fragment offset */
tpack.ip.ttl=64; /* 8-bit Time To Live */
tpack.ip.protocol=IPPROTO_TCP; /* 8-bit Protocol */
tpack.ip.check=0; /* 16-bit Header checksum
(filled in below) */
tpack.ip.saddr=iphp->daddr; /* 32-bit Source Address */
tpack.ip.daddr=iphp->saddr; /* 32-bit Destination Address
*/

  Réponse avec citation
 
Page generated in 0,05867 seconds with 9 queries