Hi Folks,
I'm trying to write a library that will change various network adapter
parameters, such as ip address. I've grabbed
the source for net-tools and have used portions of it, but I'm having a
problem. My lib opens a socket and gets back a
file descriptor (27). When I try and do an ioctl(fd, SIOCSIFADDR,
&ifr); I always get an error
r = ioctl(fd, SIOCSIFADDR, &ifr);
if (r < 0 )
perror("SIOCSIFADDR");
I always get SIOCSIFADDR: Operation not supported by device
Here is the code block in my lib. This lib is a C library that gets
called from Java.
The functions in here are in the libnet-tools lib.
when I run ifconfig, the fd it always gets for fd is always 4. In my
lib its always a large #.
any ideas ?
ife = lookup_interface(iface_name);
resp = do_if_fetch(ife);
if (resp >=0)
{
ap = get_aftype(DFLT_AF);
if (ap == NULL)
ap = get_aftype("inet");
if (ap->input(0, ipaddr, &sa) <0) {
ap->herror(ipaddr);
}
memcpy((char *) &ifr.ifr_addr, (char *) &sa, sizeof(struct
sockaddr));
{
int r = 0; /* to shut gcc up */
switch (ap->af) {
case AF_INET:
fd = get_socket_for_af(AF_INET);
if (fd < 0) {
perror("No support for INET on this system.");
exit(1);
}
r = ioctl(fd, SIOCSIFADDR, &ifr);
if (r < 0 )
perror("SIOCSIFADDR");
break;
...
...