Wireshark-dev: Re: [Wireshark-dev] Building libsmi from SVN as a .dll
From: Andrew Hood <ajhood@xxxxxxxxx>
Date: Wed, 16 Apr 2008 09:22:38 +1000
Anders Broman wrote:
> Hi,
> I have experemented with building libsmi.dll from libsmi SVN
> _http://www.ibr.cs.tu-bs.de/svn/libsmi_ with the included makefile-dll
> and smi.def file
> 
> It builds under MSVC6 I have not tested it but if some one likes to play
> with it - here it is...
> If you find any errors please let me know.

I've managed to get your makefile to work with MSVC8. My version
attached. A few more -Dxxx make the compiler and linker happy.

Adding smiFree to smi.h and EXPORTing it from the DLL lets the memory
that is currently being leaked be freed. Juergen agrees this is OK. If
have added these to smi.h and EXPORTed them:

extern void *smiMalloc(size_t size);
extern void *smiRealloc(void *ptr, size_t size);
extern char *smiStrdup(const char *s1);
extern char *smiStrndup(const char *s1, size_t n);
extern void smiFree(void *ptr);

I think I have also tracked down one of the reasons wireshark crashes.
Take this snippet:

ICS3-MIB DEFINITIONS ::= BEGIN

IMPORTS
    OBJECT-TYPE
        FROM RFC-1212
    TRAP-TYPE
        FROM RFC-1215
    westellInterchangeProducts
        FROM WESTELL-GENERAL-MIB;

ics3 OBJECT IDENTIFIER
    ::= { westellInterchangeProducts 2 2 }


smilint gives this warning.

./ICS3-MIB:16: warning: implicit node definition

At line 595 oids.c calls smiRenderOID to format the node. The implicit
node is not completely filled in, and wireshark/tshark crashes in
libsmi. This is not totally unreasonable since implicit nodes should
never be seen. Adding:

if (kind == OID_KIND_UNKNOWN) continue;

(you will have to separate the declarations and initialisations of oid
and oid_data) before that call stops the crash.

-- 
There's no point in being grown up if you can't be childish sometimes.
                -- Dr. Who
#
# makefile --
#
#       Makefile for VC++ (tested with version 6.0) for compiling
#	libsmi and associated tools natively under Win32.
#
# Copyright (c) 2000-2003 Yigal Hochberg, DMH Software.
# Copyright (c) 2000 E. Schoenfelder, Gaertner Datensysteme Braunschweig.
# Copyright (c) 2000 J. Schoenwaelder, Technical University of Braunschweig.
#
# See the file "COPYING" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# @(#) $Id: makefile 3226 2006-02-27 21:48:23Z schoenw $

##
## Project directories -- these may need to be customized for your site
##
## ROOT --	top of the source tree.
## TMPDIR --	location for .obj files.
## TOOLS32 --	location of VC++ compiler installation.
##
ROOT	= .\..
TMPDIR	= .
#TOOLS32	= C:\MSDEV
#TOOLS32	= C:\PROGRA~1\MICROS~2\VC98
TOOLS32	= "C:\Program Files\Microsoft Visual Studio 8\VC"

##
## Installation paths: 
##
## MIBROOT  -- definition for default search path (unix-style)
## MIBDIR   -- same in windows style
## PIBDIR   -- same in windows style
## BINDIR   -- destination for the binaries (smidump.exe, ...)
## LIBDIR   -- destination for the library (smi.lib)
##
MIBROOT = c:/usr/local/snmp/mibs
PIBROOT = c:/usr/local/snmp/pibs
INSTROOT = c:\usr\local
MIBDIR = $(INSTROOT)\snmp\mibs
PIBDIR = $(INSTROOT)\snmp\pibs
BINDIR = $(INSTROOT)\wbin
LIBDIR = $(INSTROOT)\wbin

##
## Visual C++ tools
##
PATH=$(TOOLS32)\bin;$(PATH)

cc32	= cl
CP      = copy
RM      = del
MKDIR	= -mkdir

##
## Definitions:
##
# DEBUG = -W3 -Zi -Od /Yd
DEBUG = /W3 /Zi /Od /DEBUG /GS /Wp64 /Yd
INCLUDES = -I$(ROOT)\lib -I$(ROOT)\win -I$(TOOLS32)\include
DEFINES = $(DEBUG) -D_CRT_SECURE_NO_DEPRECATE=1

