CJCoding With Joseph
15free / daySign inCreate account

Carleton University - SYSC 2006

packet_gen()

Assignment 2 - Spring 2025

he goal of packet_gen() is to randomly generate a data packet in the format:

source;destination;size

For example:

nodeB;nodeD;734

This means: create a packet that starts from nodeB, is going to nodeD, and is 734 bytes in size.

We’ll randomly pick both the source and destination nodes from the linked list, and also randomly pick a size between 100 and 1500 bytes.


How do we do this?

To generate the packet string, you need to:

  1. Random Selection:

    • Pick two different nodes (source and destination) randomly from the linked list.

    • Make sure they are not the same node.

  2. Packet Size:

    • Generate a random number between 100 and 1500, inclusive.

  3. Formatting:

    • Use sprintf() to format the string as src;dest;size.

  4. Return:

    • Return 0 on success.

Members only

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.