Unix Programming - uncomplete (header) information while recvmsg on a local datagram socket

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2006 > uncomplete (header) information while recvmsg on a local datagram socket





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author uncomplete (header) information while recvmsg on a local datagram socket
param

2006-05-11, 1:17 pm

Hi,

While doing recvmsg on a local datagram socket in AIX 5.3 OS. The data
received through structure msghdr is not having the sender binding
information, which is supposed to hold it in the structure member
msghdr.sun_path. I tried my same program on AIX 5.2, it is giving
(holding) proper sender binding address (path).

Please help me to solve this error.

Program:

Client:

#include <sys/socket.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/un.h>

int main()
{
int sd,size;
struct msghdr msg;
struct iovec iov;
struct sockaddr_un from, to;
char *message="param...";

if((sd=socket(AF_UNIX, SOCK_DGRAM, 0))==-1)
perror("socket"), exit(1);

from.sun_family = AF_UNIX;
strcpy(from.sun_path, "sparam101");
/* size=SUN_LEN(&from); */

if(bind(sd, (struct sockaddr *) &from, sizeof(from))==-1)
perror("bind"), exit(1);
to.sun_family = AF_UNIX;
strcpy(to.sun_path, "sparam");
size=SUN_LEN(&to);

iov.iov_base = message;
iov.iov_len = strlen(message);
msg.msg_name = (void *) &to;
msg.msg_namelen=size; //sizeof(to);
msg.msg_iov=(struct iovec*) &iov;
msg.msg_iovlen=1;
msg.msg_control=NULL;

if(sendmsg(sd, (struct msghdr *)&msg, 0) < 0)
perror("sendmsg"), exit(1);

printf("send is successful\n");
close(sd);
return 0;
}

Server:

#include <sys/socket.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/un.h>

int main()
{
int size, sd;
fd_set fbits;
struct msghdr msg;
struct iovec iov;
struct sockaddr_un from, to;
char message[20];

if((sd=socket(AF_UNIX, SOCK_DGRAM, 0))==-1)
perror("socket"), exit(1);

from.sun_family = AF_UNIX;
strcpy(from.sun_path, "sparam");
size=SUN_LEN(&from);

if(bind(sd, (struct sockaddr *)&from, size)==-1)
perror("bind"), exit(1);

FD_ZERO(&fbits);
FD_SET(sd, &fbits);
if(select(sd+1, (fd_set *) &fbits, (fd_set *)0, (fd_set *)0,
(struct timeval *)0) < 0)
perror("select"), exit(1);

iov.iov_base = message;
iov.iov_len = sizeof(message);
msg.msg_name = &to;
msg.msg_namelen=sizeof(to);
msg.msg_iov=&iov;
msg.msg_iovlen=1;
msg.msg_control=NULL;

if(recvmsg(sd, &msg, 0) < 0)
perror("recvmsg"), exit(1);

printf("%s\n", to.sun_path); /* AIX 5.3 -> print NULL AIX5.2
->print sparam101 */
printf("%s\n", iov.iov_base);
close(sd);
return 0;
}

Param

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com