Main Page -> Code Samples |
Code Samples
Overview:
This page hosts componets and chunks of code that may be compiled but are really only (designed to be) pieces that can be used in other applications.
porttool
What it does This code can be compiled and run on a system to determine variable sizes, the endian-ness of the processor, and effect of converting to network byte order. Code of value Endian test, bold printing sample. Distribution Code: porttool.c (HTML wrapped source) Package porttool-1_0_1.tar.gz (Includes Makefile) |
gethostbyname
What it does Sample code that calls gethostbyname() and processes the return hostent structure. This can be compiled and run to diagnose name resolution issues (as it will not go directly to name servers like dig/nslookup does). Code of value gethostbyname(), hostent structure, inet_ntop() Distribution Code: gethostbyname.c (HTML wrapped source) Package gethostbyname-1_0_0.tar.gz (Includes Makefile) |
flock
What it does It is a piece of "demo" code that shows the effects of file locking between two different applications (that in this case is two instances of the same flock program). Code of value The differences of the open() call and setting locks between BSD variants and Linux. Distribution Code: flock.c (HTML wrapped source) README: README (HTML wrapped README) Package flock-1_0_0.tar.gz (Includes Makefile) |
pipefork
What it does This is a small snippet that creates a pipe, forks, and sends data from the parent to the child through the pipe. Code of value Usage of: pipe(), fork(), alarm(), read(), write(), fflush() Distribution Code: pf.c (HTML wrapped source) Package pipefork-1_0_0.tar.gz (Includes Makefile) |
fusage
What it does This is a quick (Linux) utility to list the top applications on the system by open files as well as the total file statistics for the system. Code of value This is more valuable as an actual utility but includes code for reading a directory (specifically the /proc filesystem). Distribution Code: fusage.c (HTML wrapped source) Package fusage-0_6_0.tar.gz (Includes Makefile) |
sectsz
What it does I need a routine to find the sector sizes of disks in Linux for yapfr. This is a piece of sample (test) code to find that value for a given disk. It also returns the number of sectors on the disk and then calculates the disk size. Code of value Usage of: open() on a device and ioctl() on a disk device. Distribution Code: sectsz.c (HTML wrapped source) |