bind() to /dev/log failed
Mansuri, Wasim (NSN - IN/Bangalore)
wasim.mansuri at nsn.com
Thu Jul 22 06:29:56 UTC 2010
Hello All,
I want to listen to /dev/log. For that I am using the following code.
Please let me know whats the issue in the following code snip. Code I am running with root user.
Thanks, wasim
if ((sockfd = socket(AF_UNIX,SOCK_STREAM, 0)) == -1)
{
printf("Failed To open AF_UNIX Socket");
return -1;
}
sunx.sun_family = AF_UNIX;
strncpy(sunx.sun_path, PR_PATH_LOG, sizeof(sunx.sun_path));
/*if (connect(sockfd, &syslog_addr, sizeof(syslog_addr)) == -1) { //Connect call goes successful, But after that I am not able to recv any data.*/
if (bind(sockfd, (struct sockaddr *) &sunx,sizeof(sunx.sun_family)+strlen(sunx.sun_path)) < 0) { /* bind fails saying 98 : Address already in use Even if I kill syslogd*/
printf("Connect failed with the errno %s %d : %s\n",PR_PATH_LOG, errno,strerror(errno));
close(sockfd);
}
if(recv( sockfd, (void *) buff, 1024,0) <=0) /* recv never come out if I use connect even after I do logger */
{
printf("Error in recv call... errno = %d : %s : %s\n", errno, strerror(errno),buff);
break;
}
More information about the users
mailing list