[comp.sys.encore] SIOCSARP doesn't seem to work

dmh@goanna.cs.rmit.oz.au (Darren Hosking) (04/10/91)

I can't get the set arp cache ioctl (SIOCSARP) to work under UMAXV 2.4. The
code that requires this ioctl is bootpd which previously compiled and
ran correctly (under UMAXV 2.2m). However, under UMAXV 2.4 the ioctl always
produces SIOCSARP: Invalid argument. I have tried different flags etc but
to no avail.

I wrote a small test program that creates an arp cache entry that runs
correctly under BSD 4.3 (on a VAX) but not under UMAXV 2.4.

/*
 * Program to test the SIOCSARP ioctl.
 *
 * Creates a meaningless arp table entry.
 */

#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#ifdef UMAXV
#include <sys/net/if.h>
#include <sys/net/if_arp.h>
#include <sys/netinet/in.h>
#else
#include <net/if.h>
#include <netinet/in.h>
#endif

struct	arpreq arpreq;
char	ha[] = {255, 255, 255, 1, 2, 3};
int	len = 6;

main()
{
	int	s;
	struct sockaddr_in *sin;

	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
		perror("socket: ");
		exit(1);
        }
        bzero((caddr_t)&arpreq, sizeof(arpreq));

	sin = (struct sockaddr_in *)&arpreq.arp_pa;
        sin->sin_family = AF_INET;
        sin->sin_addr.s_addr = inet_addr("131.170.24.123");

        arpreq.arp_pa.sa_family = AF_INET;
        arpreq.arp_ha.sa_family = AF_UNSPEC;

        arpreq.arp_flags = ATF_INUSE | ATF_COM;
        bcopy(ha, arpreq.arp_ha.sa_data, len);

        if (ioctl(s, SIOCSARP, (caddr_t)&arpreq) < 0) {
		perror("SIOCSARP");
            	exit(1);
	}
}

What am I (and bootpd) doing wrong?

	Thanks, dmh

Darren Hosking			ACSnet: dmh@goanna.cs.rmit.oz	 
Department Of Computer Science	ARPA:   dmh%goanna.cs.rmit.oz.au@uunet.uu.net
RMIT				CSNET:  dmh%goanna.cs.rmit.oz.au@australia
GPO Box 2476V			UUCP:   ...!uunet!goanna.cs.rmit.oz.au!dmh
Melbourne Vic., Australia 3001	PH: +61 3 660 3299 FAX: +61 3 662 1617

skl@wimsey.bc.ca (Samuel Lam) (04/15/91)

In article <5184@goanna.cs.rmit.oz.au>, dmh@goanna.cs.rmit.oz.au
 (Darren Hosking) wrote:
>I can't get the set arp cache ioctl (SIOCSARP) to work under UMAXV 2.4. The
>code that requires this ioctl is bootpd which previously compiled and
>ran correctly (under UMAXV 2.2m). However, under UMAXV 2.4 the ioctl always
>produces SIOCSARP: Invalid argument.

Did the C compiler change between the 2.2m compilation and the
2.4 compilation?  The problem you described sounds very much
like one I encountered a while ago on SCO XENIX.  The culpit
I found was in the definition for SIOCSARP in <sys/socket.h>.

For a macro like:

    #define A(x) ('x')

and an expression of

    A(b)

, an older compiler (actually preprocessor) will turn that into 'b'
while a newer one will turn it into 'x'.

What you have to do is change the macro to something like

    #define A(x) (x)

and then change the invoking expression to

    A('b')

In my case, I ended up editing my <sys/socket.h> to fix
the problem.  Fortunately, all the changes, both macros and
expressions, were confined within that one header file.

Hope this helps...

...Sam
-- 
<skl@wimsey.bc.ca>

jmagee@encore.com (Jim Magee) (04/17/91)

In article <5184@goanna.cs.rmit.oz.au>, dmh@goanna.cs.rmit.oz.au
 (Darren Hosking) wrote:
>I can't get the set arp cache ioctl (SIOCSARP) to work under UMAXV 2.4. The
>code that requires this ioctl is bootpd which previously compiled and
>ran correctly (under UMAXV 2.2m). However, under UMAXV 2.4 the ioctl always
>produces SIOCSARP: Invalid argument.

UMAXV 2.4 uses STREAMS networking, whereas UMAXV 2.2m used BSD-style
networking.  Under STREAMS, ARP is implemented as a module that is
pushed onto an open ethernet driver stream (see slink and /etc/strcf
for more info).

To issue IOCTLs to ARP (including SIOCSARP) you must open the appropriate
streams device (/dev/inet/arp) and then issue the IOCTL.

Jim Magee			UMAX Development
uunet!gould!jmagee		Encore Computer Corporation
jmagee@headroom.encore.com	6901 W. Sunrise Blvd. MS-407
(305) 587-2900 x5165		Plantation, FL 33313
-- 
Jim Magee			UMAX Development
uunet!gould!jmagee		Encore Computer Corporation
jmagee@headroom.encore.com	6901 W. Sunrise Blvd. MS-407
(305) 587-2900 x5165		Plantation, FL 33313

jmagee@wizard.Berkeley.EDU (Jim Magee) (04/17/91)

Jim Magee			UMAX Development
uunet!gould!jmagee		Encore Computer Corporation
jmagee@headroom.encore.com	6901 W. Sunrise Blvd. MS-407
(305) 587-2900 x5165		Plantation, FL 33313

jmagee@encore.com (Jim Magee) (04/17/91)

In article <131038@puff.encore.com>, jmagee@encore.com (Jim Magee) writes:
> In article <5184@goanna.cs.rmit.oz.au>, dmh@goanna.cs.rmit.oz.au
>  (Darren Hosking) wrote:
> >I can't get the set arp cache ioctl (SIOCSARP) to work under UMAXV 2.4. The
> >code that requires this ioctl is bootpd which previously compiled and
> >ran correctly (under UMAXV 2.2m). However, under UMAXV 2.4 the ioctl always
> >produces SIOCSARP: Invalid argument.
> 
> To issue IOCTLs to ARP (including SIOCSARP) you must open the appropriate
> streams device (/dev/inet/arp) and then issue the IOCTL.

I almost forgot, the method for issuing the ioctl is also slightly different.
It has to be pushed as a streams message.  Here's how:

struct strioctl strioc;
struct arpreq ar;
int s;

s = open("/dev/inet/arp",0);
strioc.ic_cmd = SIOCSARP;
strioc.ic_timout = -1;
strioc.ic_len = sizeof(struct arpreq);
strioc.ic_dp = &ar;
result = ioctl(s, I_STR, &strioc);

-- 
Jim Magee			UMAX Development
uunet!gould!jmagee		Encore Computer Corporation
jmagee@headroom.encore.com	6901 W. Sunrise Blvd. MS-407
(305) 587-2900 x5165		Plantation, FL 33313