mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-18 00:37:01 +00:00
getdata: skip strings before nth_field analysis
This will allow nth_field function to begin from first field, and stop immediately when it ends, which makes function much more simple and quite a bit quicker. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
b918e9157d
commit
4341d92d41
2 changed files with 12 additions and 30 deletions
|
|
@ -157,8 +157,8 @@ int prepare_memory(void);
|
||||||
int parse_leases(void);
|
int parse_leases(void);
|
||||||
void parse_config(int, const char *__restrict, struct shared_network_t *__restrict)
|
void parse_config(int, const char *__restrict, struct shared_network_t *__restrict)
|
||||||
__attribute__ ((nonnull(2, 3)));
|
__attribute__ ((nonnull(2, 3)));
|
||||||
int nth_field(int n, char *__restrict dest, const char *__restrict src)
|
void nth_field(char *__restrict dest, const char *__restrict src)
|
||||||
__attribute__ ((nonnull(2, 3)))
|
__attribute__ ((nonnull(1, 2)))
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||||
__attribute__ ((__hot__))
|
__attribute__ ((__hot__))
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -112,8 +112,8 @@ int parse_leases(void)
|
||||||
}
|
}
|
||||||
/* It's a lease, save IP */
|
/* It's a lease, save IP */
|
||||||
if (xstrstr(line, "lease", 5)) {
|
if (xstrstr(line, "lease", 5)) {
|
||||||
strncpy(ipstring, line, MAXLEN);
|
memcpy(ipstring, line + 6, 16);
|
||||||
nth_field(2, ipstring, ipstring);
|
nth_field(ipstring, ipstring);
|
||||||
inet_aton(ipstring, &inp);
|
inet_aton(ipstring, &inp);
|
||||||
sw_active_lease = 0;
|
sw_active_lease = 0;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -147,7 +147,7 @@ int parse_leases(void)
|
||||||
if ((macaddr != NULL)
|
if ((macaddr != NULL)
|
||||||
&& (sw_active_lease == 1)
|
&& (sw_active_lease == 1)
|
||||||
&& (xstrstr(line, " hardware ethernet", 19))) {
|
&& (xstrstr(line, " hardware ethernet", 19))) {
|
||||||
nth_field(3, macstring, line);
|
nth_field(macstring, line + 20);
|
||||||
if (macstring) {
|
if (macstring) {
|
||||||
macstring[17] = '\0';
|
macstring[17] = '\0';
|
||||||
macaddr_p->ethernet = xstrdup(macstring);
|
macaddr_p->ethernet = xstrdup(macstring);
|
||||||
|
|
@ -168,36 +168,18 @@ int parse_leases(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Like strcpy but for field which is separated by white spaces. Number of
|
/* Like strcpy but for field which is separated by white spaces. */
|
||||||
* first field is 1 and not 0 like C programs should have. Question of
|
void nth_field(char *restrict dest, const char *restrict src)
|
||||||
* semantics, send mail to author if this annoys. All performance boosts for
|
|
||||||
* this function are well come. */
|
|
||||||
int nth_field(int n, char *restrict dest, const char *restrict src)
|
|
||||||
{
|
{
|
||||||
int i, j = 0, wordn = 0, len;
|
size_t i, len;
|
||||||
|
|
||||||
len = strlen(src);
|
len = strlen(src);
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (isspace(src[i])) {
|
dest[i] = src[i];
|
||||||
if (!(wordn < n)) {
|
if (src[i] == ' ' || dest[i] == '\0') {
|
||||||
dest[j] = '\0';
|
dest[i] = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
j = 0;
|
|
||||||
} else {
|
|
||||||
if (j == 0) {
|
|
||||||
wordn++;
|
|
||||||
if (n + 1 < wordn)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (wordn == n) {
|
|
||||||
dest[j] = src[i];
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dhcpd.conf interesting words */
|
/* dhcpd.conf interesting words */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue