[nmsg-dev] nmsg 0.6.8 patch for OSX

Matt Thompson mthompson at defintel.com
Mon Aug 16 20:53:33 UTC 2010

On 10-08-16 3:37 PM, Robert Edmonds wrote:
> Matt Thompson wrote:
>> It works great. OSX has a POSIX dlopen(). ELF/ABI doesn't matter so
>> long as dlsym provides the pointers and the compiler does its job.
>> OSX no longer requires dlcompat as of 10.4. the build system creates
>> .so file extensions rather than .dylib but dlopen() handles them
>> just fine.
> that is very interesting.  when i tried building on darwin 8 libtool
> produced .dylib files for me.  did you have to make any modifications to
> the build system (autoreconf with apple-branded autotools, etc.) in
> order to get this to work, or did this work with the pre-compiled
> autoconf scripts that come in the nmsg distribution tarballs?
I did an autoreconf to apply the changes to the m4 macro.

However it looks like their libtool uses the .so extension when invoked 
with the -module argument:

# Shared library suffix (normally ".so").
shrext_cmds="\`test .\$module = .yes && echo .so || echo .dylib\`"
>> I would be happy to test and provide patches in the future for OSX
>> as it is my main dev machine and have a local nmsg broadcast stream
>> on my desk. I believe that none of the changes are applicable to OSX
>> specifically (I haven't tested nmsg on any *BSD systems but I
>> suspect they lack struct icmphdr as well).
> we use nmsg on a lot of freebsd machines, so it works there.  i'll see
> about modifying the libnmsg internals to use system-independent
> definitions for the network header structures that we need.  that ought
> to work for you?
The struct icmphdr type is defined on FreeBSD.

One thing to note about struct icmphdr:

On FreeBSD:

struct icmphdr {
     u_char  icmp_type;              /* type of message, see below */
     u_char  icmp_code;              /* type sub code */
     u_short icmp_cksum;             /* ones complement cksum of struct */

On Linux:

struct icmphdr
   u_int8_t type;     /* message type */
   u_int8_t code;     /* type sub-code */
   u_int16_t checksum;
       u_int16_t   id;
       u_int16_t   sequence;
     } echo;       /* echo datagram */
     u_int32_t  gateway; /* gateway address */
       u_int16_t   __unused;
       u_int16_t   mtu;
     } frag;       /* path mtu discovery */
   } un;

Therefore sizeof(struct icmphdr) is not equal between the two systems (4 
on FBSD, 8 on Linux). Gets even uglier if you try to dereference the 
struct since they use different member naming :) The joys of cross 

My patch would also be incorrect if you intended to get the sizeof the 
FBSD declaration. I'm not exactly clear on the purpose of the icmp 
header length in nmsg but I would assume you would only want the 4 byte 
header. Linux for whatever reason has the header struct spanning an echo 
type payload.

It should be offsetof(struct icmp, icmp_hun) (Which is compatible with 
Linux, FreeBSD, and OSX)

All that aside, I agree that system independent declarations of network 
headers is the proper solution. If you would like any help with this let 
me know.


More information about the nmsg-dev mailing list