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



David,

There is one difference which I note in the code below. For the kext you use

    strcpy(ep_ctl.ctl_name, MYCONTROLNAME);


for the user client, you use

    strcpy(info.ctl_name, MYKEXTNAME);

If they are not the same, then the tool will never see the kext.

rich

At 3:00 PM -0700 4/26/06, 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:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden


-- Sincerely, Rich Kubota email@hidden (408) 974-6212 _______________________________________________ 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.