Newsgroups: comp.sources.unix From: rogers@amadeus.wr.tek.com (Roger S. Southwick) Subject: v26i293: hostcvt - convert /etc/hosts files into DNS zone files, Patch03 Sender: unix-sources-moderator@gw.home.vix.com Approved: vixie@gw.home.vix.com Submitted-By: rogers@amadeus.wr.tek.com (Roger S. Southwick) Posting-Number: Volume 26, Issue 293 Archive-Name: hostcvt/patch03 This is Official patch #3 for the hostcvt program (v25i093). This patch adds a -d flag which deletes (ignores) any duplicate IP addresses found in the input host file. Feed this to the stdin of Larry Wall's fine patch program (I've tested with patch version 2.0.1.6 Patch level: 12) and enjoy the results. -Roger (Roger.S.Southwick@tek.com) UUCP: ...!uunet!tektronix!Roger.S.Southwick Index: main.c Prereq: 1.8 11c11 < static char *RCSid = "$Id: main.c,v 1.8 92/03/24 17:46:28 rogers Release $"; --- > static char *RCSid = "$Id: main.c,v 1.10 93/07/07 15:21:02 rogers Release $"; 26a27 > char *h_ip; 63c64 < int domainflag, kflag, Sflag; --- > int domainflag, kflag, Sflag, dflag; 66c67 < errflag = outputflag = domainflag = 0; --- > errflag = outputflag = domainflag = dflag = 0; 70c71 < while ((ch = egetopt(argc, argv, "Skh:n:o:s:")) != -1) --- > while ((ch = egetopt(argc, argv, "dSkh:n:o:s:")) != -1) 111a113,116 > case 'd': /* Delete duplicate IP addresses */ > dflag++; > break; > 138c143 < (void) fprintf(stderr, "usage: hostcvt [-k] [-S] [-h hostsfile] [-n netlistfile]\n\t\t[-s soabasefile] [-o outputfile] domain\n"); --- > (void) fprintf(stderr, "usage: hostcvt [-d] [-k] [-S] [-h hostsfile] [-n netlistfile]\n\t\t[-s soabasefile] [-o outputfile] domain\n"); 180a186,191 > > if(dflag && dupip(ipaddr)){ > (void)fprintf(stderr, "hostcvt: duplicated IP address (%s) ignored\n", ipaddr); > continue; > } > 206c217 < savehp(hp); --- > savehp(hp, ipaddr); 228a240,261 > * Look thru our list of already known hosts by IP address, > * and return TRUE if it's already known. > */ > > int > dupip(ipaddr) > char *ipaddr; > { > register hn_tp hp; > u_long ip; > > for(ip = inet_addr(ipaddr), hp = hntop; hp != NULL; hp = hp->h_next) { > if(inet_addr(hp->h_ip) == ip){ > return(1); > } > } > return(0); > } > > > > /* 297c330 < savehp(hp) --- > savehp(hp, ipaddr) 298a332 > char *ipaddr; 310a345 > np->h_ip = strsave(ipaddr); Index: hostcvt.8 Prereq: 1.5 2c2 < .\" $Id: hostcvt.8,v 1.5 92/03/24 17:40:29 rogers Release $ --- > .\" $Id: hostcvt.8,v 1.7 93/07/07 15:23:09 rogers Release $ 4c4 < .TH HOSTCVT 8 "03-24-92" --- > .TH HOSTCVT 8 "07-07-93" 13a14,15 > .I -d > ] [ 66a69,71 > .TP > .BI \-d > Delete (ignore) any duplicated IP addresses in the input file.