Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Kext control




The code looks correct (eyes sometimes miss things that the computer running the code doesn't miss though). The mechanism should work fine. If you are concerned about getting the right control id, you can verify it. After calling ctl_register, the ep_ctl.ctl_id should be set to the id that was dynamically assigned. You can print this out using a printf and it should show up in the system log (/var/log/system.log). You can also print out the value before you call connect in user space to verify the two match. I would be surprised if this is where your problem lies. If you specified an invalid value, the connect would fail.

-josh

On Apr 26, 2006, at 3:00 PM, David A Rowland wrote:

I have an app and a kernel extension that should communicate. It isn't happening, and I don't know why.

I have adapted the sample code in the Network Kernel Extensions Programming Guide, 2005-8-11.

The kext loads and registers itself apparently successfully:

    bzero(&ep_ctl, sizeof(ep_ctl));
    ep_ctl.ctl_id =
0; /* OLD STYLE: ep_ctl.ctl_id = kEPCommID; */
    ep_ctl.ctl_unit =
0;
       
if (strlen(MYCONTROLNAME) >= MAX_KCTL_NAME)
            printf(
"Name too long");
    strcpy(ep_ctl.ctl_name, MYCONTROLNAME);
    ep_ctl.ctl_flags = 0;
    ep_ctl.ctl_connect = EPHandleConnect;
    ep_ctl.ctl_disconnect = EPHandleDisconnect;
    ep_ctl.ctl_send = EPHandleWrite;
    ep_ctl.ctl_setopt = EPHandleSet;
    ep_ctl.ctl_getopt = EPHandleGet;
    errno_t error = ctl_register(&ep_ctl, &kctlref);


The application opens a socket:

    fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
issues an ioctl to find out about the kext, again with apparent success:

    struct ctl_info info;
    memset(&info,
0, sizeof(info));
    assert (strlen(MYKEXTNAME) < MAX_KCTL_NAME);
    strcpy(info.ctl_name, MYKEXTNAME);
   
int err;
   
if (ioctl(fd, CTLIOCGINFO, &info)) {
        err = errno;
        printf("Could not get ID for kernel control. %d\n", err);
        return(err);
    }
    addr.sc_id = info.ctl_id;
    addr.sc_unit = 0;

then it does a connect:

            result = connect(fd, (struct sockaddr *)&addr, sizeof(addr));

with no error reported.

However, the EPHandleConnect routine is never called, and when I try getsockopt and setsockopt, they don't seem to reach the kext either. I wonder if I am setting the the sc_id in the addr struct correctly.

Has anyone made this sample code work? I'm suspicious of it because of a number of typos I found.

David
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden

References: 
 >Kext control (From: David A Rowland <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.