Mailfromd Manual (split by node):   Section:   Chapter:FastBack: Library   Up: Geolocation functions   FastForward: Using MFL Mode   Contents: Table of ContentsIndex: Concept Index

5.24.1 Legacy geoip support

For compatibility with older releases, mailfromd supports the legacy ‘GeoIP’ library. This support is going to be removed in the next release, so its use is not recommended. Please use ‘GeoIP2’ instead.

The support for the legacy GeoIP library is available if mailfromd is compiled with the ‘GeoIP’ support (the --with-geoip configure option). The m4 macro ‘WITH_GEOIP’ is defined if it is so.

The legacy GeoIP is distributed by ‘MaxMind’ under the terms of the GNU Lesser General Public License. The library is available from http://www.maxmind.com/app/c.

Built-in Function: string geoip_country_code_by_addr ( string ip [, bool tlc])

Look up the ‘ISO 3166-1’ country code corresponding to the IP address ip. If tlc is given and is not zero, return the 3 letter code, otherwise return the 2 letter code.

Built-in Function: string geoip_country_code_by_name ( string name [, bool tlc])

Look up the ‘ISO 3166-1’ country code corresponding to the host name name. If tlc is given and is not zero, return the 3 letter code, otherwise return the 2 letter code.

If it is impossible to locate the country, both functions raise the e_not_found exception. If an error internal to the ‘GeoIP’ library occurs, they raise the e_failure exception.

Applications may test whether the GeoIP support is present and enable corresponding code blocks conditionally, by testing if the ‘WITH_GEOIP’ m4 macro is defined. For example, the following code adds to the message the ‘X-Originator-Country’ header, containing the 2 letter code of the country where the client machine is located. If mailfromd is compiled without ‘GeoIP’ support, it does nothing:

m4_ifdef(`WITH_GEOIP',`
  header_add("X-Originator-Country", geoip_country_code_by_addr($client_addr))
')

Mailfromd Manual (split by node):   Section:   Chapter:FastBack: Library   Up: Geolocation functions   FastForward: Using MFL Mode   Contents: Table of ContentsIndex: Concept Index