B
bobrics
Hi,
I would like to create a packet for a RAW socket transfer. Please let
me know if this is the right approach.
1. First, I am creating a header structure where I store all the
information I would like to put in the header of a packet.
2. I know the size of data I will send and the header size in bytes, so
I allocate the space in memory for both and create two pointers: for
data part (dataptr) and header part. Header pointer coinsided with the
beginning of the packet.
3. I read the file into a data part of the packet. So my read buffer is
actually dataptr. This way I avoid copying the buffer to the location
where my packet is stored.
4. Depending on how many bytes read from the file, I update the
corresponding fields in the header structure, including CRC, etc..
5. I construct a header part of the packet - the binary version of the
structure (probably using bit masks).
6. The packet is then sent out to the RAW socket.
I have some questions about step 5.
I assume it's needed since I am using variable-length fields, including
single bit flags. I was thinking since I need to target specific groups
of bits, I would need bit masks. However, since my header will be more
than 32bits (size of int on 32-bit machine), I cannot just have int
FLAG variable and use different MASKS to change the bits. I need
something larger, like a char array. However, I am not sure how it is
done then. What is the good strategy for that?
Thank you
I would like to create a packet for a RAW socket transfer. Please let
me know if this is the right approach.
1. First, I am creating a header structure where I store all the
information I would like to put in the header of a packet.
2. I know the size of data I will send and the header size in bytes, so
I allocate the space in memory for both and create two pointers: for
data part (dataptr) and header part. Header pointer coinsided with the
beginning of the packet.
3. I read the file into a data part of the packet. So my read buffer is
actually dataptr. This way I avoid copying the buffer to the location
where my packet is stored.
4. Depending on how many bytes read from the file, I update the
corresponding fields in the header structure, including CRC, etc..
5. I construct a header part of the packet - the binary version of the
structure (probably using bit masks).
6. The packet is then sent out to the RAW socket.
I have some questions about step 5.
I assume it's needed since I am using variable-length fields, including
single bit flags. I was thinking since I need to target specific groups
of bits, I would need bit masks. However, since my header will be more
than 32bits (size of int on 32-bit machine), I cannot just have int
FLAG variable and use different MASKS to change the bits. I need
something larger, like a char array. However, I am not sure how it is
done then. What is the good strategy for that?
Thank you