Creating a packet for RAW socket transfer

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
 
M

Mark McIntyre

Hi,

I would like to create a packet for a RAW socket transfer. Please let
me know if this is the right approach.

Ask again in comp.unix.programmer, this is offtopic in CLC.
Mark McIntyre
 
R

Rod Pemberton

bobrics said:
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?

I for one am willing to help with the C code. But, I don't have alot of
experience with sockets, and it appears you are still at the planning stage,
i.e., without sample code to correct.

Rod Pemberton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top