network programming
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: network programming

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    161

    network programming

    Hello:
    I am currently in a project that involves net programming inC. The part I must solve is how to read chunks from a given file, and then pack them into UDP packets. I am guessing that I most use fread() or read(). But how do I handle the correct assembly of packets at the receiver? Any clues, tips or references are welcome.


    Thanks,
    J

  2. #2
    Banned
    Join Date
    Mar 2004
    Posts
    28

    Cisco Products

    communication of that type is easy to access, use a packet sniffer, like a port sniffer, except reads packets.

  3. #3
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    Because it's UDP you need to code something and send it allong with the data to put it all back into order again. I also suggest sending along some sort of verification to make sure the packets came in unmolested.

    Something like:

    <normal udp header>[udp data contains:<sequence number><checksum><size><data>]

    As I said you have to take care of the seq. number, checksum and size. If you send this information along it should be easy to verify the chucks and put them in the correct order on the receiving end.
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  4. #4
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    Why don't you just add a number at the start of each packet, and then when it gets to the receiving computer, it puts the packets into numerical order and strips the numbers back out. SirDice is right in that you should add in validation (I think it's validation, not verification...just being picky) of some kind, but I think that the tcp/ip network model handles that in any case.

    ac

  5. #5
    Senior Member
    Join Date
    Dec 2003
    Location
    Pacific Northwest
    Posts
    1,675
    John,

    The part I must solve is how to read chunks from a given file, and then pack them into UDP packets
    Do a search at this site for comments about sniffers and of course www.google.com for one as well.

    Don't be afraid of grabbing a packet builder to help you in your venture instead of just winging it.

    http://www.engagesecurity.com/produc...packetbuilder/

  6. #6
    Senior Member
    Join Date
    Apr 2002
    Posts
    161

    udp datagram size

    Hey, thanks everyone for your replies. I have another question: what is the max payload size that can be put on an UDP datagram? This is so i know the how to split a certain file in the right block sizes.

    thanks
    J

  7. #7
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    Actually, the maximum size of a datagram is the biggest value you can fit in the length field of the udp header (header length + data length). Since the length field is 16 bits, you can fit 2^16-8 bytes in a single udp datagram.

    And what about the mtu? Well that's the magic in the osi/tcp layers, you don't have to worry about the lower layers. If the ip packet the datagram is wrapped in encounters an mtu smaller that 64k (rather likely!), the IP packet will be fragged; however, IP handles the fragmentation and reassembly for you!


    Ammo
    Credit travels up, blame travels down -- The Boss

  8. #8
    Senior Member
    Join Date
    Apr 2002
    Posts
    161
    Ammo:
    So I can partition the file in 2^16-8 bytes blocks and then use UDP socket primitive sendto() and I dont have to worry about IP or ethernet MTU's, cool
    I need some insight on how to actually partition a file in a given size blocks and construct my UDP packet in C.
    I am new to network programming and it sure is a complex subject. Any functions that might be useful for this will be greatly appreciated.

    Thanks
    J

    PS will someone tell me why this thread's status is "very negative"?

  9. #9
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    Originally posted here by johnnymier
    PS will someone tell me why this thread's status is "very negative"?
    It's because AngelofRevenge was the receiver of sh*tloads of negative antipoints.
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  10. #10
    Senior Member
    Join Date
    Jul 2002
    Posts
    339
    and I dont have to worry about IP or ethernet MTU's, cool
    Read this if you're coding on Windows platform: UDP Datagram Can Be Silently Discarded if Larger than MTU.

    Peace always,
    <jdenny>
    Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
    I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •