Carleton University - SYSC 2006
get_route_info()
Assignment 2 - Spring 2025The 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;costFor example:
nodeA;nodeC;nodeB;8
nodeB;nodeD;nodeC;7
nodeC;nodeA;nodeB;8Each 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:
File I/O:
Open the file using
fopen().
Input Parsing:
Use
fgets()to read each line.Use
sscanf()to extract the source, destination, next hop, and cost.
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.
Insert the Destination:
Create a new destination node (
dest_node_t).Fill in its values: destination name, next hop, cost.
Set
packets_sentandbytes_sentto 0.Use
insert_dest_front()to add it to the source node’s destination list.
Return:
Return
0on success.Return
1if the file could not be opened.
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.