mirror of
https://git.freebsd.org/ports.git
synced 2025-06-16 10:10:31 -04:00
Add verbose option to print warning only, and another type gratuitous
ARP used by windows: packet containing zero sender ip. PR: ports/145198 Submitted by: Gleb Kurtsou
This commit is contained in:
parent
655db7f5a0
commit
e36a78f95b
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=253683
3 changed files with 79 additions and 16 deletions
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
PORTNAME= choparp
|
PORTNAME= choparp
|
||||||
PORTVERSION= 20021107
|
PORTVERSION= 20021107
|
||||||
PORTREVISION= 3
|
PORTREVISION= 4
|
||||||
CATEGORIES= net-mgmt
|
CATEGORIES= net-mgmt
|
||||||
MASTER_SITES= SF
|
MASTER_SITES= SF
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
--- choparp.8.orig Fri Feb 13 20:28:33 2004
|
--- choparp.8.orig 2002-11-08 07:36:03.000000000 +0900
|
||||||
+++ choparp.8 Fri Feb 13 20:30:23 2004
|
+++ choparp.8 2010-05-04 20:39:28.291199414 +0900
|
||||||
@@ -34,7 +34,7 @@
|
@@ -34,7 +34,8 @@
|
||||||
.Nm choparp
|
.Nm choparp
|
||||||
.Nd cheap and omitted proxy ARP
|
.Nd cheap and omitted proxy ARP
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
-.Nm chpoarp
|
-.Nm chpoarp
|
||||||
+.Nm choparp
|
+.Nm choparp
|
||||||
|
+.Op Fl v
|
||||||
.Ar if_name mac_addr
|
.Ar if_name mac_addr
|
||||||
.Oo Fl Oc Ns Ar net_addr Ns
|
.Oo Fl Oc Ns Ar net_addr Ns
|
||||||
.Op / Ns Ar net_mask
|
.Op / Ns Ar net_mask
|
||||||
@@ -42,7 +42,7 @@
|
@@ -42,7 +43,7 @@
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Pp
|
.Pp
|
||||||
.Nm choparp
|
.Nm choparp
|
||||||
|
@ -18,7 +19,7 @@
|
||||||
It watches ARP request packets visible on the interface specified by argument
|
It watches ARP request packets visible on the interface specified by argument
|
||||||
.Ar if_name ,
|
.Ar if_name ,
|
||||||
and sends proxy ARP reply to the sender if the ARP request queries the
|
and sends proxy ARP reply to the sender if the ARP request queries the
|
||||||
@@ -52,7 +52,7 @@
|
@@ -52,7 +53,7 @@
|
||||||
.Ar net_addr Ns / Ar net_mask .
|
.Ar net_addr Ns / Ar net_mask .
|
||||||
.Pp
|
.Pp
|
||||||
.Ar mac_addr
|
.Ar mac_addr
|
||||||
|
@ -27,7 +28,7 @@
|
||||||
It is normally the address of
|
It is normally the address of
|
||||||
.Ar if_name .
|
.Ar if_name .
|
||||||
The format of
|
The format of
|
||||||
@@ -72,7 +72,7 @@
|
@@ -72,7 +73,7 @@
|
||||||
.Dq 0x
|
.Dq 0x
|
||||||
.Pq for example Ad 0x858a0186 .
|
.Pq for example Ad 0x858a0186 .
|
||||||
.Ar net_mask
|
.Ar net_mask
|
||||||
|
@ -36,11 +37,14 @@
|
||||||
or alternatively as a mask length. The following address specifications
|
or alternatively as a mask length. The following address specifications
|
||||||
are therefore equivalent:
|
are therefore equivalent:
|
||||||
.Bl -item -offset indent
|
.Bl -item -offset indent
|
||||||
@@ -89,6 +89,13 @@
|
@@ -89,6 +90,16 @@
|
||||||
.Em excluded
|
.Em excluded
|
||||||
by preceding them with
|
by preceding them with
|
||||||
.Fl
|
.Fl
|
||||||
+.Pp
|
+.Pp
|
||||||
|
+.Fl v
|
||||||
|
+option enables verbose mode, showing warning for invalid ARP packets.
|
||||||
|
+.Pp
|
||||||
+.Nm choparp
|
+.Nm choparp
|
||||||
+uses the Berkeley Packet Filter
|
+uses the Berkeley Packet Filter
|
||||||
+.Nm bpf(4)
|
+.Nm bpf(4)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--- choparp.c.orig Fri Nov 8 07:36:03 2002
|
--- choparp.c.orig 2002-11-08 07:36:03.000000000 +0900
|
||||||
+++ choparp.c Thu Apr 20 23:56:38 2006
|
+++ choparp.c 2010-05-04 20:39:28.279310506 +0900
|
||||||
@@ -42,6 +42,7 @@
|
@@ -42,6 +42,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -8,18 +8,32 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <net/bpf.h>
|
#include <net/bpf.h>
|
||||||
@@ -239,6 +240,10 @@
|
@@ -75,6 +76,7 @@
|
||||||
|
|
||||||
|
struct cidr *targets = NULL, *excludes = NULL;
|
||||||
|
u_char target_mac[ETHER_ADDR_LEN]; /* target MAC address */
|
||||||
|
+int verbose = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
ARP filter program
|
||||||
|
@@ -239,6 +241,16 @@
|
||||||
fprintf(stderr,"checkarp: WARNING: received unknown type ARP request.\n");
|
fprintf(stderr,"checkarp: WARNING: received unknown type ARP request.\n");
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
+ if (ntohl(*(u_int32_t *)(arp->arp_tpa)) == ntohl(*(u_int32_t *)(arp->arp_spa))) {
|
+ if (ntohl(*(u_int32_t *)(arp->arp_tpa)) == ntohl(*(u_int32_t *)(arp->arp_spa))) {
|
||||||
|
+ if (verbose != 0)
|
||||||
+ fprintf(stderr,"checkarp: WARNING: sender equal dest.\n");
|
+ fprintf(stderr,"checkarp: WARNING: sender equal dest.\n");
|
||||||
+ return(0);
|
+ return(0);
|
||||||
|
+ }
|
||||||
|
+ if (0 == ntohl(*(u_int32_t *)(arp->arp_spa))) {
|
||||||
|
+ if (verbose != 0)
|
||||||
|
+ fprintf(stderr,"checkarp: WARNING: zero sender address.\n");
|
||||||
|
+ return(0);
|
||||||
+ }
|
+ }
|
||||||
target_ip = ntohl(*(u_int32_t *)(arp->arp_tpa));
|
target_ip = ntohl(*(u_int32_t *)(arp->arp_tpa));
|
||||||
return match(target_ip, targets) && !match(target_ip, excludes);
|
return match(target_ip, targets) && !match(target_ip, excludes);
|
||||||
}
|
}
|
||||||
@@ -280,13 +285,22 @@
|
@@ -280,13 +292,22 @@
|
||||||
char *rframe;
|
char *rframe;
|
||||||
char *sframe;
|
char *sframe;
|
||||||
size_t frame_len;
|
size_t frame_len;
|
||||||
|
@ -46,7 +60,7 @@
|
||||||
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
@@ -295,7 +309,7 @@
|
@@ -295,7 +316,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +69,7 @@
|
||||||
if (rlen < 0) {
|
if (rlen < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
@@ -307,7 +321,7 @@
|
@@ -307,7 +328,7 @@
|
||||||
while((rframe = getarp(p, rlen, &nextp, &nextlen)) != NULL){
|
while((rframe = getarp(p, rlen, &nextp, &nextlen)) != NULL){
|
||||||
if (checkarp(rframe)){
|
if (checkarp(rframe)){
|
||||||
sframe = gen_arpreply(rframe, &frame_len);
|
sframe = gen_arpreply(rframe, &frame_len);
|
||||||
|
@ -64,7 +78,52 @@
|
||||||
}
|
}
|
||||||
p = nextp;
|
p = nextp;
|
||||||
rlen = nextlen;
|
rlen = nextlen;
|
||||||
@@ -437,6 +451,9 @@
|
@@ -362,13 +383,13 @@
|
||||||
|
|
||||||
|
void
|
||||||
|
usage(void){
|
||||||
|
- fprintf(stderr,"usage: choparp if_name mac_addr [-]addr/mask...\n");
|
||||||
|
+ fprintf(stderr,"usage: choparp [-v] if_name mac_addr [-]addr/mask...\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv){
|
||||||
|
- int fd;
|
||||||
|
+ int ch, fd;
|
||||||
|
char *buf, *ifname;
|
||||||
|
struct cidr **targets_tail = &targets, **excludes_tail = &excludes;
|
||||||
|
#define APPEND(LIST,ADDR,MASK) \
|
||||||
|
@@ -381,13 +402,24 @@
|
||||||
|
} while (0)
|
||||||
|
size_t buflen;
|
||||||
|
|
||||||
|
- if (argc < 4)
|
||||||
|
+ while ((ch = getopt(argc, argv, "v")) != -1)
|
||||||
|
+ switch (ch) {
|
||||||
|
+ case 'v':
|
||||||
|
+ verbose++;
|
||||||
|
+ break;
|
||||||
|
+ default:
|
||||||
|
+ usage();
|
||||||
|
+ }
|
||||||
|
+ argc -= optind;
|
||||||
|
+ argv += optind;
|
||||||
|
+
|
||||||
|
+ if (argc < 3)
|
||||||
|
usage();
|
||||||
|
|
||||||
|
- ifname = argv[1];
|
||||||
|
- if (setmac(argv[2], ifname))
|
||||||
|
+ ifname = argv[0];
|
||||||
|
+ if (setmac(argv[1], ifname))
|
||||||
|
usage();
|
||||||
|
- argv += 3; argc -= 3;
|
||||||
|
+ argv += 2; argc -= 2;
|
||||||
|
|
||||||
|
while (argc > 0) {
|
||||||
|
u_int32_t addr, mask = ~0;
|
||||||
|
@@ -437,6 +469,9 @@
|
||||||
#endif
|
#endif
|
||||||
if ((fd = openbpf(ifname, &buf, &buflen)) < 0)
|
if ((fd = openbpf(ifname, &buf, &buflen)) < 0)
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue