From 313f71b25817a54832ac2ab46efcee2f5ab30331 Mon Sep 17 00:00:00 2001 From: Paul Nasrat Date: Tue, 15 May 2007 14:25:55 +0100 Subject: [PATCH] This part creates the cfg_set_default_by_mac() function. This function sets the default cf_option if there is an image label if the same MAC address of the machine is netbooting. Signed-off-by: Paulo Ricardo Paz Vital --- include/cfg.h | 1 + second/cfg.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/cfg.h b/include/cfg.h index be34e0f..1053f9a 100644 --- a/include/cfg.h +++ b/include/cfg.h @@ -28,5 +28,6 @@ extern char* cfg_get_strg(char *image, char *item); extern int cfg_get_flag(char *image, char *item); extern void cfg_print_images(void); extern char* cfg_get_default(void); +extern char* cfg_set_default_by_mac(char *mac_addr); #endif diff --git a/second/cfg.c b/second/cfg.c index d7f4084..fe3f1e1 100644 --- a/second/cfg.c +++ b/second/cfg.c @@ -585,6 +585,43 @@ char *cfg_get_default (void) return ret; } +/* + * cfg_set_default_by_mac () + * return 1 if the default cf_option was changed to label with the MAC addr + * return 0 if not changed + */ +int cfg_set_default_by_mac (char *mac_addr) +{ + CONFIG *walk; + struct IMAGES *tmp; + char * label = NULL; + int haslabel = 0; + + /* check if there is an image label equal to mac_addr */ + for (tmp = images; tmp; tmp = tmp->next) { + label = cfg_get_strg_i (tmp->table, "label"); + if (!strcmp(label,mac_addr)){ + haslabel = 1; + } + } + + if (!haslabel) + return 0; + else { + /* + * if there is an image label equal to mac_addr, change the default + * cf_options to this image label + */ + for (walk = cf_options; walk->type != cft_end; walk++) { + if (!strcasecmp(walk->name,"default")) { + walk->data = mac_addr; + return 1; + } + } + return 0; + } +} + /* * Local variables: * c-file-style: "k&r" -- 2.39.2