Richard's FreeBSD code samples



Have you ever wanted to track the system load from a program? While "top" and "systat" give you that information, calling them from inside an application would be clumsy at best. The first code sample uses a system load object (structure) to track the idle time.

The second sample is a function to look up an ATM address, given the host's IP address. A main() wrapper gets an IP address from the command line and prints the ATM address in hex.

The third sample is a function using gcc inline assembler code. It is a small and fast function to calculate the checksum for a standard 20-byte IP header.

The fourth is actually a patch for netinet/igmp.c to fix the way IGMP works so that it does not choke on high-bandwidth multicast streams.
This patch adds a sysctl variable so that you can make IGMP do the following:
  1. When joining a multicast group, a report is ALWAYS sent.
  2. When leaving a multicast group, a leave is ALWAYS sent.
  3. When a query is received, a report is sent IMMEDIATELY.
  4. The IGMP state is ALWAYS IGMPv2, even if v1 routers exist.
Simply put, strict adherance to RFC2236 behavior can cause problems when a multicast group takes up half or more of the interface bandwidth. In order for the switch or router to track group membership perfectly, our host must issue the join and leave reports always, and without delay. We must also not allow a stray IGMPv1 report to cause our host to soil itself.

After patching your kernel, you can enable this feature by issuing the command:
sysctl -w net.inet.igmp.high_bandwidth=1
Set to zero if you want to restore original IGMP behavior.

HOME



Awards furnished by The Corporation.