Commit e126bd1c authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Check invalid source entries when creating a new source.

parent a5ef363d
...@@ -35,7 +35,9 @@ struct source * ...@@ -35,7 +35,9 @@ struct source *
find_source(const unsigned char *a, const unsigned char *p, unsigned char plen, find_source(const unsigned char *a, const unsigned char *p, unsigned char plen,
int create, unsigned short seqno) int create, unsigned short seqno)
{ {
struct source *src;
int i; int i;
for(i = 0; i < numsrcs; i++) { for(i = 0; i < numsrcs; i++) {
if(!srcs[i].valid) if(!srcs[i].valid)
continue; continue;
...@@ -52,18 +54,31 @@ find_source(const unsigned char *a, const unsigned char *p, unsigned char plen, ...@@ -52,18 +54,31 @@ find_source(const unsigned char *a, const unsigned char *p, unsigned char plen,
if(!create) if(!create)
return NULL; return NULL;
if(numsrcs >= MAXSRCS) { src = NULL;
fprintf(stderr, "Too many sources.\n");
return NULL; for(i = 0; i < numsrcs; i++) {
if(srcs[i].valid == 0) {
src = &srcs[i];
break;
}
} }
srcs[numsrcs].valid = 1;
memcpy(srcs[numsrcs].address, a, 16); if(!src) {
memcpy(srcs[numsrcs].prefix, p, 16); if(numsrcs >= MAXSRCS) {
srcs[numsrcs].plen = plen; fprintf(stderr, "Too many sources.\n");
srcs[numsrcs].seqno = seqno; return NULL;
srcs[numsrcs].metric = INFINITY; }
srcs[numsrcs].time = now.tv_sec; src = &srcs[numsrcs++];
return &srcs[numsrcs++]; }
src->valid = 1;
memcpy(src->address, a, 16);
memcpy(src->prefix, p, 16);
src->plen = plen;
src->seqno = seqno;
src->metric = INFINITY;
src->time = now.tv_sec;
return src;
} }
struct source * struct source *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment