473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Creating a packet for RAW socket transfer

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

Feb 21 '06 #1
2 6136
On 21 Feb 2006 13:25:35 -0800, in comp.lang.c , "bobrics"
<bo*****@gmail.com> wrote:
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
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 22 '06 #2

"bobrics" <bo*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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
Feb 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: AA | last post by:
If I want to write the code, so... is everything same in both case (udp, tcp) with the only difference of the .net Socket class constructor? socketType for udp: Dgram for tcp: Stream ...
5
by: Glenn Wilson | last post by:
I am writing a network system for project I am working on. How would I send a class or structure to the clients and recieve one back. Or how would I go about building a packet with a header and...
0
by: Gregory Hassett | last post by:
Hello, I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip address, port 8801, and go to the peer's ip address,...
10
by: PH | last post by:
Hi guys! I need to get the remote EndPoint from when I receive packets when listening in a local port in my computer. I'm using UDP (connection-less) so I only bind the socket to my...
6
Sagittarius
by: Sagittarius | last post by:
I will first try to describe my problem in words. I have a simple program, written in C++, that needs to send a single bytearray via a UDP socket to a microprocessor, which returns an answer, also...
1
by: AngreGanon | last post by:
Hi all~ I've written a network program in C. This program catputures ARP request packet and reply wrong ARP packet. Hi. I've written a small program to learn to write in C. But unfortunately...
1
by: nitheshsalian | last post by:
I have created a Packet as a structure. i am not able to send the packet through the send() because what i have understood it sends only strings. Is there any way to send the packet as a structure...
4
by: Zytan | last post by:
This may be the dumbest question of all time, but... When I set the packet size, does it mean ALL packets are that size, no matter what? Let's say the packet size is 8KB, and I send a 5 byte...
1
by: alex21 | last post by:
Ok i have never before tried networking in my programming, so this is the first time i have tried anything like this. But i am trying to make an application which acts as a medium between a server...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.