you are to write a TCP/IP server that can build up a graph of a network of networks (using the supplied graph library and implementation of Dijkstra’s algorithm) and then query that graph to find out which link between two networks should be used as the next hop to send a packet of data from one network to another within the network of networks (using the supplied implementation of Dijkstra’s algorithm).

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 21SA
icon
Related questions
Question

C PROGRAMMING.

you are to write a TCP/IP server that can build up a graph of a network of
networks (using the supplied graph library and implementation of Dijkstra’s algorithm) and then
query that graph to find out which link between two networks should be used as the next hop to
send a packet of data from one network to another within the network of networks (using the
supplied implementation of Dijkstra’s algorithm).

using the following program as a start point:

/*
 *  NetworkServer.c
 *  ProgrammingPortfolio Skeleton
 *
 */

/* You will need to include these header files to be able to implement the TCP/IP functions */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>

/* You will also need to add #include for your graph library header files */

int main(int argc, const char * argv[])
{
    int serverSocket = -1;
    
    printf("Programming Portfolio 2022 Implementation\n");
    printf("=========================================\n\n");
    
    /* Insert your code here to create, and the TCP/IP socket for the Network Server
     *
     * Then once a connection has been accepted implement protocol described in the coursework description.
     */
    
    
    
    return 0;
}

h graph.h 1.16 KB
1 #ifndef _GRAPH_H
#define _GRAPH_H
2
3
4 #include "linked_list.h"
5
6
7
8
9
/* each node in the adjacency List stores a vertex */
10 /* a vertex has a unique numerical id */
11
11
12
12
17
13
14
15
16
17
18
LO
19
20
21
4
22
23
24
47
25
4
26
20
27
28
co
29
SO
30
24
34
25
35
36
27
37
20
39
40
40
/* a graph represented as an adjacency List /
typedef LinkedList Graph;
41
41
42
43
T
/* and stores a list of edges from the vertex ³/
typedef struct Vertex {
int id;
LinkedList "edges;
MA
31
32
33 void add_edge_undirected (Graph *, int, int, double);
void remove_edge (Graph *, int, int);
void remove_edges (Graph *, int);
48
19
49
50
} vertex;
/* each node in the list of edges for a vertex store the edge weight */
/* and the destination vertex 3/
typedef struct Edge {
double weight;
Vertex *vertex;
} Edge;
/* function prototypes */
Vertex *init_vertex(int);
20
38 void free_vertex (Vertex *);
Graph *init_graph (void);
void free_graph (Graph *);
void print_graph (Graph *);
Vertex *find_vertex (Graph *, int);
vertex *add_vertex (Graph *, int);
void remove_vertex (Graph *, int);
Edge *add_edge (Graph *, int, int, double);
Edge *init_edge (void);
void free_edge (Edge *);
int *get_vertices (Graph *, int *);
Edge **get_edges (Graph *, Vertex *, int *);
44
44
45 Edge *get_edge (Graph *, int, int);
46 int edge_destination (Edge *);
47
double edge_weight (Edge *);
#endif
Open in Web IDE
v
Replace Delete GOJ
Transcribed Image Text:h graph.h 1.16 KB 1 #ifndef _GRAPH_H #define _GRAPH_H 2 3 4 #include "linked_list.h" 5 6 7 8 9 /* each node in the adjacency List stores a vertex */ 10 /* a vertex has a unique numerical id */ 11 11 12 12 17 13 14 15 16 17 18 LO 19 20 21 4 22 23 24 47 25 4 26 20 27 28 co 29 SO 30 24 34 25 35 36 27 37 20 39 40 40 /* a graph represented as an adjacency List / typedef LinkedList Graph; 41 41 42 43 T /* and stores a list of edges from the vertex ³/ typedef struct Vertex { int id; LinkedList "edges; MA 31 32 33 void add_edge_undirected (Graph *, int, int, double); void remove_edge (Graph *, int, int); void remove_edges (Graph *, int); 48 19 49 50 } vertex; /* each node in the list of edges for a vertex store the edge weight */ /* and the destination vertex 3/ typedef struct Edge { double weight; Vertex *vertex; } Edge; /* function prototypes */ Vertex *init_vertex(int); 20 38 void free_vertex (Vertex *); Graph *init_graph (void); void free_graph (Graph *); void print_graph (Graph *); Vertex *find_vertex (Graph *, int); vertex *add_vertex (Graph *, int); void remove_vertex (Graph *, int); Edge *add_edge (Graph *, int, int, double); Edge *init_edge (void); void free_edge (Edge *); int *get_vertices (Graph *, int *); Edge **get_edges (Graph *, Vertex *, int *); 44 44 45 Edge *get_edge (Graph *, int, int); 46 int edge_destination (Edge *); 47 double edge_weight (Edge *); #endif Open in Web IDE v Replace Delete GOJ
h dijkstra.h379 bytes
1
2
3
4
5
6
*
*
*
*/
dijkstras.h
Programming Portfolio
7
#ifndef dijkstra_h
8 #define dijkstra_h
9
10
/* an entry storing the shortest path */
11
/* next_hop is the next vertex in the path */
12
/* weight is the total weight of the path to dst */
13 typedef struct Path
14
{
15
16
17
18
19
20 Path *dijkstra (Graph *graph, int id, int *pnEntries);
21
22 #endif /* dijkstras_h */
23
int next_hop;
double weight;
} Path;
Open in Web IDE
V
Replace
Delete
G
Transcribed Image Text:h dijkstra.h379 bytes 1 2 3 4 5 6 * * * */ dijkstras.h Programming Portfolio 7 #ifndef dijkstra_h 8 #define dijkstra_h 9 10 /* an entry storing the shortest path */ 11 /* next_hop is the next vertex in the path */ 12 /* weight is the total weight of the path to dst */ 13 typedef struct Path 14 { 15 16 17 18 19 20 Path *dijkstra (Graph *graph, int id, int *pnEntries); 21 22 #endif /* dijkstras_h */ 23 int next_hop; double weight; } Path; Open in Web IDE V Replace Delete G
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Properties of Different Architectures
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning