Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Use of SIOCSDRVSPEC and struct ifdrv: (1 Item)
   
Use of SIOCSDRVSPEC and struct ifdrv  
Hi,

In my io-pkt driver, I want to use the ioctl SIOCSDRVSPEC command to configure driver specific properties.

I've got to the point where the driver is able to accept the SOICSDRVSPEC command.  It can read the struct ifdrv 
memebers correctly except for ifd_data.

Here is the code of the ioctl caller:

    struct ifdrv ifd;
    int data;
    int fd;

    data = 73;

    strcpy(ifd.ifd_name, "test0");
    ifd.ifd_cmd = TEST;
    ifd.ifd_len = sizeof(data);
    ifd.ifd_data = (void*)&data

    fd = socket(AF_INET, SOCK_DGRAM, 0);
    result = ioctl(fd, SIOCSDRVSPEC, &ifd);
    if (-1 == result) {
        perror(NULL);
    }


driver ioctl handler code:

switch(cmd) {
        case SIOCSDRVSPEC:
            ifd = (struct ifdrv *)data;
            switch(ifd->ifd_cmd) {
                case TEST:
                    slogf(_SLOG_SETCODE(_SLOGC_NETWORK_MOST, 0), _SLOG_DEBUG1, "received RIOCAIFCHANNEL: len = %d, data 
= %d", ifd->ifd_len, *(int*)ifd->ifd_data);
                    break;
                default:
                    break;
            }
            break;
            ...
}

The interface always receives ifd_cmd and ifd_len with the correct values, while ifd->ifd_data always points to some 
unknown memory location and sometimes brings down io-pkt.  Dynamically allocating memory for ifd_data in the ioctl 
caller makes no difference.

ifd_data is a void pointer, so ioctl should be taking the address of my input data and send a copy of that data into io-
pkt memory space, in turn to my driver, for consumption, is that not correct?

Any help or insight is appreciated.