I have written the following program to get the ESSID of the wireless network to which my Desktop is currently connected, but it is giving me errors. Can anyone help me corr
You are testing the return code of ioctl(2) incorrectly. ioctl(2) returns -1 on error, not true (non-zero). Since an error is not being returned, the value in errno is undefined and is misleading.
It should read:
if (ioctl(sockfd,SIOCGIWESSID, &wreq) == -1) {
fprintf(stderr, "Get ESSID ioctl failed \n");
fprintf(stderr, "errno = %d \n", errno);
fprintf(stderr, "Error description : %s\n",strerror(errno));
exit(2);
}
Edit: With that incorrect code out of the way, there's this:
id = new char(IW_ESSID_MAX_SIZE+1);
Perhaps you meant:
id = new char[IW_ESSID_MAX_SIZE+1];
The former allocated only a single character and sets its value to IW_ESSID_MAX_SIZE+1. The latter allocates an array of size IW_ESSID_MAX_SIZE+1.
With that change, the code works for me and does not give an error for the ioctl.