CJCoding With Joseph
15free / daySign inCreate account

Carleton University - SYSC 2006

get_route_info()

Assignment 2 - Spring 2025

The goal of get_route_info() is to read routing table entries from the file routeinfo.txt, and update each node’s routing table, which is stored as a linked list of destinations. Each line in the file follows this format:

source;destination;nextHop;cost

For example:

nodeA;nodeC;nodeB;8
nodeB;nodeD;nodeC;7
nodeC;nodeA;nodeB;8

Each line tells us: From source, to reach destination, send the packet first to nextHop with the given cost.


How do we do this?

To build the routing tables, you need to:

  1. File I/O:

    • Open the file using fopen().

  2. Input Parsing:

    • Use fgets() to read each line.

    • Use sscanf() to extract the source, destination, next hop, and cost.

  3. Find the Source Node:

    • Use find_node() to find the source node in the main node list.

    • If the node is not found, ignore that entry.

  4. Insert the Destination:

    • Create a new destination node (dest_node_t).

    • Fill in its values: destination name, next hop, cost.

    • Set packets_sent and bytes_sent to 0.

    • Use insert_dest_front() to add it to the source node’s destination list.

  5. Return:

    • Return 0 on success.

    • Return 1 if the file could not be opened.

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.