Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added ipv4 configuration type
  • Loading branch information
Michael Brown committed Aug 11, 2006
1 parent 7029fb8 commit fe774fe
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/core/settings.c
Expand Up @@ -21,6 +21,8 @@
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <vsprintf.h>
#include <gpxe/in.h>
#include <gpxe/settings.h>

/** @file
Expand Down Expand Up @@ -195,3 +197,57 @@ struct config_setting_type config_setting_type_string __config_setting_type = {
.show = show_string,
.set = set_string,
};

/**
* Show value of IPv4 setting
*
* @v context Configuration context
* @v setting Configuration setting
* @v buf Buffer to contain value
* @v len Length of buffer
* @ret rc Return status code
*/
static int show_ipv4 ( struct config_context *context,
struct config_setting *setting,
char *buf, size_t len ) {
struct dhcp_option *option;
struct in_addr ipv4;

option = find_dhcp_option ( context->options, setting->tag );
if ( ! option )
return -ENOENT;
dhcp_ipv4_option ( option, &ipv4 );
snprintf ( buf, len, inet_ntoa ( ipv4 ) );
return 0;
}

/** Set value of IPV4 setting
*
* @v context Configuration context
* @v setting Configuration setting
* @v value Setting value (as a string)
* @ret rc Return status code
*/
static int set_ipv4 ( struct config_context *context,
struct config_setting *setting,
const char *value ) {
struct dhcp_option *option;
struct in_addr ipv4;
int rc;

if ( ( rc = inet_aton ( value, &ipv4 ) ) != 0 )
return rc;
option = set_dhcp_option ( context->options, setting->tag,
&ipv4, sizeof ( ipv4 ) );
if ( ! option )
return -ENOMEM;
return 0;
}

/** An IPv4 configuration setting */
struct config_setting_type config_setting_type_ipv4 __config_setting_type = {
.name = "ipv4",
.show = show_ipv4,
.set = set_ipv4,
};

0 comments on commit fe774fe

Please sign in to comment.