CS43 Lab7 - A Router Stack  1.2019
sr_if.h
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------------
2  * file: sr_if.h
3  * date: Sun Oct 06 14:13:13 PDT 2002
4  * Contact: casado@stanford.edu
5  *---------------------------------------------------------------------------*/
6 
7 /** \file
8  * Data structures and methods for handeling interfaces
9  * */
10 
11 #ifndef sr_INTERFACE_H
12 #define sr_INTERFACE_H
13 
14 #ifdef _LINUX_
15 #include <stdint.h>
16 #endif /* _LINUX_ */
17 
18 #ifdef _SOLARIS_
19 #include </usr/include/sys/int_types.h>
20 #endif /* SOLARIS */
21 
22 #ifdef _DARWIN_
23 #include <inttypes.h>
24 #endif
25 
26 #include "sr_protocol.h"
27 
28 struct sr_instance;
29 
30 /* ----------------------------------------------------------------------------
31  * struct sr_if
32  *
33  * Node in the interface list for each router
34  *
35  * -------------------------------------------------------------------------- */
36 /** A node in the interface list of the router.
37  * The interface is stored as a linked list.*/
38 struct sr_if
39 {
40  char name[sr_IFACE_NAMELEN]; /**< The name of the interface*/
41  unsigned char addr[ETHER_ADDR_LEN]; /**< The MAC address of the interface */
42  uint32_t ip; /**< The IP address of the interface */
43  uint32_t speed;
44  struct sr_if* next; /**< The next interface in the linked list */
45 };
46 
47 /** Searches the interface list to find the interface with the given name.
48  *
49  * If no such interface exists, returns NULL.
50  * @param sr The router instance.
51  * @param name The name of the requested interface.
52  */
53 struct sr_if* sr_get_interface(struct sr_instance* sr, const char* name);
54 void sr_add_interface(struct sr_instance*, const char*);
55 void sr_set_ether_addr(struct sr_instance*, const unsigned char*);
56 void sr_set_ether_ip(struct sr_instance*, uint32_t ip_nbo);
57 
58 /** Prints the interface list*/
59 void sr_print_if_list(struct sr_instance*);
60 /** Prints the given interface*/
61 void sr_print_if(struct sr_if*);
62 
63 #endif /* -- sr_INTERFACE_H -- */
struct sr_if * next
The next interface in the linked list.
Definition: sr_if.h:44
char name[sr_IFACE_NAMELEN]
The name of the interface.
Definition: sr_if.h:40
struct sr_if * sr_get_interface(struct sr_instance *sr, const char *name)
Searches the interface list to find the interface with the given name.
Definition: sr_if.c:37
unsigned char addr[ETHER_ADDR_LEN]
The MAC address of the interface.
Definition: sr_if.h:41
uint32_t ip
The IP address of the interface.
Definition: sr_if.h:42
void sr_print_if(struct sr_if *)
Prints the given interface.
Definition: sr_if.c:180
A collection of macros, structs, and enums to represent packet types and headers. ...
A node in the interface list of the router.
Definition: sr_if.h:38
Struct which encapsulates all the state of a single router.
Definition: sr_router.h:59
void sr_print_if_list(struct sr_instance *)
Prints the interface list.
Definition: sr_if.c:151