View Single Post
  #1   (View Single Post)  
Old 26th November 2012
munchiez munchiez is offline
New User
 
Join Date: Nov 2012
Posts: 7
Default scanning network using ioctl problem

hi, i'm making a network manager type program for openBSD. I'm using ioctl's to try scan for wireless networks the same way ifconfig does it, but it seems that i cant scan unless i'm already connected to a network. Why does my code fail when i'm not connected..?

Code:
void getNodes(char *name)
{

	struct ieee80211_nodereq_all na;
	struct ieee80211_nodereq nr[512];
	struct ifreq ifr;
	
	bzero(&ifr, sizeof(ifr));
	strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));

	if (ioctl(s, SIOCS80211SCAN, (caddr_t)&ifr) != 0) {
		
			printf("\t\tno permission to scan\n");
		//goto done;
	}   

	bzero(&na, sizeof(na));
	bzero(&nr, sizeof(nr));
	na.na_node = nr;
	na.na_size = sizeof(nr);
	strlcpy(na.na_ifname, name, sizeof(na.na_ifname));
	
	if (ioctl(s, SIOCG80211ALLNODES, &na) != 0) {
		warn("SIOCG80211ALLNODES");
		//goto done;
	}

	if (!na.na_nodes)
		printf("\t\tnone\n");
	int i;
	for (i = 0; i < na.na_nodes; i++) {
		printf("\t\t");
		printNode(&nr[i]);
		putchar('\n');
	}
}

both SIOCG80211ALLNODES and SIOCS80211SCAN requests will fail in this instance. most of this code is from ifconfig ive missed something out but cant figure out what...

any insight would be good.
Reply With Quote