Archive for the ‘C / C++’ Category

My journey with ioctl() on Linux

Wednesday, October 10th, 2007

Background

Lately, I’ve been working on an application that heavily uses the ioctl() function for different settings with hardware devices (get/set NIC config – IP, subnet, broadcast, MTU, etc.). This function is so versatile and has so many different uses, that it can be difficult at times to understand what exactly is needed for it to work properly. (more…)

Interaction of stdout buffering using standard stdio.h functions when using pthreads

Thursday, September 27th, 2007

I’ve been working on a project recently that stretched my C programming ability (yes, I’ve been learning quite a bit — especially since I’d never really tackled any significant programming on Linux prior to this).  The app is multithreaded, using the pthreads library.

I ran into a situation where I had multiple threads executing simultaneously, but the text output wasn’t being displayed. (more…)

x86 Kernel (32-bit protected-mode)

Wednesday, February 23rd, 2005

OBSELENCE NOTE: This was written well over a year ago, so may be outdated (ie. may have broken links — if so, let me know and I’ll update).  Just because it’s old doesn’t mean that it’s not worth sharing!

Summary:

Kernel design can be overwhelming.  Fortunately, there are lots of resources available (just hard to find at times).  Using IRC, UseNet, the Internet and written books, it is possible to learn quite a bit about OS design and development as well as writing your own.

This kernel operates in protected-mode (must already be in protected-mode — accomplished via boot loader — look at Boot Loader (32-bit protected-mode) for an example of such a boot loader).

It loads the Global Descriptor Table (GDT), IDT & provides a basic/buggy text output routines & keyboard driver (interrupt-driven).  Note that it’s not complete, comes with no guarantees.

One book that’s an excellent resource on OS theory is Modern Operating Systems by Andrew S. Tanenbaum (published by Prentice Hall).  See below for links to UseNet groups, IRC channels & websites that I’ve found helpful.

(more…)

Windows 2000/2003 Directory Services Audit Logging Management Utility

Thursday, January 13th, 2005

Summary:

There’s a way to get very detailed event logging features for core Active Directory services.  Unfortunately, there’s no GUI for doing this — you have to dig in the registry to do it.  This can be cumbersome if you’ve got a list of servers to monitor/diagnose.  This tools allows you to specify a server, select which Active Directory service to log and what logging level it should be set at.

See http://support.microsoft.com/default.aspx?scid=kb;en-us;314980&sd=tech for more information on the registry keys and values.

(more…)

NT Authentication DLL

Thursday, January 13th, 2005

OBSELENCE NOTE: This was written well over a year ago, so may be outdated (ie. may have broken links — if so, let me know and I’ll update).  Just because it’s old doesn’t mean that it’s not worth sharing!

Summary:

How many times have you had a program that you need to authenticate users?  Most programs today require authentication at some point or another.  You have two solutions: use an existing authentication mechanism or re-create the wheel (make your own).

Sometimes it’s best to re-create the wheel, but for most apps (especially in-house, home-brewn apps) this simply results in another username/password combo that end-users will simply forget.  The bottom line: more work for you (or whoever’s maintaining the system) because you’ll be getting complaints from users and having to reset their passwords all the time.  Then, to make things better, you notice that people are leaving sticky notes on their monitors with their usernames/passwords to these programs.  Maybe you’d better think about using an existing authentication system.  May I encourage you to use NT authentication!

If you have a Windows environment (domain), you already have the usernames & passwords created with a system that enforces all of your companies account policies (expiration, lockout, password change interval, etc.).  Simply check the usernames and passwords provided against NT.  This DLL provides one way of doing this.  Maybe there’s a better way.  In fact, I’m almost sure there is, but this works for me.  If you have a better way, please email me — tclegg at ovhd.com.

As a bonus, this DLL also is useful for getting NT group membership.  One function allows you to provide the group name and it will enumerate all of the users in that group.  Another group function takes a username and lists all groups that the user belongs to.  Note that these are domain (global) groups, not local groups.

(more…)

C++ Memory Management System

Thursday, January 13th, 2005

OBSELENCE NOTE: This was written several years ago, so may be outdated (ie. may have broken links — if so, let me know and I’ll update).  Just because it’s old doesn’t mean that it’s not worth sharing!

Summary:

Here’s a handy (and free) snippet of code that overloads the ‘new’, ‘new[]‘ and ‘delete’ operators.  The new overloaded functions keep track of memory allocations and de-allocations, therefore allowing you to summarize memory that wasn’t de-allocated.

Note that the code that you’ll see here is derived from some of the code shown in the references.  I didn’t find a complete all-in-one package that I really liked and had the features I wanted (like dumping a summary to a log file, being able to tell it to echo allocations to stdout, etc).  This is not all coded from hand, therefore much of the credit goes to the people who made the pages in the references section!

(more…)