[klibc] networking problems in kinit

Hubert Feurstein h.feurstein at gmail.com
Wed Apr 22 00:47:01 PDT 2009

Hi all,

I need UDP support in kinit. But when I did the implementation I ran into some
fundamental problems, maybe someone can help me.

First, the description what I did so far:
The network interface itself has been configured by 'do_ipconfig'
with a static configuration from the kernel cmdline:

I added the following (simplified) code somewhere after 'do_ipconfig':
int fd;
struct sockaddr_in addr;
bindresvport(fd, 0);
memset( &addr, 0, sizeof( addr ) );
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr( "" );
addr.sin_port = htons( 60000 );
connect(fd, (struct sockaddr *)&addr, sizeof(addr))
send( fd, ... some data ... )

But now 'connect' fails with the error "Permission denied".
I've already checked whether the network interface is really up, so
I placed a 'sleep' after 'do_ipconfig' and tried to ping the
board (ARM9 based module) during this sleep-phase which was ok,
so the interface is up and running.

I still was wondering why this simple piece of code doesn't work,
so I tried to find the place in the kernel which returns the error:
It occours in net/ipv4/datagram.c in function

int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
	err = ip_route_connect(&rt, usin->sin_addr.s_addr, saddr,
			       RT_CONN_FLAGS(sk), oif,
			       inet->sport, usin->sin_port, sk, 1);
	if (err)
		return err;

	if ((rt->rt_flags & RTCF_BROADCAST) && !sock_flag(sk, SOCK_BROADCAST)) {
		return -EACCES; >>>>>> This throws me out <<<<<<<<<

So for me it seems, that there is something wrong or not correctly set
up in the routing table.
(But the host is within the same net, so routing is not really required).

I tried to set the socketoption SO_BROADCAST to see whether it works
then, and it did.
But of course only boardcasts were sent, and I need unicasts.

Now this brings me to the following questions:
Do I have to do anything special to use UDP networking in early userspace?
Did I miss something in the configuration of the network interface or
routing table?

Any help is very appreciated.
Thanks in advance.

best regards

More information about the klibc mailing list