Subject: Sample (but possibly useful) LKM: fake Ethernet device
To: None <tech-kern@netbsd.org, tech-net@netbsd.org>
From: Quentin Garnier <cube@cubidou.net>
List: tech-kern
Date: 11/04/2003 18:54:33
This is a multi-part message in MIME format.

--Multipart=_Tue__4_Nov_2003_18_54_33_+0100_Zk1pyTd5SWiU/+Xi
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Hi all,

Because I kind of needed it at work (anyone who had to deal with FlexML
will understand), I wrote that tiny LKM that fakes an Ethernet device.

I think it can be useful as a sample LKM, because it uses some of the
neat (and clean, too) features of the kernel.

I'd like to have some input on it, since it is likely that some
errors remain in the comments notably. Then I will either commit it
somewhere under sys/lkm (just as an example, of course), or make it
available through a site, maybe with Benedikt Meurer's fine guide [1].

Comments?

Quentin Garnier.

[1] <URL:http://www.home.unix-ag.org/bmeurer/NetBSD/howto-lkm.html>

--Multipart=_Tue__4_Nov_2003_18_54_33_+0100_Zk1pyTd5SWiU/+Xi
Content-Type: application/octet-stream;
 name="ethfoo.tgz"
Content-Disposition: attachment;
 filename="ethfoo.tgz"
Content-Transfer-Encoding: base64

H4sIABTkpz8AA+xcWXcbN7LOK/krEM9EIpW2TGqxJnLsOTTZsnoskQpJeZlcTw/UDYo96oXpRTJv
xv/91oJeuNlJJnbOmat+kEk0UCgUqr4qVIFW6XQSRV991qfVOmgdHR7Cv6320WEL/221Dw7oX/18
1To6OmwfPW4/brWhvd1u7z/+6vDzssVPlqQyFuIrJ7tSH++n4uRLMPRlH0X7/yhRqXTd+PPM8Sv2
f6/V2sf93zt83L7f/y/wLO5//u+u83vO0Wq3Wo95v9ft/8H+0ePC/o8OaP8PDg7h39+TiU3P//P9
f7RT+3Nfpc9HvT/Xdh7V64926mJHiG40m8fe9TQVDacp0CoN8UOmwtQLxQsZh56Kd4Xo+L6gXomI
FcjnVrm7OJxIDJXrJWnsXWWpF4VChq4AGQogkERZ7ChqufJCGc/FJIqDxBB3XjoVUUz/RllKZILI
9SaeI5GIIW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