Re: Socket problems in NKE
Re: Socket problems in NKE
- Subject: Re: Socket problems in NKE
- From: Christophe Allie <email@hidden>
- Date: Sat, 19 Oct 2002 00:05:28 -0700
Michael,
What you do is correct, but apparently the ctl_enqueuedata() function is
buggy. It creates an mbuf with you data but doesn't set the len of the mbuf.
Using ctl_enqueuembuf() for the time being. I should just work fine.
Christophe.
On 10/18/02 4:16 PM, "Michael Cashwell" <email@hidden> wrote:
>
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.
_______________________________________________
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.