Carleton University - SYSC 2006
packet_gen()
Assignment 1 - Spring 2025The goal of packet_gen() is to randomly generate a data packet that includes a source node, destination node, and packet size. The format of the packet is: src;dest;size. For example, the it might look like this:
nodeA;nodeC;928This string means: Send a packet from nodeA to nodeC, and the packet size is 928 bytes.
How do we do this?
To generate a packet in this format, you need to:
Random Number Generation:
Use
rand()to pick a random source and destination node.Ensure the source and destination are not the same.
Generate a random size between 100 and 1500 bytes.
Format the Packet String:
Use
sprintf()to combine the source node name, destination node name, and size into a single string, separated by semicolons.
Return:
Return
0for success.
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 25 more lessons in Carleton University - SYSC 2006.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.