FreeBSD/sbin/dhclient/bpf.c
/*
 * Called by get_interface_list for each interface that's discovered.
 * Opens a packet filter for each interface and adds it to the select
 * mask.
 */
Called by get_interface_list for each interface that's discovered.
Opens a packet filter for each interface and adds it to the select
mask.
Called by get_interface_list for each interface that ' s discovered . Opens a packet filter for each interface and adds it to the select mask .
int
if_register_bpf(struct interface_info *info, int flags)
{
	char filename[50];
	int sock, b;
	for (b = 0;; b++) {
		snprintf(filename, sizeof(filename), BPF_FORMAT, b);
		sock = open(filename, flags);
		if (sock < 0) {
			if (errno == EBUSY)
				continue;
			else
				error("Can't find free bpf: %m");
		} else
			break;
	}
	if (ioctl(sock, BIOCSETIF, info->ifp) < 0)
		error("Can't attach interface %s to bpf device %s: %m",
		    info->name, filename);
	return (sock);
}
int if_register_bpf ( struct interface_info * info , int flags ) { char filename [ 50 ] ; int sock , b ; for ( b = 0 ; ; b ++ ) { snprintf ( filename , sizeof ( filename ) , BPF_FORMAT , b ) ; sock = open ( filename , flags ) ; if ( sock < 0 ) { if ( errno == EBUSY ) continue ; else error ( " " ) ; } else break ; } if ( ioctl ( sock , BIOCSETIF , info -> ifp ) < 0 ) error ( " " , info -> name , filename ) ; return ( sock ) ; }
Called by get_interface_list for each interface that's discovered.
Called by get_interface_list for each interface that ' s discovered .
/* Open a BPF device */ /* Set the BPF device to point at this interface. */