MaxMind Inc. publishes a GeoIP database for use in open source software. It can be used to map IP addresses to geographical locations.
If this library isn't already installed or available as a package for your platform, you can get it at: http://www.maxmind.com/app/c.
You can get the latest version at: http://www.maxmind.com/app/c