more configdata
This commit is contained in:
parent
f88f369fa6
commit
a15af2d522
@ -22,6 +22,11 @@ int main(int argc, char *argv[])
|
||||
config_patch(config->data, CFG_DEFAULTGW, "10.10.250.250");
|
||||
config_patch(config->data, CFG_NAMESERVER, "10.10.0.1");
|
||||
|
||||
config_patch(config->data, CFG_MACAGEING, "301");
|
||||
|
||||
config_patch(config->data, CFG_PORTNAME_MASK + 1, "PORT-001");
|
||||
config_patch(config->data, CFG_PORTNAME_MASK + 2, "PORT-002");
|
||||
|
||||
put_filedata(argv[2], config);
|
||||
|
||||
free(config);
|
||||
|
37
configdata.c
37
configdata.c
@ -27,6 +27,16 @@ static int patch_8bit(void *config, struct cfg_patch *patch, int code, const cha
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int patch_16bit(void *config, struct cfg_patch *patch, int code, const char *parameter)
|
||||
{
|
||||
int value = atoi(parameter);
|
||||
if (value < patch->min || value > patch->max)
|
||||
return -1;
|
||||
|
||||
*((uint16_t *)(config + patch->offset)) = htons(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int patch_string(void *config, struct cfg_patch *patch, int code, const char *parameter)
|
||||
{
|
||||
strncpy(config + patch->offset, parameter, patch->size);
|
||||
@ -38,6 +48,16 @@ static int patch_ip(void *config, struct cfg_patch *patch, int code, const char
|
||||
return (inet_pton(AF_INET, parameter, config + patch->offset) <= 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
static int patch_portname(void *config, struct cfg_patch *patch, int code, const char *parameter)
|
||||
{
|
||||
int num = code - patch->code;
|
||||
if (num < patch->min || num > patch->max)
|
||||
return -1;
|
||||
|
||||
strncpy(config + patch->offset + (num -1) * 0x70, parameter, patch->size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct cfg_patch patcharr[] = {{
|
||||
.code = CFG_LOCATION,
|
||||
.patch = patch_string,
|
||||
@ -65,12 +85,23 @@ static struct cfg_patch patcharr[] = {{
|
||||
.code = CFG_NETMASK,
|
||||
.patch = patch_8bit,
|
||||
.offset = 0x2dfe,
|
||||
.min = 0x00,
|
||||
.max = 0x20,
|
||||
.min = 0x00, .max = 0x20,
|
||||
}, {
|
||||
.code = CFG_NAMESERVER,
|
||||
.patch = patch_ip,
|
||||
.offset = 0x32dc,
|
||||
}, {
|
||||
.code = CFG_MACAGEING,
|
||||
.patch = patch_16bit,
|
||||
.offset = 0x53e8,
|
||||
.min = 0, .max = 0xFFFF,
|
||||
}, {
|
||||
.code = CFG_PORTNAME_MASK,
|
||||
.mask = 0xFFFFFFE0,
|
||||
.patch = patch_portname,
|
||||
.offset = 0x336c,
|
||||
.size = 8,
|
||||
.min = 1, .max = 26,
|
||||
}};
|
||||
|
||||
int config_patch(void *config, int code, const char *parameter)
|
||||
@ -79,7 +110,7 @@ int config_patch(void *config, int code, const char *parameter)
|
||||
for (i = 0; i < (sizeof(patcharr) / sizeof(struct cfg_patch)); i++) {
|
||||
int mask = (patcharr[i].mask != 0) ? patcharr[i].mask : ~0;
|
||||
|
||||
if ((patcharr[i].code & mask) == code)
|
||||
if ((code & mask) == patcharr[i].code)
|
||||
return patcharr[i].patch(config, &patcharr[i], code, parameter);
|
||||
}
|
||||
return -1;
|
||||
|
@ -5,10 +5,15 @@ enum {
|
||||
CFG_LOCATION = 0x0001,
|
||||
CFG_SYSNAME,
|
||||
CFG_CONTACT,
|
||||
|
||||
CFG_DEFAULTGW,
|
||||
CFG_IPADDRESS,
|
||||
CFG_NETMASK,
|
||||
CFG_NAMESERVER,
|
||||
|
||||
CFG_MACAGEING,
|
||||
|
||||
CFG_PORTNAME_MASK = 0x0100, // next 0x0120
|
||||
};
|
||||
|
||||
int config_patch(void *config, int code, const char *parameter);
|
||||
|
Loading…
Reference in New Issue
Block a user