diff -u -r arpwatch-2.1a13-NEW/db.c arpwatch-2.1a13-NEW-DB/db.c --- arpwatch-2.1a13-NEW/db.c Mon Jul 25 10:48:03 2005 +++ arpwatch-2.1a13-NEW-DB/db.c Thu Jul 6 13:10:59 2006 @@ -116,6 +116,25 @@ } } + if( do_once == 0) { + ainfo_special.elist = + (struct einfo **)malloc(sizeof(ainfo_special.elist[0])); + if (ainfo_special.elist == NULL) { + syslog(LOG_ERR, "ainfo_special malloc: %m"); + exit(1); + } + ainfo_special.elist[0] = &einfo_special; + do_once = 1; + } + + /* Quick dump of this new record */ + ainfo_special.a = ap->a; + ainfo_special.ecount = 1; + BCOPY(e, einfo_special.e, 6); + einfo_special.t = t; + if(!initializing) + dumpupdate(); + /* Check for a virgin ainfo record */ if (ap->ecount == 0) { ap->ecount = 1; @@ -179,22 +198,8 @@ ap->elist[0] = elist_alloc(a, e, t, tprev, h); ++ap->ecount; #endif - if( do_once == 0) { - ainfo_special.elist = - (struct einfo **)malloc(sizeof(ainfo_special.elist[0])); - if (ainfo_special.elist == NULL) { - syslog(LOG_ERR, "ainfo_special malloc: %m"); - exit(1); - } - ainfo_special.elist[0] = &einfo_special; - do_once = 1; - } - /* log changes to IP->ethernet mappings, keep only most current */ - ainfo_special.a = ap->a; - ainfo_special.ecount = 1; BCOPY(ap->elist[0], ainfo_special.elist[0], sizeof(struct einfo)); - ep = ap->elist[0]; BCOPY(e, ep->e, 6); if (h == NULL && !initializing) diff -u -r arpwatch-2.1a13-NEW/util.c arpwatch-2.1a13-NEW-DB/util.c --- arpwatch-2.1a13-NEW/util.c Mon Jul 25 10:53:02 2005 +++ arpwatch-2.1a13-NEW-DB/util.c Thu Jul 6 12:46:13 2006 @@ -107,6 +107,21 @@ (void)putc('\n', dumpf); } +void +dumponeshort(register u_int32_t a, register u_char *e, time_t t, time_t tprev, + register char *h) +{ + char s[256]; + time_t t2 = t; + + (void)fprintf(dumpf, "%s\t%s", e2str(e), intoa(a)); + if (t2 == 0) + t2 = time(NULL); + strftime(s,256,"%Y/%m/%d-%T",localtime(&t2)) ; + (void)fprintf(dumpf, "\t%s", s) ; + (void)putc('\n', dumpf); +} + int dump(void) { @@ -166,6 +181,39 @@ (void)ent_getspecial(dumpone); if (ferror(dumpf)) { syslog(LOG_ERR, "ferror %s: %m", arpfilechange); + set_can_checkpoint(1); + return(0); + } + + (void)fclose(dumpf); + set_can_checkpoint(1); + + return(1); +} + +int +dumpupdate(void) +{ + register int fd; + char arpfileupdate[256]; + + set_can_checkpoint(0); /* dumpf would get overwritten */ + (void)sprintf(arpfileupdate, "%s.updates", arpfile); + + if ((fd = open(arpfileupdate, O_WRONLY | O_CREAT, 0644)) < 0) { + syslog(LOG_ERR, "open(%s): %m", arpfileupdate); + set_can_checkpoint(1); + return(0); + } + if ((dumpf = fdopen(fd, "a")) == NULL) { + syslog(LOG_ERR, "fdopen(%s): %m", arpfileupdate); + set_can_checkpoint(1); + return(0); + } + + (void)ent_getspecial(dumponeshort); + if (ferror(dumpf)) { + syslog(LOG_ERR, "ferror %s: %m", arpfileupdate); set_can_checkpoint(1); return(0); }