Packets and how to make them...?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 7944 Views - Last Post: 17 September 2010 - 01:40 PM Rate Topic: -----

#1 zardoshti2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 10

Packets and how to make them...?

Posted 17 September 2010 - 07:35 AM

Hi there,

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
Is This A Good Question/Topic? 0
  • +

Replies To: Packets and how to make them...?

#2 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Packets and how to make them...?

Posted 17 September 2010 - 07:49 AM

http://www.lmgtfy.co...rogramming+in+c
Was This Post Helpful? 0
  • +
  • -

#3 zardoshti2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 10

Re: Packets and how to make them...?

Posted 17 September 2010 - 07:55 AM

View PostSarumanTheWhite, on 17 September 2010 - 06:49 AM, said:




That, I could do myself. It talks about socket programming. My question was about how to make a packet in C? and how to send/receive it? not those complicated network programming. Thanks anyway.
Was This Post Helpful? 0
  • +
  • -

#4 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Packets and how to make them...?

Posted 17 September 2010 - 08:11 AM

Quote

My question was about how to make a packet in C? and how to send/receive it? not those complicated network programming.
You've got a nice contradiction going here. You want to learn how to send and receive packets, but you don't want to touch the topic of sockets and networks (which would deal with the question of sending and receiving packets).

How is this going to work?
Was This Post Helpful? 2
  • +
  • -

#5 zardoshti2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 10

Re: Packets and how to make them...?

Posted 17 September 2010 - 08:18 AM

View PostOler1s, on 17 September 2010 - 07:11 AM, said:

Quote

My question was about how to make a packet in C? and how to send/receive it? not those complicated network programming.
You've got a nice contradiction going here. You want to learn how to send and receive packets, but you don't want to touch the topic of sockets and networks (which would deal with the question of sending and receiving packets).

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
Was This Post Helpful? 0
  • +
  • -

#6 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Packets and how to make them...?

Posted 17 September 2010 - 08:41 AM

Quote

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.
A packet is a chunk of data. That's it. Here's an example of a packet in C:

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.
Was This Post Helpful? 1
  • +
  • -

#7 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,140
  • Joined: 14-September 07

Re: Packets and how to make them...?

Posted 17 September 2010 - 09:04 AM

I would start here. Then I'd make a model or data structure of that in my program. Then I'd figure out how to send and receive that data using my structures.
Was This Post Helpful? 1
  • +
  • -

#8 zardoshti2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 10

Re: Packets and how to make them...?

Posted 17 September 2010 - 09:05 AM

View PostOler1s, on 17 September 2010 - 07:41 AM, said:

Quote

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.
A packet is a chunk of data. That's it. Here's an example of a packet in C:

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
Was This Post Helpful? 0
  • +
  • -

#9 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Packets and how to make them...?

Posted 17 September 2010 - 10:36 AM

You want to read from the file and store in a block of memory. Let's say you decide to operate on 512 byte memory blocks. That is, you divide up the file into 512 bytes and send that much in a packet's payload. So your data structure is going to be char buf[512] or the like. It's just 512 bytes there to be filled up with data.

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.
Was This Post Helpful? 1
  • +
  • -

#10 Anarion  Icon User is offline

  • The Persian Coder
  • member icon

Reputation: 282
  • View blog
  • Posts: 1,456
  • Joined: 16-May 09

Re: Packets and how to make them...?

Posted 17 September 2010 - 11:02 AM

View Postzardoshti2010, on 17 September 2010 - 06:35 PM, said:

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

Given that, I think you should learn and practice C a bit more, before going towards network programming.
Was This Post Helpful? 1
  • +
  • -

#11 zardoshti2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 10

Re: Packets and how to make them...?

Posted 17 September 2010 - 11:27 AM

View PostOler1s, on 17 September 2010 - 09:36 AM, said:

You want to read from the file and store in a block of memory. Let's say you decide to operate on 512 byte memory blocks. That is, you divide up the file into 512 bytes and send that much in a packet's payload. So your data structure is going to be char buf[512] or the like. It's just 512 bytes there to be filled up with data.

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
Was This Post Helpful? 0
  • +
  • -

#12 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Packets and how to make them...?

Posted 17 September 2010 - 11:32 AM

Quote

Do you happen to have an example source code?
Not really. I don't see why it's necessary though. It's just file I/O. Consult Google for function documentation, and just follow C syntax to write the code.
Was This Post Helpful? 1
  • +
  • -

#13 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5795
  • View blog
  • Posts: 12,627
  • Joined: 16-October 07

Re: Packets and how to make them...?

Posted 17 September 2010 - 12:12 PM

Packets are just the basic building blocks of data transfer. Unless you're down in the ethernet trenches, everything is a packet. Sounds like you want to be higher up the stack.

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.
Was This Post Helpful? 0
  • +
  • -

#14 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5224
  • View blog
  • Posts: 26,990
  • Joined: 10-May 07

Re: Packets and how to make them...?

Posted 17 September 2010 - 12:26 PM

This is networking :

View Postzardoshti2010, on 17 September 2010 - 08:35 AM, said:

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.


This is asking for someone else to do your homework :

View Postzardoshti2010, on 17 September 2010 - 08:35 AM, said:

I want it in C programming.


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.
Was This Post Helpful? 1
  • +
  • -

#15 Darkhack  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 208
  • Joined: 25-November 08

Re: Packets and how to make them...?

Posted 17 September 2010 - 12:46 PM

Wikipedia describes the structure of a packet very well. http://en.wikipedia....ple:_IP_packets

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.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2