15 Replies - 13809 Views - Last Post: 17 September 2010 - 01:40 PM
#1
Packets and how to make them...?
Posted 17 September 2010 - 07:35 AM
I was wondering if somebody guides me to some tutorials regarding packets. I want to know the basics of packets and how to form a packet send/receive packets. I want it in C programming. Thanks
Replies To: Packets and how to make them...?
#2
Re: Packets and how to make them...?
Posted 17 September 2010 - 07:49 AM
#3
Re: Packets and how to make them...?
Posted 17 September 2010 - 07:55 AM
#4
Re: Packets and how to make them...?
Posted 17 September 2010 - 08:11 AM
Quote
How is this going to work?
#5
Re: Packets and how to make them...?
Posted 17 September 2010 - 08:18 AM
Oler1s, on 17 September 2010 - 07:11 AM, said:
Quote
How is this going to work?
I am trying to take my baby steps. For starter, I want to learn what is a packet and how to form it in C. I know what is a packet and that somehow you can use C structs to form a packet. But I want a tutorial for beginner to show how to form a packet, of course in C? without geting involved into complicated IP/TCP kinda of stuff. Thanks
#6
Re: Packets and how to make them...?
Posted 17 September 2010 - 08:41 AM
Quote
char packet[100];
There. That's a packet. It's also not very meaningful without context. In this case, I have none. I just created a block of data.
#7
Re: Packets and how to make them...?
Posted 17 September 2010 - 09:04 AM
#8
Re: Packets and how to make them...?
Posted 17 September 2010 - 09:05 AM
Oler1s, on 17 September 2010 - 07:41 AM, said:
Quote
char packet[100];
There. That's a packet. It's also not very meaningful without context. In this case, I have none. I just created a block of data.
Suppose you have a file, say a .jpg image. How do you break down this image file and put it in packets in preparation for sending it somewhere?Thanks
#9
Re: Packets and how to make them...?
Posted 17 September 2010 - 10:36 AM
Then you need to read the file into memory, either directly to that buffer, or to another buffer, and then copy over to buf. So you might use the function fread in stdio.h to read from the file.
You'll basically just repeatedly read and store in the buffer. Then use that buffer when sending data.
#10
Re: Packets and how to make them...?
Posted 17 September 2010 - 11:02 AM
zardoshti2010, on 17 September 2010 - 06:35 PM, said:
Given that, I think you should learn and practice C a bit more, before going towards network programming.
#11
Re: Packets and how to make them...?
Posted 17 September 2010 - 11:27 AM
Oler1s, on 17 September 2010 - 09:36 AM, said:
Then you need to read the file into memory, either directly to that buffer, or to another buffer, and then copy over to buf. So you might use the function fread in stdio.h to read from the file.
You'll basically just repeatedly read and store in the buffer. Then use that buffer when sending data.
Thanks a lot. Your explanation was ver helpful. Do you happen to have an example source code? Thanks
#12
Re: Packets and how to make them...?
Posted 17 September 2010 - 11:32 AM
Quote
#13
Re: Packets and how to make them...?
Posted 17 September 2010 - 12:12 PM
If you're moving files about and you don't want to write a protocol yourself, then pick one. Now you're at the top of the stack. HTTP is a good choice, since it's ubiquitous and basically text.
#14
Re: Packets and how to make them...?
Posted 17 September 2010 - 12:26 PM
zardoshti2010, on 17 September 2010 - 08:35 AM, said:
This is asking for someone else to do your homework :
zardoshti2010, on 17 September 2010 - 08:35 AM, said:
Examples of socket programming are going to be much more relevant if you can provide us with which Operating System you are trying to develop this for. Though it doesn't sound like you are writing a program, but doing homework. If this is the case, are you not covering the what & how in class?
Sorry to beat the dead horse here, but your request just seems straight forward that you just want a working example. We get that. Help us to understand what you are trying to get done. No one just decides they are going to send self created networking packets with C. There must be more to this.
#15
Re: Packets and how to make them...?
Posted 17 September 2010 - 12:46 PM
The problem is that I don't know of any API that lets you modify packets at that low of a level. You'd almost have to be writing a network driver yourself to create a completely custom packet and send it over the network.
For any real world usage of networking, you aren't going to be manipulating data on a per-packet level. You'll just tell your program to connect to an IP address and start sending and receiving data and it works out all the details of splitting it into packets and forming the correct headers.