I've been trying to receive ancillary data using TIPC 1.5.12 on a linux
2.6.9 kernel, but I always seem to get ancillary data with the cmsg_len,
cmsg_level and cmsg_type set to 0 and the data set to '\0'.
I've included the receive code that I'm using below. This is a modified
version of the hello_world program where I don't have the server up and
running and so the message is rejected back to the client. That is
happening as planned. I can see recvmsg is returning 0, but when I try
to look at the ancillary data, the message type is always 0. Any ideas?
Thanks for any help,
Felix
char recvbuf[2000];
memset (recvbuf, 0 , sizeof(recvbuf));
struct iovec iovrecv[1]; //define an iovec structure
containing 1 entry (1 msg)
struct msghdr msgrecv; //iovec structure shall be
stored in the msghdr
memset (&msgrecv, 0, sizeof(msgrecv));
memset (iovrecv, 0, sizeof(iovrecv));
iovrecv[0].iov_base=recvbuf;
iovrecv[0].iov_len= sizeof(recvbuf);
msgrecv.msg_iov= iovrecv; //the actual message
msgrecv.msg_iovlen = 1; //only one element in msg_iov
//Set the length to the sum of the possible payloads:
//8 bytes fo the ErrorCode, 1024 bytes for the returned
//message and 12 bytes for the destination address
const socklen_t ancBufSize = CMSG_SPACE(8) +
CMSG_SPACE(1024) +
CMSG_SPACE(12);
//Setup the structure needed to capture ancillary data
char anc_buf[ancBufSize];
memset(&anc_buf, 0, sizeof(anc_buf));
msg.msg_control = anc_buf; //ancillary buffer for
holding the returned message
msg.msg_controllen = ancBufSize;
fd_set fds;
struct timeval tv;
FD_ZERO(&fds);
FD_SET(sd, &fds);
tv.tv_sec = 0;
tv.tv_usec = 1;
struct tipc_name_seq tipcNameSeq;
// Try to receive messages
int r = select(sd + 1, &fds, 0, 0, &tv);
if (r > 0 && FD_ISSET(sd, &fds))
{
int recvsize = (recvmsg(sd, &msgrecv, 0));
if (0 == recvsize){
struct cmsghdr *anc;
anc = CMSG_FIRSTHDR(&msg);
while (anc != NULL) {
printf("The message type is %i \n",
anc->cmsg_type); //Always prints 0
if (anc->cmsg_type == TIPC_DESTNAME) {
printf("Got here!\n"); //Never get here
tipcNameSeq = *((struct tipc_name_seq
*)(CMSG_DATA(anc)));
printf("Client Received Returned Message
from: <%i,%i,%i> /n",
tipcNameSeq.type,
tipcNameSeq.lower, tipcNameSeq.upper);
break;
}
anc = CMSG_NXTHDR(&msg, anc);
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
tipc-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tipc-discussion