[nmsg-dev] nmsg 0.6.8 patch for OSX

Matt Thompson mthompson at defintel.com
Mon Aug 16 19:30:28 UTC 2010

On 10-08-16 3:04 PM, Robert Edmonds wrote:
> Matt Thompson wrote:
>> I've attached a patch against nmsg 0.6.8 to fix compilation on OSX.
>> This may be required for other BSD systems as well if they lack
>> struct icmphdr in netinet/ip_icmp.h.
>> This compiles fine on at least Debian Linux since Linux also defines
>> the BSD style struct icmp.
>> I replaced sizeof(struct icmphdr) with offsetof(struct icmp,
>> icmp_dun) and changed autoconf/check_net.m4 to check for struct icmp
>> rather than icmphdr.
> i think the amount of autoconf / #ifdef crap required to get these
> structure definitions right across multiple systems exceeds the LOC to
> just detect the system's endianness and define our own structures for
> these network headers.  i'll try to rework this in the next release of
> nmsg.
Agreed. Thank you.
> note, however, that you'll probably need a lot more changes to make nmsg
> work on OS X; in particular, the module loader assumes a relatively sane
> posix/ELF system with dlopen() and DSOs with filenames that end in
> ".so".
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.

Matt-Thompsons-MacBook-Pro:~ fuzzy$ uname -a
Darwin Matt-Thompsons-MacBook-Pro.local 10.4.0 Darwin Kernel Version 
10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 
i386 i386

Matt-Thompsons-MacBook-Pro:~ fuzzy$ /opt/nmsg/bin/nmsgtool -l -c 2
[47] [2010-08-16 19:13:18.272418000] [4:1 Defintel sink] [00000000] [] []
group: 10000
rule: 1

[61] [2010-08-16 19:13:18.272438000] [4:1 Defintel sink] [00000000] [] []
group: 10000
rule: 2

Matt-Thompsons-MacBook-Pro:~ fuzzy$ ls -las /opt/nmsg/lib/nmsg/
total 3760
    0 drwxr-xr-x  8 root  admin      272 16 Aug 14:37 .
    0 drwxr-xr-x  7 root  admin      238 16 Aug 13:59 ..
   40 -rw-r--r--  1 root  admin    18904 16 Aug 14:37 nmsg_msg7_defintel.a
    8 -rwxr-xr-x  1 root  admin     1021 16 Aug 14:37 nmsg_msg7_defintel.la
   24 -rwxr-xr-x  1 root  admin    11216 16 Aug 14:37 nmsg_msg7_defintel.so
3024 -rw-r--r--  1 root  admin  1547176 16 Aug 13:59 nmsg_msg7_isc.a
    8 -rwxr-xr-x  1 root  admin      939 16 Aug 13:59 nmsg_msg7_isc.la
  656 -rwxr-xr-x  1 root  admin   334896 16 Aug 13:59 nmsg_msg7_isc.so

> also note that i'm not particularly interested in supporting a closed
> source operating system like OS X.  at one point i had darwin 8 running
> in a qemu virtual machine but it was sloooow and made testing extremely
> difficult, and now i can't even find the download link on apple.com for
> the installer that i used.  it seems apple is scrubbing almost all
> mentions of darwin from their websites, and of course they don't make
> installers for newer versions of darwin available now.
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).
>> OSX uses a macro for snprintf(). The source file src/argv.c
>> LOC_SNPRINTF and SNP_ARGS macros are being evaluated after the
>> snprintf() macro resulting in argument errors during compilation.
>> I implemented a static wrapper func named loc_snprintf() around
>> vsnprintf that the LOC_SNPRINTF() macro is defined to.
> the upstream author of the argument parsing code in nmsgtool is gray
> watson:
>      http://256.com/sources/argv/
> could you please submit the patch to him and ask that it be applied
> upstream?  he was very responsive when i reported a memory corruption
> bug earlier this year.
I will submit the patch to him.

Thanks Robert.

Matt Thompson

More information about the nmsg-dev mailing list