Created attachment 144963 [details] sample program to reproduce problem I have application that sends socket FD from one process to another using sendmsg API and receives that FD using recvmsg API. It works perfectly on FreeBSD 6 (i386-32 bits binary) but fails on FreeBSD 9.2 (amd64-64 bits binary) . The recvmsg API does not fail but the FD, that is retuned, is no longer socket FD hence further use of that FD fails with EBADF error. Has anyone faced this problem before? Is this a known issue? I have tried simple program that uses Unix domain socket and shares FD between 2 processes. It reproduces my problem. The program open file '/etc/motd' and sends the FD to another process using sendmsg. The other process receives the FD and prints the contents of the file. The program works perfectly on FreeBSD 6 (i386-32 bits binary) but fails to print contents of file on FreeBSD 9.2 (amd64-64 bits binary).
Created attachment 144986 [details] fixed reproducer
Your code is incorrect and works on i386 only by chance. It should use CMSG_ macros to fil up data. I modified your reproducer to use it in a least-resistant way and everything seems to be working fine.