arp.c (7c478bd9) arp.c (69bb4bb4)
1/*
1/*
2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5/*
6 * Copyright (c) 1984 Regents of the University of California.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to Berkeley by
10 * Sun Microsystems, Inc.

--- 39 unchanged lines hidden (view full) ---

50#include <sys/types.h>
51#include <sys/socket.h>
52#include <netinet/in.h>
53#include <sys/ioctl.h>
54#include <errno.h>
55#include <netdb.h>
56#include <net/if.h>
57#include <net/if_arp.h>
3 * Use is subject to license terms.
4 */
5/*
6 * Copyright (c) 1984 Regents of the University of California.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to Berkeley by
10 * Sun Microsystems, Inc.

--- 39 unchanged lines hidden (view full) ---

50#include <sys/types.h>
51#include <sys/socket.h>
52#include <netinet/in.h>
53#include <sys/ioctl.h>
54#include <errno.h>
55#include <netdb.h>
56#include <net/if.h>
57#include <net/if_arp.h>
58#include <netinet/if_ether.h>
59#include <stdlib.h>
60#include <unistd.h>
61#include <string.h>
62#include <arpa/inet.h>
63#include <net/if_types.h>
64#include <net/if_dl.h>
65
66static int file(char *);

--- 79 unchanged lines hidden (view full) ---

146 exit(1);
147 }
148 return (0);
149}
150
151/*
152 * Process a file to set standard arp entries
153 */
58#include <stdlib.h>
59#include <unistd.h>
60#include <string.h>
61#include <arpa/inet.h>
62#include <net/if_types.h>
63#include <net/if_dl.h>
64
65static int file(char *);

--- 79 unchanged lines hidden (view full) ---

