mirror of
https://github.com/hufrea/byedpi.git
synced 2024-11-21 22:45:23 +03:00
parent
a6c5173d9c
commit
8ad4c22b30
1 changed files with 23 additions and 0 deletions
23
main.c
23
main.c
|
@ -242,17 +242,39 @@ char *ftob(const char *str, ssize_t *sl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline int lower_char(char *cl)
|
||||||
|
{
|
||||||
|
char c = *cl;
|
||||||
|
if (c < 'A') {
|
||||||
|
if (c > '9' || c < '-')
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (c < 'a') {
|
||||||
|
if (c > 'Z')
|
||||||
|
return -1;
|
||||||
|
*cl = c + 32;
|
||||||
|
}
|
||||||
|
else if (c > 'z')
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct mphdr *parse_hosts(char *buffer, size_t size)
|
struct mphdr *parse_hosts(char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
struct mphdr *hdr = mem_pool(1);
|
struct mphdr *hdr = mem_pool(1);
|
||||||
if (!hdr) {
|
if (!hdr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
size_t num = 0;
|
||||||
char *end = buffer + size;
|
char *end = buffer + size;
|
||||||
char *e = buffer, *s = buffer;
|
char *e = buffer, *s = buffer;
|
||||||
|
|
||||||
for (; e <= end; e++) {
|
for (; e <= end; e++) {
|
||||||
if (e != end && *e != ' ' && *e != '\n' && *e != '\r') {
|
if (e != end && *e != ' ' && *e != '\n' && *e != '\r') {
|
||||||
|
if (lower_char(e)) {
|
||||||
|
LOG(LOG_E, "invalid host: num: %zd (%.*s)\n", num + 1, (int )(e - s + 1), s);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (s == e) {
|
if (s == e) {
|
||||||
|
@ -263,6 +285,7 @@ struct mphdr *parse_hosts(char *buffer, size_t size)
|
||||||
free(hdr);
|
free(hdr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
num++;
|
||||||
s = e + 1;
|
s = e + 1;
|
||||||
}
|
}
|
||||||
return hdr;
|
return hdr;
|
||||||
|
|
Loading…
Reference in a new issue