Example #1
0
int
netif_open(void *machdep_hint)
{
	int fd;
	struct iodesc *s;
	struct netif *nif;

	/* find a free socket */
	for (fd = 0, s = sockets; fd < SOPEN_MAX; fd++, s++)
		if (s->io_netif == (struct netif *)0)
			goto fnd;
	errno = EMFILE;
	return -1;

fnd:
	(void)memset(s, 0, sizeof(*s));
	netif_init();
	nif = netif_select(machdep_hint);
	if (!nif)
		panic("netboot: no interfaces left untried");
	if (netif_probe(nif, machdep_hint)) {
		printf("netboot: couldn't probe %s%d\n",
		    nif->nif_driver->netif_bname, nif->nif_unit);
		errno = EINVAL;
		return -1;
	}
	netif_attach(nif, s, machdep_hint);

	return fd;
}
Example #2
0
int 
netif_open(void *aux)
{
	struct netif *nif;
	struct iodesc *s;
	int fd, error;

	/* find a free socket */
	for (fd = 0, s = sockets; fd < SOPEN_MAX; fd++, s++)
		if (s->io_netif == NULL)
			goto found;
	errno = EMFILE;
	return (-1);

found:
	memset(s, 0, sizeof(*s));
	nif = &prom_netif;
	error = netif_attach(nif, s, aux);
	if (error != 0) {
		errno = error;
		return (-1);
	}
	return (fd);
}