Results 1 to 2 of 2
Hello,
Can any please help me for " how to send and recv ancillary data using msghdr option"
I have tried . But I am not how to get the ...
- 07-19-2007 #1Just Joined!
- Join Date
- Jul 2007
- Posts
- 15
Sending ancillary data
Hello,
Can any please help me for " how to send and recv ancillary data using msghdr option"
I have tried . But I am not how to get the same.
Below is my code sniffet.
client application
char buf[256] = "cyber";
char buffer[256] = "srini"
struct msghdr msg;
struct cmsghdr *cmsg;
struct iovec iov[iovlen];
char buf1[CMSG_SPACE(sizeof (int))];
memset(&msg, 0, sizeof msg);
memset(buf1, 0, sizeof buf1);
iov[0].iov_base = buf;
iov[0].iov_len = sizeof buf;
msg.msg_name = (struct sockaddr *)&addr_srvr;
msg.msg_namelen = sizeof addr_srvr;
msg.msg_iov = iov;
msg.msg_iovlen = iovlen;
msg.msg_flags = 0;
msg.msg_control = buf1;
msg.msg_controllen = sizeof buf1;
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = CMSG_LEN (sizeof (int));
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
msg.msg_controllen = cmsg->cmsg_len;
*((char *)CMSG_DATA(cmsg)) = buffer[256];
printf("\n.................udpdata................ .........................\n");
if(sendmsg(appdata->sk[n].sock_id, &msg,0 )< 0)
{
printf("writing failed:%d\n",errno);
perror("");
}
SERVER APPLICATION:
char buffer[256] ;
char buf[512];
struct msghdr msg;
struct iovec iov[iovlen];
struct cmsghdr *cmsg;
struct ucred *credp;
char buf1[CMSG_SPACE(sizeof (int))];
memset(&msg, 0, sizeof msg);
//memset(buf1, 0, sizeof buf);
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = iovlen;
iov[0].iov_base = buffer;
iov[0].iov_len = sizeof buffer;
msg.msg_control = buf1;
msg.msg_controllen = sizeof (buf);
cmsg = CMSG_FIRSTHDR (&msg);
cmsg->cmsg_len = CMSG_LEN (sizeof (int));
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
y= recvmsg(Appdata->sk.sock_id, &msg,0);
if(y < 0)
{
printf("error");
}
int fd;
buf1[256] = *((char *) CMSG_DATA (cmsg));
printf("Recieved %d bytes from the client \n ",y);
printf("This is the message:%s\n",buf1);
printf("This is the message:%s\n",buffer);
printf("\n........................................ .....\n");
}
Please let me know what would be the difference in TCP and UDP for send and recv ancillary data. How to check the ancillary data is send/recv, and I am capturing all the packets using ethereal.
Thanks!
Cyber
- 07-21-2007 #2Just Joined!
- Join Date
- Nov 2004
- Posts
- 4
passing ancillary data
Hi,
cmsg(3) says "See the specific protocol man pages for the available control message types." And I think only unix(7) actually supports passing ancillary data. See the respective man-page. Also you didn't provide the complete source code, from your question about tcp and udp difference, I guess, you were not using a unix socket.
Regards
Guennadi


Reply With Quote