ndp.c (256281) | ndp.c (270655) |
---|---|
1/* $FreeBSD: stable/10/usr.sbin/ndp/ndp.c 253999 2013-08-06 17:10:52Z hrs $ */ | 1/* $FreeBSD: stable/10/usr.sbin/ndp/ndp.c 270655 2014-08-26 10:32:08Z ae $ */ |
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> --- 18 unchanged lines hidden (view full) --- 126static int s = -1; 127static int repeat = 0; 128 129char ntop_buf[INET6_ADDRSTRLEN]; /* inet_ntop() */ 130char host_buf[NI_MAXHOST]; /* getnameinfo() */ 131char ifix_buf[IFNAMSIZ]; /* if_indextoname() */ 132 133int 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> --- 18 unchanged lines hidden (view full) --- 127static int s = -1; 128static int repeat = 0; 129 130char ntop_buf[INET6_ADDRSTRLEN]; /* inet_ntop() */ 131char host_buf[NI_MAXHOST]; /* getnameinfo() */ 132char ifix_buf[IFNAMSIZ]; /* if_indextoname() */ 133 134int main(int, char **); |
134int file(char *); | 135static int file(char *); |
135void getsocket(void); 136int set(int, char **); 137void get(char *); 138int delete(char *); 139void dump(struct in6_addr *, int); 140static struct in6_nbrinfo *getnbrinfo(struct in6_addr *, int, int); 141static char *ether_str(struct sockaddr_dl *); 142int ndp_ether_aton(char *, u_char *); --- 46 unchanged lines hidden (view full) --- 189 case 'I': 190 if (mode) { 191 usage(); 192 /*NOTREACHED*/ 193 } 194 mode = ch; 195 arg = NULL; 196 break; | 136void getsocket(void); 137int set(int, char **); 138void get(char *); 139int delete(char *); 140void dump(struct in6_addr *, int); 141static struct in6_nbrinfo *getnbrinfo(struct in6_addr *, int, int); 142static char *ether_str(struct sockaddr_dl *); 143int ndp_ether_aton(char *, u_char *); --- 46 unchanged lines hidden (view full) --- 190 case 'I': 191 if (mode) { 192 usage(); 193 /*NOTREACHED*/ 194 } 195 mode = ch; 196 arg = NULL; 197 break; |
197 case 'd': | |
198 case 'f': | 198 case 'f': |
199 case 'i' : | 199 exit(file(optarg) ? 1 : 0); 200 case 'd': 201 case 'i': |
200 if (mode) { 201 usage(); 202 /*NOTREACHED*/ 203 } 204 mode = ch; 205 arg = optarg; 206 break; 207 case 'n': --- 106 unchanged lines hidden (view full) --- 314 break; 315 } 316 exit(0); 317} 318 319/* 320 * Process a file to set standard ndp entries 321 */ | 202 if (mode) { 203 usage(); 204 /*NOTREACHED*/ 205 } 206 mode = ch; 207 arg = optarg; 208 break; 209 case 'n': --- 106 unchanged lines hidden (view full) --- 316 break; 317 } 318 exit(0); 319} 320 321/* 322 * Process a file to set standard ndp entries 323 */ |
322int | 324static int |
323file(name) 324 char *name; 325{ 326 FILE *fp; 327 int i, retval; | 325file(name) 326 char *name; 327{ 328 FILE *fp; 329 int i, retval; |
328 char line[100], arg[5][50], *args[5]; | 330 char line[100], arg[5][50], *args[5], *p; |
329 | 331 |
330 if ((fp = fopen(name, "r")) == NULL) { 331 fprintf(stderr, "ndp: cannot open %s\n", name); 332 exit(1); 333 } | 332 if ((fp = fopen(name, "r")) == NULL) 333 err(1, "cannot open %s", name); |
334 args[0] = &arg[0][0]; 335 args[1] = &arg[1][0]; 336 args[2] = &arg[2][0]; 337 args[3] = &arg[3][0]; 338 args[4] = &arg[4][0]; 339 retval = 0; 340 while (fgets(line, sizeof(line), fp) != NULL) { | 334 args[0] = &arg[0][0]; 335 args[1] = &arg[1][0]; 336 args[2] = &arg[2][0]; 337 args[3] = &arg[3][0]; 338 args[4] = &arg[4][0]; 339 retval = 0; 340 while (fgets(line, sizeof(line), fp) != NULL) { |
341 if ((p = strchr(line, '#')) != NULL) 342 *p = '\0'; 343 for (p = line; isblank(*p); p++); 344 if (*p == '\n' || *p == '\0') 345 continue; |
|
341 i = sscanf(line, "%49s %49s %49s %49s %49s", 342 arg[0], arg[1], arg[2], arg[3], arg[4]); 343 if (i < 2) { | 346 i = sscanf(line, "%49s %49s %49s %49s %49s", 347 arg[0], arg[1], arg[2], arg[3], arg[4]); 348 if (i < 2) { |
344 fprintf(stderr, "ndp: bad line: %s\n", line); | 349 warnx("bad line: %s", line); |
345 retval = 1; 346 continue; 347 } 348 if (set(i, args)) 349 retval = 1; 350 } 351 fclose(fp); 352 return (retval); --- 1240 unchanged lines hidden --- | 350 retval = 1; 351 continue; 352 } 353 if (set(i, args)) 354 retval = 1; 355 } 356 fclose(fp); 357 return (retval); --- 1240 unchanged lines hidden --- |