Here's how I find the IF index. If you check out last weekend's mail, you'll
find examples of creating the socket, binding (with info gotten from this method),
and sending (with a NULL 'to' address, because we already bound..). Receiving
is simply done with the recvfrom (used with select of course.)
int findDeviceIndex(const char* device_name) {
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, device_name, IFNAMSIZ); //max length of a device name.
int ioctl_sock = socket(AF_INET, SOCK_STREAM, 0);
if (ioctl_sock >= 0) {
if (ioctl(ioctl_sock, SIOCGIFINDEX, &ifr) >= 0) {
VLOG << "Found index for dev: " << device_name << ", was: "
<< ifr.ifr_ifindex << endl;
close(ioctl_sock);
return ifr.ifr_ifindex;
}
else {
VLOG << "ERROR: couldn't find socket: " << strerror(errno) << endl;
close(ioctl_sock);
}
}
return -1;
}
Vijay Thirumalai wrote:
> > I tried doing this and it says device not configured.....i would appreciate if you
>could
> > throw some pointers...and how do u obtain dev_idx.......maybe i am messing up
>there...i
> > directly write the interface name into the sll_addr ....thanks alot
> > -VJ
--
Ben Greear ([EMAIL PROTECTED]) http://www.candelatech.com
Author of ScryMUD: scry.wanfear.com 4444 (Released under GPL)
http://scry.wanfear.com http://scry.wanfear.com/~greear
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]