"Fossies" - the Fresh Open Source Software Archive

Member "libmaxminddb-1.5.2/t/ipv6_lookup_in_ipv4_t.c" (18 Feb 2021, 1555 Bytes) of package /linux/misc/libmaxminddb-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "ipv6_lookup_in_ipv4_t.c": 1.5.0_vs_1.5.2.

    1 #include "maxminddb_test_helper.h"
    2 
    3 void run_tests(int mode, const char *mode_desc) {
    4     const char *filename = "MaxMind-DB-test-ipv4-28.mmdb";
    5     const char *path = test_database_path(filename);
    6     MMDB_s *mmdb = open_ok(path, mode, mode_desc);
    7     free((void *)path);
    8 
    9     const char *ip = "::abcd";
   10     int gai_error, mmdb_error;
   11     MMDB_lookup_result_s UNUSED(result) =
   12         MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
   13 
   14     cmp_ok(mmdb_error,
   15            "==",
   16            MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR,
   17            "MMDB_lookup_string sets mmdb_error to "
   18            "MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR when we try to look up an "
   19            "IPv6 address in an IPv4-only database");
   20 
   21     struct addrinfo hints = {.ai_family = AF_INET6, .ai_flags = AI_NUMERICHOST};
   22 
   23     struct addrinfo *addresses;
   24     gai_error = getaddrinfo(
   25         "2001:db8:85a3:0:0:8a2e:370:7334", NULL, &hints, &addresses);
   26     if (gai_error) {
   27         BAIL_OUT("getaddrinfo failed: %s", gai_strerror(gai_error));
   28     }
   29 
   30     mmdb_error = 0;
   31     MMDB_lookup_sockaddr(mmdb, addresses->ai_addr, &mmdb_error);
   32 
   33     cmp_ok(mmdb_error,
   34            "==",
   35            MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR,
   36            "MMDB_lookup_sockaddr sets mmdb_error to "
   37            "MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR when we try to look up an "
   38            "IPv6 address in an IPv4-only database");
   39 
   40     freeaddrinfo(addresses);
   41     MMDB_close(mmdb);
   42     free(mmdb);
   43 }
   44 
   45 int main(void) {
   46     plan(NO_PLAN);
   47     for_all_modes(&run_tests);
   48     done_testing();
   49 }