📄 xsupconfig_devices.c
字号:
/**
*
* Licensed under a dual GPL/BSD license. (See LICENSE file for more info.)
*
* \file xsupconfig_devices.c
*
* \author chris@open1x.org
*
* $Id: xsupconfig_devices.c,v 1.1.2.14 2008/01/21 22:51:44 chessing Exp $
* $Date: 2008/01/21 22:51:44 $
**/
#include <stdio.h>
#include <stdlib.h>
#ifndef WINDOWS
#include <stdint.h>
#endif
#include "xsupconfig_structs.h"
#include "../../src/xsup_common.h"
#include "../../src/xsup_debug.h"
#include "xsupconfig_devices.h"
#include "xsupconfig.h"
#include "xsupconfig_vars.h"
/**
* \brief Initialize the devices structure so that it can be populated.
*
* Make sure that if we have any memory already allocated for the devices
* structure that we free it. When this function terminates, we should have
* a clean slate to work on.
**/
void xsupconfig_devices_init()
{
debug_printf(DEBUG_INIT, "Init devices structure.\n");
// If there is already something in memory, clean it up.
if (conf_devices != NULL)
{
xsupconfig_devices_deinit(&conf_devices);
}
}
/**
* \brief Clean up the interfaces list in memory.
*
* Clean out the "interfaces" sub-structure in the devices structure.
* All memory for each record should be freed here, and ->next should
* be set to NULL.
*
* @param[in] ints A pointer to the head of the list that contains the
* interfaces we want to free.
**/
void xsupconfig_devices_clear_interfaces(struct xsup_interfaces *ints)
{
struct xsup_interfaces *cur, *next;
debug_printf(DEBUG_DEINIT, "Clearing out interfaces from devices structure.\n");
if (ints == NULL) return; // Nothing to do.
cur = ints;
while (cur != NULL)
{
next = cur->next;
FREE(cur->description);
FREE(cur->driver_type);
FREE(cur->default_connection);
cur->next = NULL;
cur = next;
}
}
/**
* \brief Free the memory that is used to store the devices
* structure in memory.
*
* Go through all of the elements in xsup_devs and free
* any memory that was allocated.
*
* @param[in] xsup_devs The pointer to the head of the devices structure
* that we need to free.
**/
void xsupconfig_devices_deinit(struct xsup_devices **xsup_devs)
{
debug_printf(DEBUG_INIT, "Clearing out devices structure.\n");
if ((*xsup_devs) == NULL) return;
// Clear out any interfaces that we may have allocated.
xsupconfig_devices_clear_interfaces((*xsup_devs)->interf);
(*xsup_devs)->interf = NULL;
free((*xsup_devs));
(*xsup_devs) = NULL;
}
/**
* \brief Dump all information about interfaces we know about.
*
* @param[in] data A pointer to the head of the interfaces structure
* that we want to dump to the screen/log file.
**/
void xsupconfig_devices_dump_interfaces(struct xsup_interfaces *data)
{
struct xsup_interfaces *cur;
uint8_t i;
cur = data;
while (cur != NULL)
{
printf("\t---------- Interface -------------\n");
printf("\tDescription : %s\n", cur->description);
printf("\tMAC Address : ");
for (i=0; i<6; i++)
{
printf("%02X", cur->mac[i]);
if (i != 5) printf(":");
}
printf("\n");
printf("\tDriver Type : %s\n", cur->driver_type);
printf("\t----------------------------------\n");
cur = cur->next;
}
}
/**
* \brief Dump all information that we know about devices in our structure.
*
* @param[in] data A pointer to the devices structure that we want to dump all
* of the information for.
**/
void xsupconfig_devices_dump(struct xsup_devices *data)
{
if (data == NULL) return;
xsupconfig_devices_dump_interfaces(data->interf);
}
/**
* \brief Return a pointer to the interfaces component of the devices structure.
*
* \retval NULL if no interfaces exist in the list, or on error
* \retval ptr to the head of the interfaces list.
**/
struct xsup_interfaces *xsupconfig_devices_get_interfaces()
{
if (conf_devices == NULL)
{
printf("No devices found in the configuration!\n");
return NULL;
}
return conf_devices->interf;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -