Subject: Re: strangeness while using SOCK_RAW
To: None <>
From: Eric Auge <>
List: tech-kern
Date: 02/09/2007 18:58:29
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
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=
if you read carefully what the problem is you will understand what
my question is.

Thanks anyway,

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=
> 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 =
> 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=
> 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=
> with no changes at all to the application code.
> Here are my snippets.
> I hope they help.
> [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");
> 			}
> [...]
> [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);
>  [...]

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

Version: GnuPG v1.4.6 (NetBSD)