Pete Wilson : Consultant Software Engineer

Lowell MA   978.454.4547   pete at pwilson dot net    April 2009

 Home/Résumé  
 Sample code 
 Experimental 
 SNMP 
 CGI notes 
 CSS notes 
 Standards 
 Books 
  Virus Alerts  
 wildcards  
 getopt() 
 safe strings 
 kbhit() 
 cli 
 snmp 

Summary

Sample code: please take a look at this code and, if you find it useful, you're very free to download, use, and distribute it. All code on the site is free to use.
  1. wildcards
  2. getopt
  3. safe strings
  4. kbhit
  5. cli
  6. snmp

Sample code for free

String-compare function understands wildcards: wc_strncmp()


Capable, portable (Unix/Win32/RTOS) C-language strncmp() function that honors and correctly interprets the wildcard characters '*' and '?'.
 wc_strncmp.c string compare with wildcards
 wc_strncmp.h error-code definitions; included by wc_strncmp.c and its callers
 makefile vanilla Unix makefile

Command line options parser for Win32: getopt()


Port of GNU getopt() to Win32 for anyone who's tired of dealing with getopt() calls in Unix-to-Windows ports.
C file getopt.c Win32 getopt()
H file getopt.h included by getopt.c and its callers
man page Usage GNU getopt() man page

Safe string functions: st4ncat() and st4ncpy()


I've tripped myself up with the length-bounded string cat/cpy functions forever: strncat() and strncpy() can silently write unterminated destination strings. I'm aiming for bulletproof code, so I'm starting to use and to talk up the safer functions st4ncat() and st4ncpy().
editorial Discussion Why strncat() and strncpy() are dangerous
strncat4.c st4ncat.c Safe string cat
strncpy4.c st4ncpy.c Safe string copy
placeholder for slprintf.c slprintf.c Another rascal: snprintf(). Here's a safer version

Single-character keyboard input for Linux and Unix


Sources of the MS-Windows kbhit() function that runs under Linux and most flavors of Unix.
Source: kbhit.c  kbhit.c Complete C-language source file, including test code in main().

Portable, embeddable CLI package


Highly configurable, extensible, and portable CLI package for embedded systems management. A snap to port and integrates with SNMP- and HTTP-based local/remote management. I developed this C-language package with gcc and with MS Visual Studio 6.
Runs in a Win32 console  cli.exe
 56kb
Win32 demo .exe file runs from a console window. It's not ready for prime demo time, and it's documented only in its internal "help" commands: very sorry for that! I'll make this demo more intuitive, self-documenting, and generally spiffier shortly.
MSVC++ project: CLI.zip cli.zip The entire MSVC++6.0 CLI project, zipped up, with sources that you can modify and extend so as to include and try out whatever new commands you like.

SNMP tools, utilities, and libraries


It's nice to have a library of functions you can call from a manager- or agent-like app to handle authentication, encoding/decoding, OID search, MIB walks, and all the rest of the dreary low-level function that SNMP needs. I've collected all that function into a source library that I'll put up here in the next few weeks.

And I find it handy to have a few quick management-side tools and utilities, just to do that one-time test, the one I could really use right now. I've written a few that I think useful and I'll put 'em up here, too, along with their source files.