Kext control
Kext control
- Subject: Kext control
- From: David A Rowland <email@hidden>
- Date: Wed, 26 Apr 2006 15:00:53 -0700
Title: Kext control
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