ndp.c (259176) | ndp.c (265778) |
---|---|
1/* $FreeBSD: head/usr.sbin/ndp/ndp.c 259176 2013-12-10 14:17:07Z ae $ */ | 1/* $FreeBSD: head/usr.sbin/ndp/ndp.c 265778 2014-05-09 14:24:02Z melifaro $ */ |
2/* $KAME: ndp.c,v 1.104 2003/06/27 07:48:39 itojun Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 82 unchanged lines hidden (view full) --- 92#include <netinet/if_ether.h> 93 94#include <netinet/icmp6.h> 95#include <netinet6/in6_var.h> 96#include <netinet6/nd6.h> 97 98#include <arpa/inet.h> 99 | 2/* $KAME: ndp.c,v 1.104 2003/06/27 07:48:39 itojun Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 82 unchanged lines hidden (view full) --- 92#include <netinet/if_ether.h> 93 94#include <netinet/icmp6.h> 95#include <netinet6/in6_var.h> 96#include <netinet6/nd6.h> 97 98#include <arpa/inet.h> 99 |
100#include <ctype.h> |
|
100#include <netdb.h> 101#include <errno.h> 102#include <nlist.h> 103#include <stdio.h> 104#include <string.h> 105#include <paths.h> 106#include <err.h> 107#include <stdlib.h> --- 13 unchanged lines hidden (view full) --- 121static int s = -1; 122static int repeat = 0; 123 124char ntop_buf[INET6_ADDRSTRLEN]; /* inet_ntop() */ 125char host_buf[NI_MAXHOST]; /* getnameinfo() */ 126char ifix_buf[IFNAMSIZ]; /* if_indextoname() */ 127 128int main(int, char **); | 101#include <netdb.h> 102#include <errno.h> 103#include <nlist.h> 104#include <stdio.h> 105#include <string.h> 106#include <paths.h> 107#include <err.h> 108#include <stdlib.h> --- 13 unchanged lines hidden (view full) --- 122static int s = -1; 123static int repeat = 0; 124 125char ntop_buf[INET6_ADDRSTRLEN]; /* inet_ntop() */ 126char host_buf[NI_MAXHOST]; /* getnameinfo() */ 127char ifix_buf[IFNAMSIZ]; /* if_indextoname() */ 128 129int main(int, char **); |
129int file(char *); | 130static int file(char *); |
130void getsocket(void); 131int set(int, char **); 132void get(char *); 133int delete(char *); 134void dump(struct sockaddr_in6 *, int); 135static struct in6_nbrinfo *getnbrinfo(struct in6_addr *, int, int); 136static char *ether_str(struct sockaddr_dl *); 137int ndp_ether_aton(char *, u_char *); --- 46 unchanged lines hidden (view full) --- 184 usage(); 185 /*NOTREACHED*/ 186 } 187 mode = ch; 188 arg = NULL; 189 break; 190 case 'd': 191 case 'f': | 131void getsocket(void); 132int set(int, char **); 133void get(char *); 134int delete(char *); 135void dump(struct sockaddr_in6 *, int); 136static struct in6_nbrinfo *getnbrinfo(struct in6_addr *, int, int); 137static char *ether_str(struct sockaddr_dl *); 138int ndp_ether_aton(char *, u_char *); --- 46 unchanged lines hidden (view full) --- 185 usage(); 186 /*NOTREACHED*/ 187 } 188 mode = ch; 189 arg = NULL; 190 break; 191 case 'd': 192 case 'f': |
192 case 'i' : | 193 exit(file(optarg) ? 1 : 0); 194 case 'i': |
193 if (mode) { 194 usage(); 195 /*NOTREACHED*/ 196 } 197 mode = ch; 198 arg = optarg; 199 break; 200 case 'n': --- 106 unchanged lines hidden (view full) --- 307 break; 308 } 309 exit(0); 310} 311 312/* 313 * Process a file to set standard ndp entries 314 */ | 195 if (mode) { 196 usage(); 197 /*NOTREACHED*/ 198 } 199 mode = ch; 200 arg = optarg; 201 break; 202 case 'n': --- 106 unchanged lines hidden (view full) --- 309 break; 310 } 311 exit(0); 312} 313 314/* 315 * Process a file to set standard ndp entries 316 */ |
315int | 317static int |
316file(char *name) 317{ 318 FILE *fp; 319 int i, retval; | 318file(char *name) 319{ 320 FILE *fp; 321 int i, retval; |
320 char line[100], arg[5][50], *args[5]; | 322 char line[100], arg[5][50], *args[5], *p; |
321 | 323 |
322 if ((fp = fopen(name, "r")) == NULL) { 323 fprintf(stderr, "ndp: cannot open %s\n", name); 324 exit(1); 325 } | 324 if ((fp = fopen(name, "r")) == NULL) 325 err(1, "cannot open %s", name); |
326 args[0] = &arg[0][0]; 327 args[1] = &arg[1][0]; 328 args[2] = &arg[2][0]; 329 args[3] = &arg[3][0]; 330 args[4] = &arg[4][0]; 331 retval = 0; 332 while (fgets(line, sizeof(line), fp) != NULL) { | 326 args[0] = &arg[0][0]; 327 args[1] = &arg[1][0]; 328 args[2] = &arg[2][0]; 329 args[3] = &arg[3][0]; 330 args[4] = &arg[4][0]; 331 retval = 0; 332 while (fgets(line, sizeof(line), fp) != NULL) { |
333 if ((p = strchr(line, '#')) != NULL) 334 *p = '\0'; 335 for (p = line; isblank(*p); p++); 336 if (*p == '\n' || *p == '\0') 337 continue; |
|
333 i = sscanf(line, "%49s %49s %49s %49s %49s", 334 arg[0], arg[1], arg[2], arg[3], arg[4]); 335 if (i < 2) { | 338 i = sscanf(line, "%49s %49s %49s %49s %49s", 339 arg[0], arg[1], arg[2], arg[3], arg[4]); 340 if (i < 2) { |
336 fprintf(stderr, "ndp: bad line: %s\n", line); | 341 warnx("bad line: %s", line); |
337 retval = 1; 338 continue; 339 } 340 if (set(i, args)) 341 retval = 1; 342 } 343 fclose(fp); 344 return (retval); --- 1226 unchanged lines hidden --- | 342 retval = 1; 343 continue; 344 } 345 if (set(i, args)) 346 retval = 1; 347 } 348 fclose(fp); 349 return (retval); --- 1226 unchanged lines hidden --- |