Re: bind() to /dev/log failed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/22/2010 02:29 AM, Mansuri, Wasim (NSN - IN/Bangalore) wrote:
>
> 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;
> }
>   
I'm not 100% understanding exactly what you want to do. First, I think
you should use 'PF-INET' not 'AF_UNIX'.
In any case, the sequence of calls should be:
socket(2), bind(2), listen(2), accept(2), recv(2).

The connect(2) function is used on the sending side.

You can use the lsof(8) command to see if that socket is already in use.


-- 
Jerry Feldman <gaf@xxxxxxx>
Boston Linux and Unix
PGP key id: 537C5846
PGP Key fingerprint: 3D1B 8377 A3C0 A5F2 ECBB  CA3B 4607 4319 537C 5846


Attachment: signature.asc
Description: OpenPGP digital signature

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux