Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Socket problems in NKE
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Socket problems in NKE



Greetings all,

I can almost talk with my NKE from userland but I'm having socket
problems. I can't get any data from the NKE.

I'm using the AF_SYSTEM domain from <sys/kern_control.h>. It
essentially is registering a protocol handler as a SOCK_DGRAM type.

Then from userland I do this (I've deleted the error checking code
below for brevity):

struct sockaddr_ctl sf;
memset(&sf, 0, sizeof(sf));

m_rpcSock = socket(AF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);

sf.sc_len = sizeof(sf);
sf.sc_family = AF_SYSTEM;
sf.ss_sysaddr = AF_SYS_CONTROL;
sf.sc_id = A1_DARWIN_NKE_SIG;
sf.sc_unit = A1_NKE_UNIT_RPC;

connect(m_rpcSock, (struct sockaddr *)&sf, sizeof(sf);

This all works. I also successfully send one byte of data to the NKE
via:

char dummy = 0;
error = send(m_rpcSock, &dummy, 1, 0);

But then when the userland code call recv() with zero flags it blocks
forever. I then added this diagnostic loop just to verify and recv()
always returns -1 and EAGAIN:

do {
sleep(2);
error = recv(m_rpcSock, ver, sizeof(ver), MSG_DONTWAIT |
MSG_PEEK);
printf("version MSG_PEEK returned X, error %d\n", error,
errno);
} while (error != sizeof(ver));

But the log shows that the NKE does receive the one zero byte and in
response does this:

unsigned short ver[2];

ver[0] = IPC_VERSION;
ver[1] = IPC_MIN_SUPPORTED_VERSION;

error = ctl_enqueuedata(ctlref, ver, sizeof(ver), 0);

printf("RPC version send result = %d\n", error);

The log also shows that the ctl_enqueuedata() call returns zero. (I've
also verified that ctlref is the same one the NKE registered.) So it
should have written data to the socket. I can't figure out why the
userland code cannot receive anything.

I've done this sort of thing in the past using SOCK_RAW but the
infrastructure is forcing me to use SOCK_DGRAM. I expect this to raise
some issues in terms of how I read data from the socket but I can
handle that with MSG_PEEK. But only if I can get data to arrive. If
anyone's done this sort of socket code and could assist I'd appreciate
it.

Thanks,
Mike
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.



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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.