Subject: Re: strangeness while using SOCK_RAW
To: None <tech-kern@netbsd.org>
From: Eric Auge <eau@phear.org>
List: tech-kern
Date: 02/09/2007 18:58:29
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig0380B9FE5FAC750A7B98F1D6
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello Brian,

I didn't say I needed to change something in the kernel,
OpenOSPFD is already ported and works perfectly (as said in my previous m=
ail),
if you read carefully what the problem is you will understand what
my question is.

Thanks anyway,
Regards,
Eric.

Brian Buhrow wrote:
> 	Hello.  If it helps, here is some user-space code I'm using under
> NetBSD and FreeBSD which uses raw sockets.  With raw sockets, you get t=
he
> IP header from the kernel on reception, but it's not required that you
> provide a full header on transmission.  In fact, you can't, unless you =
use
> the setsockopt, IP_HDRINCL, to tell the kernel that you, the user, will=

> provide the full IP header for packets you send.  Even then, the kernel=

> will calculate the checksum for you, and set the len field on the packe=
t
> before it puts it on the wire.
> 	I very much doubt you need to change things in the kernel to get
> openospfd to run under NetBSD, and things should be pretty close to wor=
king
> with no changes at all to the application code.
>=20
> Here are my snippets.
>=20
> I hope they help.
>=20
> [code to send data to the network]
> 	bzero(&sin, sizeof(sin));
> 	sin.sin_family =3D AF_INET;
> 	sinlen =3D sizeof(sin);
> 	intlen =3D sizeof(int);
> [...]
> 			if (sendto(tunnelsock, inbuf, bytesread, 0,=20
> 			(struct sockaddr *)&sin, sinlen) !=3D bytesread) {
> 				syslog(LOG_CRIT,"function: sendto: %m");
> 			}
>=20
> [...]
>=20
> [Code to receive data from the network using raw sockets]
> 		bzero(&sin, sizeof(sin));
> 		sin.sin_family =3D AF_INET;
> 		sin.sin_addr.s_addr =3D htonl(INADDR_ANY);
> 		sin.sin_port =3D htons(0);
> 		sinlen =3D sizeof(sin);
> 		if (bind(tunnelsock, (struct socaddr *)&sin, sinlen) < 0) {
> 			syslog(LOG_CRIT,"overlan: bind: %m");
> 			return(1); /*Should never happen*/
> 		}
> 	sinlen =3D sizeof(sin);
> 	bytesread =3D recvfrom(tunnelsock, inbuf, 3000, 0, &sin, &sinlen);
> 	if (bytesread < 0) {
> 		syslog(LOG_CRIT,"function: %m");
> 		return(1); /*Should never happen*/
> 	}
> 	inlen =3D bytesread - sizeof(struct ip);
> 	indata =3D inbuf + sizeof(struct ip);
>  [...]
>=20


--------------enig0380B9FE5FAC750A7B98F1D6
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (NetBSD)

iD8DBQFFzLZHSdZNA80H8MYRAm0mAJ41EBmP8xYgm/MDf+3zIcH4QV0fUgCdHqWO
15RTvtRPf2/uTguarJzcQz8=
=Phx3
-----END PGP SIGNATURE-----

--------------enig0380B9FE5FAC750A7B98F1D6--