!include <win32.mak>

## 
## Global makefile settings
##

LIBSMIOBJS =					\
	$(TMPDIR)\win.obj			\
	$(TMPDIR)\shhopt.obj			\
	$(TMPDIR)\data.obj			\
	$(TMPDIR)\check.obj			\
	$(TMPDIR)\error.obj			\
	$(TMPDIR)\util.obj			\
	$(TMPDIR)\smi.obj			\
	$(TMPDIR)\parser-smi.obj		\
	$(TMPDIR)\scanner-smi.obj		\
	$(TMPDIR)\parser-sming.obj		\
	$(TMPDIR)\scanner-sming.obj		\
	$(TMPDIR)\snprintf.obj

SMIQUERYOBJS =					\
	$(TMPDIR)\smiquery.obj			\

SMILINTOBJS =					\
	$(TMPDIR)\smilint.obj			\

SMIXLATEOBJS =					\
	$(TMPDIR)\smixlate.obj			\
	$(TMPDIR)\dstring.obj			\

SMIDUMPOBJS =					\
	$(TMPDIR)\smidump.obj			\
	$(TMPDIR)\dump-sming.obj		\
	$(TMPDIR)\dump-smi.obj			\
	$(TMPDIR)\dump-imports.obj		\
	$(TMPDIR)\dump-types.obj		\
	$(TMPDIR)\dump-tree.obj			\
	$(TMPDIR)\dump-mosy.obj			\
	$(TMPDIR)\dump-corba.obj		\
	$(TMPDIR)\dump-netsnmp.obj		\
	$(TMPDIR)\dump-jax.obj			\
	$(TMPDIR)\dump-xml.obj			\
	$(TMPDIR)\dump-cm.obj			\
	$(TMPDIR)\dump-metrics.obj		\
	$(TMPDIR)\dump-identifiers.obj		\
	$(TMPDIR)\dump-python.obj		\
	$(TMPDIR)\dump-perl.obj			\
	$(TMPDIR)\dump-scli.obj			\
	$(TMPDIR)\dump-xsd.obj			\
	$(TMPDIR)\dump-sppi.obj			\
	$(TMPDIR)\dump-sizes.obj		\
	$(TMPDIR)\dump-svg.obj			\
	$(TMPDIR)\dump-compliance.obj		\
	$(TMPDIR)\dump-boilerplate.obj		\
	$(TMPDIR)\dump-yang.obj			\
	$(TMPDIR)\fprint.obj			\
	$(TMPDIR)\rea.obj			\
	$(TMPDIR)\fortopat.obj			

SMIDIFFOBJS =					\
	$(TMPDIR)\smidiff.obj			\

SMILIB = smi.lib
SMIDLL = smi.dll

##
## Implicit Targets
##
.c.obj:
	$(cc32) $(cdebug) $(cflags) $(INCLUDES) \
		$(DEFINES) -Fo$(TMPDIR)\ $<

{$(ROOT)\lib}.c{$(TMPDIR)}.obj:
	$(cc32) $(cdebug) $(cflags) -D_DLL -D_MT /MD $(INCLUDES) \
		 -DYYMALLOC=malloc -DYYFREE=free \
		$(DEFINES) -Fo$(TMPDIR)\ $<

{$(ROOT)\tools}.c{$(TMPDIR)}.obj:
	$(cc32) $(cdebug) $(cflags) -D_DLL -D_MT /MD $(INCLUDES) \
		$(DEFINES) -Fo$(TMPDIR)\ $<

##
## Targets
##
all:	libs tools

libs:	$(SMILIB) $(SMIDLL)

# special compilation rules
# (flex-src avoids missing unistd.h if _Win32 defined)
#
$(TMPDIR)\scanner-smi.obj : $(ROOT)\lib\scanner-smi.c
	$(cc32) $(cdebug) $(cflags) -D_DLL -D_MT /MD -D_Win32 -D__STDC__ $(INCLUDES) \
		-DYY_NEVER_INTERACTIVE \
		$(DEFINES) -Fo$(TMPDIR)\ $?

$(TMPDIR)\scanner-sming.obj : $(ROOT)\lib\scanner-sming.c
	$(cc32) $(cdebug) $(cflags) -D_DLL -D_MT /MD -D_Win32 -D__STDC__ $(INCLUDES) \
		-DYY_NEVER_INTERACTIVE \
		$(DEFINES) -Fo$(TMPDIR)\ $?