145 exit(1);
146 }
147 return (0);
148}
149
150/*
151 * Process a file to set standard arp entries
152 */
154static int file(char *name)
153static int
154file(char *name)
155{
156 /*
157 * A line of input can be:
155{
156 /*
157 * A line of input can be:
158 * <hostname> <macaddr> ["temp"] ["pub"] ["trail"]
158 * <hostname> <macaddr> ["temp"] ["pub"] ["trail"] ["permanent"]
159 */
160#define MAX_LINE_LEN (MAXHOSTNAMELEN + \
159 */
160#define MAX_LINE_LEN (MAXHOSTNAMELEN + \
161 sizeof (" xx:xx:xx:xx:xx:xx temp pub trail\n"))
161 sizeof (" xx:xx:xx:xx:xx:xx temp pub trail permanent\n"))
162#define MIN_ARGS 2
163#define MAX_ARGS 5
164
165 FILE *fp;
166 char line[MAX_LINE_LEN];
167 int retval;
168
169 if ((fp = fopen(name, "r")) == NULL) {

--- 39 unchanged lines hidden (view full) ---

209
210 (void) fclose(fp);
211 return (retval);
212}
213
214/*
215 * Set an individual arp entry
216 */
162#define MIN_ARGS 2
163#define MAX_ARGS 5
164
165 FILE *fp;
166 char line[MAX_LINE_LEN];
167 int retval;
168
169 if ((fp = fopen(name, "r")) == NULL) {

--- 39 unchanged lines hidden (view full) ---

209
210 (void) fclose(fp);
211 return (retval);
212}
213
214/*
215 * Set an individual arp entry
216 */
217static int set(int argc, char *argv[])
217static int
218set(int argc, char *argv[])
218{
219 struct xarpreq ar;
220 struct hostent *hp;
221 struct sockaddr_in *sin;
222 uchar_t *ea;
223 int s;
224 char *host = argv[0], *eaddr = argv[1];
225

--- 24 unchanged lines hidden (view full) ---

250 exit(1);
251 }
252 ar.xarp_ha.sdl_alen = s;
253 (void) memcpy(LLADDR(&ar.xarp_ha), ea, ar.xarp_ha.sdl_alen);
254 free(ea);
255 ar.xarp_ha.sdl_family = AF_LINK;
256 ar.xarp_flags = ATF_PERM;
257 while (argc-- > 0) {
219{
220 struct xarpreq ar;
221 struct hostent *hp;
222 struct sockaddr_in *sin;
223 uchar_t *ea;
224 int s;
225 char *host = argv[0], *eaddr = argv[1];
226

--- 24 unchanged lines hidden (view full) ---

251 exit(1);
252 }
253 ar.xarp_ha.sdl_alen = s;
254 (void) memcpy(LLADDR(&ar.xarp_ha), ea, ar.xarp_ha.sdl_alen);
255 free(ea);
256 ar.xarp_ha.sdl_family = AF_LINK;
257 ar.xarp_flags = ATF_PERM;
258 while (argc-- > 0) {
258 if (strncmp(argv[0], "temp", 4) == 0)
259 if (strncmp(argv[0], "temp", 4) == 0) {
259 ar.xarp_flags &= ~ATF_PERM;
260 ar.xarp_flags &= ~ATF_PERM;
260 if (strncmp(argv[0], "pub", 3) == 0)
261 } else if (strncmp(argv[0], "pub", 3) == 0) {
261 ar.xarp_flags |= ATF_PUBL;
262 ar.xarp_flags |= ATF_PUBL;
262 if (strncmp(argv[0], "trail", 5) == 0)
263 } else if (strncmp(argv[0], "trail", 5) == 0) {
263 ar.xarp_flags |= ATF_USETRAILERS;
264 ar.xarp_flags |= ATF_USETRAILERS;
265 } else if (strcmp(argv[0], "permanent") == 0) {
266 ar.xarp_flags |= ATF_AUTHORITY;
267 } else {
268 (void) fprintf(stderr,
269 "arp: unknown keyword '%s'\n", argv[0]);
270 return (1);
271 }
264 argv++;
265 }
266
272 argv++;
273 }
274
275 if ((ar.xarp_flags & (ATF_PERM|ATF_AUTHORITY)) == ATF_AUTHORITY) {
276 (void) fprintf(stderr, "arp: 'temp' and 'permanent' flags are "
277 "not usable together.\n");
278 return (1);
279 }
280
267 s = socket(AF_INET, SOCK_DGRAM, 0);
268 if (s < 0) {
269 perror("arp: socket");
270 exit(1);
271 }
272 if (ioctl(s, SIOCSXARP, (caddr_t)&ar) < 0) {
273 perror(host);
274 exit(1);
275 }
276 (void) close(s);
277 return (0);
278}
279
281 s = socket(AF_INET, SOCK_DGRAM, 0);
282 if (s < 0) {
283 perror("arp: socket");
284 exit(1);
285 }
286 if (ioctl(s, SIOCSXARP, (caddr_t)&ar) < 0) {
287 perror(host);
288 exit(1);
289 }
290 (void) close(s);
291 return (0);
292}
293
280
281/*
282 * Display an individual arp entry
283 */
294/*
295 * Display an individual arp entry
296 */
284static void get(char *host)
297static void
298get(char *host)
285{
286 struct xarpreq ar;
287 struct hostent *hp;
288 struct sockaddr_in *sin;
289 uchar_t *ea;
290 int s;
291 char *str = NULL;
292

--- 36 unchanged lines hidden (view full) ---

329 } else {
330 perror("arp: nomem");
331 exit(1);
332 }
333 } else {
334 (void) printf("%s (%s) at (incomplete)", host,
335 inet_ntoa(sin->sin_addr));
336 }
299{
300 struct xarpreq ar;
301 struct hostent *hp;
302 struct sockaddr_in *sin;
303 uchar_t *ea;
304 int s;
305 char *str = NULL;
306

--- 36 unchanged lines hidden (view full) ---

343 } else {
344 perror("arp: nomem");
345 exit(1);
346 }
347 } else {
348 (void) printf("%s (%s) at (incomplete)", host,
349 inet_ntoa(sin->sin_addr));
350 }
337 if (ar.xarp_flags & ATF_PERM)
338 (void) printf(" permanent");
351 if (!(ar.xarp_flags & ATF_PERM))
352 (void) printf(" temp");
339 if (ar.xarp_flags & ATF_PUBL)
353 if (ar.xarp_flags & ATF_PUBL)
340 (void) printf(" published");
354 (void) printf(" pub");
341 if (ar.xarp_flags & ATF_USETRAILERS)
355 if (ar.xarp_flags & ATF_USETRAILERS)
342 (void) printf(" trailers");
356 (void) printf(" trail");
357 if (ar.xarp_flags & ATF_AUTHORITY)
358 (void) printf(" permanent");
343 (void) printf("\n");
344}
345
346/*
347 * Delete an arp entry
348 */
359 (void) printf("\n");
360}
361
362/*
363 * Delete an arp entry
364 */
349static void delete(char *host)
365static void
366delete(char *host)
350{
351 struct xarpreq ar;
352 struct hostent *hp;
353 struct sockaddr_in *sin;
354 int s;
355
356 (void) memset(&ar, 0, sizeof (ar));
357 sin = (struct sockaddr_in *)&ar.xarp_pa;

--- 22 unchanged lines hidden (view full) ---

380 else
381 perror("SIOCDXARP");
382 exit(1);
383 }
384 (void) close(s);
385 (void) printf("%s (%s) deleted\n", host, inet_ntoa(sin->sin_addr));
386}
387
367{
368 struct xarpreq ar;
369 struct hostent *hp;
370 struct sockaddr_in *sin;
371 int s;
372
373 (void) memset(&ar, 0, sizeof (ar));
374 sin = (struct sockaddr_in *)&ar.xarp_pa;

--- 22 unchanged lines hidden (view full) ---

397 else
398 perror("SIOCDXARP");
399 exit(1);
400 }
401 (void) close(s);
402 (void) printf("%s (%s) deleted\n", host, inet_ntoa(sin->sin_addr));
403}
404
388static void usage(void)
405static void
406usage(void)
389{
390 (void) printf("Usage: arp hostname\n");
391 (void) printf(" arp -a [-n]\n");
392 (void) printf(" arp -d hostname\n");
393 (void) printf(" arp -s hostname ether_addr "
407{
408 (void) printf("Usage: arp hostname\n");
409 (void) printf(" arp -a [-n]\n");
410 (void) printf(" arp -d hostname\n");
411 (void) printf(" arp -s hostname ether_addr "
394 "[temp] [pub] [trail]\n");
412 "[temp] [pub] [trail] [permanent]\n");
395 (void) printf(" arp -f filename\n");
396}
413 (void) printf(" arp -f filename\n");
414}