arpd/arpd.patch

Mon, 28 Jan 2013 17:37:18 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 28 Jan 2013 17:37:18 +0100
changeset 758
a2c6460cfb16
parent 714
119553d296d2
permissions
-rw-r--r--

Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.

     1 Index: arpd.c
     2 --- arpd.c.dist	2003-07-02 16:49:31.000000000 +0200
     3 +++ arpd.c	2003-07-02 16:53:25.000000000 +0200
     4 @@ -33,7 +33,7 @@
     5  #define ARPD_MAX_ACTIVE		600
     6  #define ARPD_MAX_INACTIVE	300
     8 -#define PIDFILE			"/var/run/arpd.pid"
     9 +#define PIDFILE			"/opsw/var/arpd/arpd.pid"
    11  struct arp_req {
    12  	struct addr		pa;
    13 @@ -111,9 +111,11 @@
    14  			struct in_addr in;
    15  			ip_addr_t istart, iend;
    17 -			second = p;
    18 +            first  = p;
    19 +            second = strchr(p, '-');
    20 +            if (second != NULL)
    21 +                *second++ = '\0';
    23 -			first = strsep(&second, "-");
    24  			if (second == NULL)
    25  				errx(1, "%s: Invalid network range: %s",
    26  				    __func__, p);
    27 @@ -185,7 +187,7 @@
    28  arpd_init(char *dev, int naddresses, char **addresses)
    29  {
    30  	struct bpf_program fcode;
    31 -	char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst;
    32 +	char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst, *iface;
    33  	intf_t *intf;
    35  	dst = arpd_expandips(naddresses, addresses);
    36 @@ -203,7 +205,16 @@
    37  			errx(1, "pcap_lookupdev: %s", ebuf);
    38  	}
    39  	arpd_ifent.intf_len = sizeof(arpd_ifent);
    40 -	strncpy(arpd_ifent.intf_name, dev, sizeof(arpd_ifent.intf_name) - 1);
    41 +
    42 +	/* mitigate slash paths in OS that provide   */
    43 +	/* network devices in subdirectories of /dev */
    44 +	iface = strrchr(dev, '/');
    45 +	if (iface)
    46 +		iface += sizeof(char);
    47 +	else
    48 +		iface = dev;
    49 +
    50 +	strncpy(arpd_ifent.intf_name, iface, sizeof(arpd_ifent.intf_name) - 1);
    51  	arpd_ifent.intf_name[sizeof(arpd_ifent.intf_name) - 1] = '\0';
    53  	if (intf_get(intf, &arpd_ifent) < 0)
    54 @@ -218,7 +229,7 @@
    55  	    dst ? "and (" : "", dst ? dst : "", dst ? ")" : "",
    56  	    addr_ntoa(&arpd_ifent.intf_link_addr));
    58 -	if ((arpd_pcap = pcap_open_live(dev, 128, 0, 500, ebuf)) == NULL)
    59 +	if ((arpd_pcap = pcap_open_live(iface, 128, 0, 500, ebuf)) == NULL)
    60  		errx(1, "pcap_open_live: %s", ebuf);
    62  	if (pcap_compile(arpd_pcap, &fcode, filter, 1, 0) < 0 ||
    63 @@ -265,7 +276,7 @@
    64  	    spa->addr_ip, tha->addr_eth, tpa->addr_ip);
    66  	if (op == ARP_OP_REQUEST) {
    67 -		syslog(LOG_DEBUG, __FUNCTION__ ": who-has %s tell %s",
    68 +		syslog(LOG_DEBUG, "%s: who-has %s tell %s", __FUNCTION__,
    69  		    addr_ntoa(tpa), addr_ntoa(spa));
    70  	} else if (op == ARP_OP_REPLY) {
    71  		syslog(LOG_INFO, "arp reply %s is-at %s",
    72 @@ -282,7 +293,7 @@
    73  	int error;
    75  	if (addr_cmp(addr, &arpd_ifent.intf_addr) == 0) {
    76 -		syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s",
    77 +		syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__,
    78  		    addr_ntoa(addr), addr_ntoa(&arpd_ifent.intf_link_addr));
    79  		return (0);
    80  	}
    81 @@ -291,10 +302,10 @@
    82  	error = arp_get(arpd_arp, &arpent);
    84  	if (error == -1) {
    85 -		syslog(LOG_DEBUG, __FUNCTION__ ": no entry for %s",
    86 +		syslog(LOG_DEBUG, "%s: no entry for %s", __FUNCTION__,
    87  		    addr_ntoa(addr));
    88  	} else {
    89 -		syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s",
    90 +		syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__,
    91  		    addr_ntoa(addr), addr_ntoa(&arpent.arp_ha));
    92  	}
    93  	return (error);
    94 @@ -423,7 +434,7 @@
    95  		if ((req = SPLAY_FIND(tree, &arpd_reqs, &tmp)) != NULL) {
    96  			addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS,
    97  			    ethip->ar_sha, ETH_ADDR_LEN);
    98 -			syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s",
    99 +			syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__,
   100  			    addr_ntoa(&req->pa), addr_ntoa(&src.arp_ha));
   102  			/* This address is claimed */
   103 @@ -445,9 +456,6 @@
   104  void
   105  terminate_handler(int sig)
   106  {
   107 -	extern int event_gotsig;
   108 -
   109 -	event_gotsig = 1;
   110  	arpd_sig = sig;
   111  }
   113 @@ -464,7 +472,6 @@
   114  main(int argc, char *argv[])
   115  {
   116  	struct event recv_ev;
   117 -	extern int (*event_sigcb)(void);
   118  	char *dev;
   119  	int c, debug;
   120  	FILE *fp;
   121 @@ -524,7 +531,6 @@
   122  		perror("signal");
   123  		return (-1);
   124  	}
   125 -	event_sigcb = arpd_signal;
   127  	event_dispatch();

mercurial