Here are my first suggestion for HWAddr.
class HWAddr
{
static final int SIZE = 6;
byte[] addr = new byte[ SIZE ];
HWAddr( byte[] raw, int offset )
{
System.arraycopy( raw, offset, addr, 0, SIZE );
}
};
Pass the entire raw array to HWAddr constructor. In C, it is just like
char *raw = "a-very-long-string";
puts( raw );
Inside EtherPacket.java,
dest = new HWAddr(raw[0],raw[1],raw[2],raw[3],raw[4],raw[5]);
becomes
dest = new HWAddr( raw, 0 );
and
src = new HWAddr(raw[6],raw[7],raw[8],raw[9],raw[10],raw[11]);
becomes
src = new HWAddr( raw, 6 );
-----
Going to the next level...
In the interest of high performance, bytes from an ethernet packet do not
have to be duplicated in HWAddr. The HWAddr object is immutable. It points
to the MAC Address. It might be written something like this:
class HWAddr
{
byte[] raw;
int offset;
HWAddr( byte[] r, int o )
{
raw = r;
offset = o;
}
};
-----
Going to the next level: If you wanted to split HWAddr into SourceAddr and
TargetAddress, you'd have this:
dest = new HWAddr( raw, 0 );
becomes
dest = new SourceAddr( raw );
and
src = new HWAddr( raw, 6 );
becomes
src = new TargetAddr( raw );
SourceAddr and TargetAddr share all of the same behavior, except for offset
and class name.
class SourceAddr
{
static final int OFFSET = 0;
byte[] raw;
SourceAddr( byte[] r )
{
raw = r
}
};
and
class TargetAddr
{
static final int OFFSET = 6;
byte[] raw;
TargetAddr( byte[] r )
{
raw = r;
}
};
_______________________________________________
Kernel maillist - [EMAIL PROTECTED]
http://jos.org/mailman/listinfo/kernel
[JOS-Kernel] [TCP/IP Stack] HWAddr suggestions
Gilbert Carl Herschberger II Thu, 25 Nov 1999 19:15:57 -0800