$(SMIDLL): $(SMILIB)
#	$(link) -entry:_DllMainCRTStartup@12  -dll /NODEFAULTLIB /INCREMENTAL:NO /PDB:NONE /RELEASE /NOLOGO msvcrt.lib oldnames.lib kernel32.lib  ws2_32.lib shell32.lib /DEF:smi.def /OUT:$(SMIDLL) /IMPLIB:$(SMILIB) $(LIBSMIOBJS)
        link  $(dlllflags) $(conlibsdll) /NODEFAULTLIB /machine:i386 msvcrt.lib shell32.lib version.lib /DEBUG /DEF:smi.def /OUT:smi.dll  /IMPLIB:smi.lib   $(LIBSMIOBJS)

		
$(SMILIB):	$(LIBSMIOBJS)
	$(implib) /out:smi.lib $(LIBSMIOBJS)

tools:	smiquery.exe smilint.exe smixlate.exe smidump.exe smidiff.exe

smiquery.exe:	$(SMIQUERYOBJS) $(SMILIB)
	$(cc32) $(DEFINES) /osmiquery.exe $(SMIQUERYOBJS) $(SMILIB)

smilint.exe:	$(SMILINTOBJS) $(SMILIB)
	$(cc32) $(DEFINES) /osmilint.exe $(SMILINTOBJS) $(SMILIB)

smidump.exe:	$(SMIDUMPOBJS) $(SMILIB)
	$(cc32) $(DEFINES) \
		/osmidump.exe $(SMIDUMPOBJS) $(SMILIB)

smidiff.exe:	$(SMIDIFFOBJS) $(SMILIB)
	$(cc32) $(DEFINES) \
		/osmidiff.exe $(SMIDIFFOBJS) $(SMILIB)

smixlate.exe:	$(SMIXLATEOBJS) $(SMILIB)
	$(cc32) $(DEFINES) \
		/osmixlate.exe $(SMIXLATEOBJS) $(SMILIB)

clean:
	rm -f *.lib
	rm -f *.obj
	rm -f *.exe
	rm -f *.ilk
	rm -f *.pdb
	rm -f *.mdp

install:	all install-doc install-bin install-lib install-mibs install-pibs

install-doc:
	$(MKDIR) $(INSTROOT)
	$(CP) ..\README $(INSTROOT)
	$(CP) ..\COPYING $(INSTROOT)
	$(CP) README.win $(INSTROOT)
	$(MKDIR) $(INSTROOT)\doc
	$(CP) ..\doc\*.txt $(INSTROOT)\doc
	$(CP) ..\doc\*.ps $(INSTROOT)\doc

install-bin:
	$(MKDIR) $(BINDIR)
	$(CP) *.exe $(BINDIR)

install-lib:
	$(MKDIR) $(LIBDIR)
	$(CP) *.lib $(LIBDIR)

install-mibs:
	$(MKDIR) $(MIBDIR)
	$(MKDIR) $(MIBDIR)\iana
	$(CP) ..\mibs\iana\*.* $(MIBDIR)\iana
	$(MKDIR) $(MIBDIR)\ietf
	$(CP) ..\mibs\ietf\*.* $(MIBDIR)\ietf
	$(MKDIR) $(MIBDIR)\irtf
	$(CP) ..\mibs\irtf\*.* $(MIBDIR)\irtf
	$(MKDIR) $(MIBDIR)\tubs
	$(CP) ..\mibs\tubs\*.* $(MIBDIR)\tubs
	$(MKDIR) $(MIBDIR)\site


install-pibs:
	$(MKDIR) $(PIBDIR)
	$(MKDIR) $(PIBDIR)\ietf
	$(CP) ..\pibs\ietf\*.* $(PIBDIR)\ietf
	$(MKDIR) $(PIBDIR)\tubs
	$(CP) ..\pibs\tubs\*.* $(PIBDIR)\tubs
	$(MKDIR) $(PIBDIR)\site


#
# Local Variables:
# mode: makefile
# make: "nmake"
# eval: (set (make-local-variable 'this-file) (file-name-nondirectory buffer-file-name))
# eval: (set (make-local-variable 'compile-command) (concat make " -k -f " this-file))
# End:
#


# EOF: makefile