struct refcnt refcnt;
/** List of network devices */
struct list_head list;
+ /** List of open network devices */
+ struct list_head open_list;
/** Name of this network device */
char name[8];
/** Underlying hardware device */
extern struct net_device * find_netdev ( const char *name );
extern struct net_device * find_netdev_by_location ( unsigned int bus_type,
unsigned int location );
+extern struct net_device * last_opened_netdev ( void );
extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
struct net_protocol *net_protocol, const void *ll_dest );
extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
/** List of network devices */
struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
+/** List of open network devices, in reverse order of opening */
+struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices );
+
/**
* Record network device statistic
*
/* Mark as opened */
netdev->state |= NETDEV_OPEN;
+
+ /* Add to head of open devices list */
+ list_add ( &netdev->open_list, &open_net_devices );
+
return 0;
}
/* Mark as closed */
netdev->state &= ~NETDEV_OPEN;
+
+ /* Remove from open devices list */
+ list_del ( &netdev->open_list );
}
/**
return NULL;
}
+/**
+ * Get most recently opened network device
+ *
+ * @ret netdev Most recently opened network device, or NULL
+ */
+struct net_device * last_opened_netdev ( void ) {
+ struct net_device *netdev;
+
+ list_for_each_entry ( netdev, &open_net_devices, open_list ) {
+ assert ( netdev->state & NETDEV_OPEN );
+ return netdev;
+ }
+
+ return NULL;
+}
+
/**
* Transmit network-layer packet
*