44 static const char *provider_names[] = {
51 #define STATE(type, ds) \
52 ((corsaro_geo_datastructure_state_##type##_t*)(ds)->state)
56 typedef struct corsaro_geo_datastructure_state_patricia
58 patricia_tree_t *trie;
59 } corsaro_geo_datastructure_state_patricia_t;
65 assert(
STATE(patricia, ds) == NULL);
67 if((ds->
state = malloc(
sizeof(corsaro_geo_datastructure_state_patricia_t)))
70 corsaro_log(__func__, corsaro,
"could not malloc patricia state");
75 STATE(patricia, ds)->trie = New_Patricia(32);
76 assert(
STATE(patricia, ds)->trie != NULL);
88 if(
STATE(patricia, ds) != NULL)
90 if(
STATE(patricia, ds)->trie != NULL)
92 Destroy_Patricia(
STATE(patricia, ds)->trie, NULL);
93 STATE(patricia, ds)->trie = NULL;
95 free(
STATE(patricia, ds));
104 static int patricia_add_prefix(
corsaro_t *corsaro,
106 uint32_t addr, uint8_t mask,
109 assert(corsaro != NULL && ds != NULL && ds->
state != NULL);
110 patricia_tree_t *trie =
STATE(patricia, ds)->trie;
111 assert(trie != NULL);
115 trie_pfx.family = AF_INET;
116 trie_pfx.ref_count = 0;
117 patricia_node_t *trie_node;
119 trie_pfx.bitlen = mask;
120 trie_pfx.add.sin.s_addr = addr;
121 if((trie_node = patricia_lookup(trie, &trie_pfx)) == NULL)
123 corsaro_log(__func__, corsaro,
"failed to insert prefix in trie");
135 assert(corsaro != NULL && ds != NULL && ds->
state != NULL);
136 patricia_tree_t *trie =
STATE(patricia, ds)->trie;
137 assert(trie != NULL);
139 patricia_node_t *node = NULL;
142 pfx.family = AF_INET;
145 pfx.add.sin.s_addr = addr;
147 if((node = patricia_search_best2(trie, &pfx, 1)) == NULL)
166 patricia_lookup_record,
178 if(record->
city != NULL)
190 if(record->
asn != NULL)
212 return provider_names[id];
219 return provider_names;
232 corsaro_log(__func__, corsaro,
"could not malloc corsaro_geo_provider_t");
239 provider->
id = provider_id;
243 provider->all_records = kh_init(corsaro_geo_rechash);
249 "could not malloc corsaro_geo_datastructure_t");
261 corsaro_log(__func__, corsaro,
"invalid geolocation datastructure");
266 if(provider->
ds->
init(corsaro, provider->
ds) != 0)
274 assert(corsaro->
packet != NULL);
287 if(provider->
ds != NULL)
309 if(corsaro->
packet != NULL)
325 if(provider->
ds != NULL)
332 if(provider->all_records != NULL)
335 kh_free_vals(corsaro_geo_rechash, provider->all_records, free_record);
336 kh_destroy(corsaro_geo_rechash, provider->all_records);
337 provider->all_records = NULL;
360 assert(kh_get(corsaro_geo_rechash, provider->all_records,
id) ==
361 kh_end(provider->all_records));
363 khiter = kh_put(corsaro_geo_rechash, provider->all_records,
id, &khret);
364 kh_value(provider->all_records, khiter) =
record;
366 assert(kh_get(corsaro_geo_rechash, provider->all_records,
id) !=
367 kh_end(provider->all_records));
378 if((khiter = kh_get(corsaro_geo_rechash, provider->all_records,
id))
379 == kh_end(provider->all_records))
383 return kh_val(provider->all_records, khiter);
391 int rec_cnt = kh_size(provider->all_records);
409 for(i = kh_begin(provider->all_records);
410 i != kh_end(provider->all_records);
413 if(kh_exist(provider->all_records, i))
415 *rec_ptr = kh_value(provider->all_records, i);
431 assert(corsaro != NULL && provider != NULL && record != NULL);
432 assert(provider->
ds != NULL);
434 return provider->
ds->
add_prefix(corsaro, provider->
ds, addr, mask, record);
441 assert(corsaro != NULL && provider != NULL);
442 assert(provider->
ds != NULL);
452 assert(provider != NULL);
454 while(provider->
records != NULL)
468 assert(provider != NULL);
477 assert(record->
next == NULL);
491 assert(corsaro != NULL && corsaro->
packet != NULL);
498 assert(corsaro != NULL && corsaro->
packet != NULL);
512 strncasecmp(provider->
name, name, strlen(provider->
name)) == 0)
524 assert(provider != NULL);
527 if(record == NULL || provider->
records == NULL)
545 "id: %"PRIu32
", cc: %s, cont: %d, reg: %s, city: %s, post: %s, "
546 "lat: %f, long: %f, met: %"PRIu32
", area: %"PRIu32
", "
561 for(i=0; i<record->
asn_cnt; i++)
563 fprintf(stdout,
"%d", record->
asn[i]);
564 if(i<record->asn_cnt-1)
565 fprintf(stdout,
"_");
567 fprintf(stdout,
"\n");
573 const char *corsaro_geo_maxmind_country_code_iso2[] = {
574 "--",
"AP",
"EU",
"AD",
"AE",
"AF",
"AG",
"AI",
"AL",
"AM",
"CW",
575 "AO",
"AQ",
"AR",
"AS",
"AT",
"AU",
"AW",
"AZ",
"BA",
"BB",
576 "BD",
"BE",
"BF",
"BG",
"BH",
"BI",
"BJ",
"BM",
"BN",
"BO",
577 "BR",
"BS",
"BT",
"BV",
"BW",
"BY",
"BZ",
"CA",
"CC",
"CD",
578 "CF",
"CG",
"CH",
"CI",
"CK",
"CL",
"CM",
"CN",
"CO",
"CR",
579 "CU",
"CV",
"CX",
"CY",
"CZ",
"DE",
"DJ",
"DK",
"DM",
"DO",
580 "DZ",
"EC",
"EE",
"EG",
"EH",
"ER",
"ES",
"ET",
"FI",
"FJ",
581 "FK",
"FM",
"FO",
"FR",
"SX",
"GA",
"GB",
"GD",
"GE",
"GF",
582 "GH",
"GI",
"GL",
"GM",
"GN",
"GP",
"GQ",
"GR",
"GS",
"GT",
583 "GU",
"GW",
"GY",
"HK",
"HM",
"HN",
"HR",
"HT",
"HU",
"ID",
584 "IE",
"IL",
"IN",
"IO",
"IQ",
"IR",
"IS",
"IT",
"JM",
"JO",
585 "JP",
"KE",
"KG",
"KH",
"KI",
"KM",
"KN",
"KP",
"KR",
"KW",
586 "KY",
"KZ",
"LA",
"LB",
"LC",
"LI",
"LK",
"LR",
"LS",
"LT",
587 "LU",
"LV",
"LY",
"MA",
"MC",
"MD",
"MG",
"MH",
"MK",
"ML",
588 "MM",
"MN",
"MO",
"MP",
"MQ",
"MR",
"MS",
"MT",
"MU",
"MV",
589 "MW",
"MX",
"MY",
"MZ",
"NA",
"NC",
"NE",
"NF",
"NG",
"NI",
590 "NL",
"NO",
"NP",
"NR",
"NU",
"NZ",
"OM",
"PA",
"PE",
"PF",
591 "PG",
"PH",
"PK",
"PL",
"PM",
"PN",
"PR",
"PS",
"PT",
"PW",
592 "PY",
"QA",
"RE",
"RO",
"RU",
"RW",
"SA",
"SB",
"SC",
"SD",
593 "SE",
"SG",
"SH",
"SI",
"SJ",
"SK",
"SL",
"SM",
"SN",
"SO",
594 "SR",
"ST",
"SV",
"SY",
"SZ",
"TC",
"TD",
"TF",
"TG",
"TH",
595 "TJ",
"TK",
"TM",
"TN",
"TO",
"TL",
"TR",
"TT",
"TV",
"TW",
596 "TZ",
"UA",
"UG",
"UM",
"US",
"UY",
"UZ",
"VA",
"VC",
"VE",
597 "VG",
"VI",
"VN",
"VU",
"WF",
"WS",
"YE",
"YT",
"RS",
"ZA",
598 "ZM",
"ME",
"ZW",
"A1",
"A2",
"O1",
"AX",
"GG",
"IM",
"JE",
599 "BL",
"MF",
"BQ",
"SS",
605 const char *corsaro_geo_maxmind_country_code_iso3[] = {
606 "--",
"AP",
"EU",
"AND",
"ARE",
"AFG",
"ATG",
"AIA",
"ALB",
"ARM",
"CUW",
607 "AGO",
"ATA",
"ARG",
"ASM",
"AUT",
"AUS",
"ABW",
"AZE",
"BIH",
"BRB",
608 "BGD",
"BEL",
"BFA",
"BGR",
"BHR",
"BDI",
"BEN",
"BMU",
"BRN",
"BOL",
609 "BRA",
"BHS",
"BTN",
"BVT",
"BWA",
"BLR",
"BLZ",
"CAN",
"CCK",
"COD",
610 "CAF",
"COG",
"CHE",
"CIV",
"COK",
"CHL",
"CMR",
"CHN",
"COL",
"CRI",
611 "CUB",
"CPV",
"CXR",
"CYP",
"CZE",
"DEU",
"DJI",
"DNK",
"DMA",
"DOM",
612 "DZA",
"ECU",
"EST",
"EGY",
"ESH",
"ERI",
"ESP",
"ETH",
"FIN",
"FJI",
613 "FLK",
"FSM",
"FRO",
"FRA",
"SXM",
"GAB",
"GBR",
"GRD",
"GEO",
"GUF",
614 "GHA",
"GIB",
"GRL",
"GMB",
"GIN",
"GLP",
"GNQ",
"GRC",
"SGS",
"GTM",
615 "GUM",
"GNB",
"GUY",
"HKG",
"HMD",
"HND",
"HRV",
"HTI",
"HUN",
"IDN",
616 "IRL",
"ISR",
"IND",
"IOT",
"IRQ",
"IRN",
"ISL",
"ITA",
"JAM",
"JOR",
617 "JPN",
"KEN",
"KGZ",
"KHM",
"KIR",
"COM",
"KNA",
"PRK",
"KOR",
"KWT",
618 "CYM",
"KAZ",
"LAO",
"LBN",
"LCA",
"LIE",
"LKA",
"LBR",
"LSO",
"LTU",
619 "LUX",
"LVA",
"LBY",
"MAR",
"MCO",
"MDA",
"MDG",
"MHL",
"MKD",
"MLI",
620 "MMR",
"MNG",
"MAC",
"MNP",
"MTQ",
"MRT",
"MSR",
"MLT",
"MUS",
"MDV",
621 "MWI",
"MEX",
"MYS",
"MOZ",
"NAM",
"NCL",
"NER",
"NFK",
"NGA",
"NIC",
622 "NLD",
"NOR",
"NPL",
"NRU",
"NIU",
"NZL",
"OMN",
"PAN",
"PER",
"PYF",
623 "PNG",
"PHL",
"PAK",
"POL",
"SPM",
"PCN",
"PRI",
"PSE",
"PRT",
"PLW",
624 "PRY",
"QAT",
"REU",
"ROU",
"RUS",
"RWA",
"SAU",
"SLB",
"SYC",
"SDN",
625 "SWE",
"SGP",
"SHN",
"SVN",
"SJM",
"SVK",
"SLE",
"SMR",
"SEN",
"SOM",
626 "SUR",
"STP",
"SLV",
"SYR",
"SWZ",
"TCA",
"TCD",
"ATF",
"TGO",
"THA",
627 "TJK",
"TKL",
"TKM",
"TUN",
"TON",
"TLS",
"TUR",
"TTO",
"TUV",
"TWN",
628 "TZA",
"UKR",
"UGA",
"UMI",
"USA",
"URY",
"UZB",
"VAT",
"VCT",
"VEN",
629 "VGB",
"VIR",
"VNM",
"VUT",
"WLF",
"WSM",
"YEM",
"MYT",
"SRB",
"ZAF",
630 "ZMB",
"MNE",
"ZWE",
"A1",
"A2",
"O1",
"ALA",
"GGY",
"IMN",
"JEY",
631 "BLM",
"MAF",
"BES",
"SSD",
637 const char *corsaro_geo_maxmind_country_name[] = {
638 "N/A",
"Asia/Pacific Region",
"Europe",
"Andorra",
"United Arab Emirates",
639 "Afghanistan",
"Antigua and Barbuda",
"Anguilla",
"Albania",
"Armenia",
640 "Cura" "\xe7" "ao",
"Angola",
"Antarctica",
"Argentina",
"American Samoa",
641 "Austria",
"Australia",
"Aruba",
"Azerbaijan",
"Bosnia and Herzegovina",
642 "Barbados",
"Bangladesh",
"Belgium",
"Burkina Faso",
"Bulgaria",
"Bahrain",
643 "Burundi",
"Benin",
"Bermuda",
"Brunei Darussalam",
"Bolivia",
"Brazil",
644 "Bahamas",
"Bhutan",
"Bouvet Island",
"Botswana",
"Belarus",
"Belize",
645 "Canada",
"Cocos (Keeling) Islands",
"Congo, The Democratic Republic of the",
646 "Central African Republic",
"Congo",
"Switzerland",
"Cote D'Ivoire",
647 "Cook Islands",
"Chile",
"Cameroon",
"China",
"Colombia",
"Costa Rica",
"Cuba",
648 "Cape Verde",
"Christmas Island",
"Cyprus",
"Czech Republic",
"Germany",
649 "Djibouti",
"Denmark",
"Dominica",
"Dominican Republic",
"Algeria",
"Ecuador",
650 "Estonia",
"Egypt",
"Western Sahara",
"Eritrea",
"Spain",
"Ethiopia",
"Finland",
651 "Fiji",
"Falkland Islands (Malvinas)",
"Micronesia, Federated States of",
652 "Faroe Islands",
"France",
"Sint Maarten (Dutch part)",
"Gabon",
653 "United Kingdom",
"Grenada",
"Georgia",
"French Guiana",
"Ghana",
"Gibraltar",
654 "Greenland",
"Gambia",
"Guinea",
"Guadeloupe",
"Equatorial Guinea",
"Greece",
655 "South Georgia and the South Sandwich Islands",
"Guatemala",
"Guam",
656 "Guinea-Bissau",
"Guyana",
"Hong Kong",
"Heard Island and McDonald Islands",
657 "Honduras",
"Croatia",
"Haiti",
"Hungary",
"Indonesia",
"Ireland",
"Israel",
658 "India",
"British Indian Ocean Territory",
"Iraq",
"Iran, Islamic Republic of",
659 "Iceland",
"Italy",
"Jamaica",
"Jordan",
"Japan",
"Kenya",
"Kyrgyzstan",
"Cambodia",
660 "Kiribati",
"Comoros",
"Saint Kitts and Nevis",
661 "Korea, Democratic People's Republic of",
"Korea, Republic of",
"Kuwait",
662 "Cayman Islands",
"Kazakhstan",
"Lao People's Democratic Republic",
"Lebanon",
663 "Saint Lucia",
"Liechtenstein",
"Sri Lanka",
"Liberia",
"Lesotho",
"Lithuania",
664 "Luxembourg",
"Latvia",
"Libyan Arab Jamahiriya",
"Morocco",
"Monaco",
665 "Moldova, Republic of",
"Madagascar",
"Marshall Islands",
"Macedonia",
"Mali",
666 "Myanmar",
"Mongolia",
"Macau",
"Northern Mariana Islands",
"Martinique",
667 "Mauritania",
"Montserrat",
"Malta",
"Mauritius",
"Maldives",
"Malawi",
"Mexico",
668 "Malaysia",
"Mozambique",
"Namibia",
"New Caledonia",
"Niger",
"Norfolk Island",
669 "Nigeria",
"Nicaragua",
"Netherlands",
"Norway",
"Nepal",
"Nauru",
"Niue",
670 "New Zealand",
"Oman",
"Panama",
"Peru",
"French Polynesia",
"Papua New Guinea",
671 "Philippines",
"Pakistan",
"Poland",
"Saint Pierre and Miquelon",
672 "Pitcairn Islands",
"Puerto Rico",
"Palestinian Territory",
"Portugal",
"Palau",
673 "Paraguay",
"Qatar",
"Reunion",
"Romania",
"Russian Federation",
"Rwanda",
674 "Saudi Arabia",
"Solomon Islands",
"Seychelles",
"Sudan",
"Sweden",
"Singapore",
675 "Saint Helena",
"Slovenia",
"Svalbard and Jan Mayen",
"Slovakia",
"Sierra Leone",
676 "San Marino",
"Senegal",
"Somalia",
"Suriname",
"Sao Tome and Principe",
677 "El Salvador",
"Syrian Arab Republic",
"Swaziland",
"Turks and Caicos Islands",
678 "Chad",
"French Southern Territories",
"Togo",
"Thailand",
"Tajikistan",
679 "Tokelau",
"Turkmenistan",
"Tunisia",
"Tonga",
"Timor-Leste",
"Turkey",
680 "Trinidad and Tobago",
"Tuvalu",
"Taiwan",
"Tanzania, United Republic of",
681 "Ukraine",
"Uganda",
"United States Minor Outlying Islands",
"United States",
682 "Uruguay",
"Uzbekistan",
"Holy See (Vatican City State)",
683 "Saint Vincent and the Grenadines",
"Venezuela",
"Virgin Islands, British",
684 "Virgin Islands, U.S.",
"Vietnam",
"Vanuatu",
"Wallis and Futuna",
"Samoa",
685 "Yemen",
"Mayotte",
"Serbia",
"South Africa",
"Zambia",
"Montenegro",
"Zimbabwe",
686 "Anonymous Proxy",
"Satellite Provider",
"Other",
"Aland Islands",
"Guernsey",
687 "Isle of Man",
"Jersey",
"Saint Barthelemy",
"Saint Martin",
688 "Bonaire, Saint Eustatius and Saba",
"South Sudan",
690 "Netherlands Antilles",
693 const char *corsaro_geo_maxmind_country_continent[] = {
694 "--",
"AS",
"EU",
"EU",
"AS",
"AS",
"NA",
"NA",
"EU",
"AS",
"NA",
695 "AF",
"AN",
"SA",
"OC",
"EU",
"OC",
"NA",
"AS",
"EU",
"NA",
696 "AS",
"EU",
"AF",
"EU",
"AS",
"AF",
"AF",
"NA",
"AS",
"SA",
697 "SA",
"NA",
"AS",
"AN",
"AF",
"EU",
"NA",
"NA",
"AS",
"AF",
698 "AF",
"AF",
"EU",
"AF",
"OC",
"SA",
"AF",
"AS",
"SA",
"NA",
699 "NA",
"AF",
"AS",
"AS",
"EU",
"EU",
"AF",
"EU",
"NA",
"NA",
700 "AF",
"SA",
"EU",
"AF",
"AF",
"AF",
"EU",
"AF",
"EU",
"OC",
701 "SA",
"OC",
"EU",
"EU",
"NA",
"AF",
"EU",
"NA",
"AS",
"SA",
702 "AF",
"EU",
"NA",
"AF",
"AF",
"NA",
"AF",
"EU",
"AN",
"NA",
703 "OC",
"AF",
"SA",
"AS",
"AN",
"NA",
"EU",
"NA",
"EU",
"AS",
704 "EU",
"AS",
"AS",
"AS",
"AS",
"AS",
"EU",
"EU",
"NA",
"AS",
705 "AS",
"AF",
"AS",
"AS",
"OC",
"AF",
"NA",
"AS",
"AS",
"AS",
706 "NA",
"AS",
"AS",
"AS",
"NA",
"EU",
"AS",
"AF",
"AF",
"EU",
707 "EU",
"EU",
"AF",
"AF",
"EU",
"EU",
"AF",
"OC",
"EU",
"AF",
708 "AS",
"AS",
"AS",
"OC",
"NA",
"AF",
"NA",
"EU",
"AF",
"AS",
709 "AF",
"NA",
"AS",
"AF",
"AF",
"OC",
"AF",
"OC",
"AF",
"NA",
710 "EU",
"EU",
"AS",
"OC",
"OC",
"OC",
"AS",
"NA",
"SA",
"OC",
711 "OC",
"AS",
"AS",
"EU",
"NA",
"OC",
"NA",
"AS",
"EU",
"OC",
712 "SA",
"AS",
"AF",
"EU",
"EU",
"AF",
"AS",
"OC",
"AF",
"AF",
713 "EU",
"AS",
"AF",
"EU",
"EU",
"EU",
"AF",
"EU",
"AF",
"AF",
714 "SA",
"AF",
"NA",
"AS",
"AF",
"NA",
"AF",
"AN",
"AF",
"AS",
715 "AS",
"OC",
"AS",
"AF",
"OC",
"AS",
"EU",
"NA",
"OC",
"AS",
716 "AF",
"EU",
"AF",
"OC",
"NA",
"SA",
"AS",
"EU",
"NA",
"SA",
717 "NA",
"NA",
"AS",
"OC",
"OC",
"OC",
"AS",
"AF",
"EU",
"AF",
718 "AF",
"EU",
"AF",
"--",
"--",
"--",
"EU",
"EU",
"EU",
"EU",
724 #define COUNTRY_CNT ((unsigned)( \
725 sizeof(corsaro_geo_maxmind_country_code_iso2) / \
726 sizeof(corsaro_geo_maxmind_country_code_iso2[0])))
730 assert(country_id < COUNTRY_CNT);
731 return corsaro_geo_maxmind_country_code_iso2[country_id];
736 *countries = corsaro_geo_maxmind_country_code_iso2;
742 assert(country_id < COUNTRY_CNT);
743 return corsaro_geo_maxmind_country_code_iso3[country_id];
748 *countries = corsaro_geo_maxmind_country_code_iso3;
754 assert(country_id < COUNTRY_CNT);
755 return corsaro_geo_maxmind_country_name[country_id];
760 *countries = corsaro_geo_maxmind_country_name;
766 assert(country_id < COUNTRY_CNT);
767 return corsaro_geo_maxmind_country_continent[country_id];
772 *continents = corsaro_geo_maxmind_country_continent;
uint32_t id
A unique ID for this record (used to join the Blocks and Locations Files)
void * state
Pointer to a instance-specific state object.
Structure which represents a geolocation datastructure.
char * conn_speed
Connection Speed/Type.
const char * corsaro_geo_get_maxmind_iso2(int country_id)
Get the ISO-3166-1 2 character country code for the given maxmind country id.
Header file dealing with the corsaro logging sub-system.
int corsaro_geo_get_maxmind_iso3_list(const char ***countries)
Get a list of all possible ISO-3166-1 3 character country codes that maxmind uses.
void corsaro_geo_free_provider(corsaro_t *corsaro, corsaro_geo_provider_t *provider)
Free the given geolocation provider object.
int corsaro_geo_get_maxmind_country_name_list(const char ***countries)
Get a list of all possible country names that maxmind uses.
int corsaro_geo_get_maxmind_iso2_list(const char ***countries)
Get a list of all possible ISO-3166-1 2 character country codes that maxmind uses.
corsaro_geo_provider_t * corsaro_geo_get_by_id(corsaro_t *corsaro, corsaro_geo_provider_id_t id)
Retrieve the provider object for the given provider ID.
const char * corsaro_geo_get_provider_name(corsaro_geo_provider_id_t id)
Get the provider name for the given ID.
#define STATE(corsaro)
Extends the generic plugin state convenience macro in corsaro_plugin.h.
This provider should be the default geolocation result.
void corsaro_geo_provider_add_record(corsaro_geo_provider_t *provider, corsaro_geo_record_t *record)
Add the given geolocation record to the head of the given geolocation provider object.
const char * corsaro_geo_get_maxmind_continent(int country_id)
Get the continent code for the given maxmind country id.
corsaro_packet_t * packet
A pointer to the wrapper packet passed to the plugins.
Structure which represents a geolocation provider.
corsaro_geo_record_t * corsaro_geo_provider_lookup_record(corsaro_t *corsaro, corsaro_geo_provider_t *provider, uint32_t addr)
Look up the given address in the provider's datastructure.
char country_code[3]
2 character string which holds the ISO2 country code
Highest numbered geolocation provider ID.
void corsaro_geo_dump_record(corsaro_geo_record_t *record)
Dump the given geolocation record to stdout (for debugging)
corsaro_geo_record_t * records
The list of records which contain the results of geolocation using this provider. ...
Header file for common utility functions.
const char * name
The name of the provider.
struct corsaro_geo_datastructure * ds
The datastructure that will be used to perform pfx => record lookups.
int corsaro_geo_get_maxmind_country_continent_list(const char ***continents)
Get a mapping of continent codes that maxmind uses.
int asn_cnt
Number of ASNs in the asn array.
int corsaro_geo_provider_clear(corsaro_geo_provider_t *provider)
Remove all the existing records from the given geolocation provider.
corsaro_geo_record_t * corsaro_geo_next_record(corsaro_geo_provider_t *provider, corsaro_geo_record_t *record)
Retrieve the next geolocation provider record in the list.
enum corsaro_geo_provider_default corsaro_geo_provider_default_t
Should this provider be set to be the default geolocation result provider.
void * malloc_zero(const size_t size)
Allocate memory and set it to zero.
static corsaro_in_record_t * record
A pointer to a corsaro record.
double latitude
Latitude of the city.
double longitude
Longitude of the city.
corsaro_geo_record_t * corsaro_geo_get_record(corsaro_geo_provider_t *provider, uint32_t id)
Get the geolocation record for the given id.
corsaro_geo_provider_t * corsaro_geo_get_default(corsaro_t *corsaro)
Retrieve the provider object for the default geolocation provider.
corsaro_geo_provider_t * geo_provider_default
Default geolocation provider object associated with this packet.
corsaro_geo_provider_t * corsaro_geo_init_provider(corsaro_t *corsaro, corsaro_geo_provider_id_t provider_id, corsaro_geo_datastructure_id_t ds_id, corsaro_geo_provider_default_t set_default)
Allocate a geolocation provider object in the packet state.
char region[3]
2 character string which represents the region the city is in
void(* free)(struct corsaro_geo_datastructure *ds)
Pointer to free function.
uint32_t area_code
Area code.
corsaro_geo_provider_id_t id
The ID of the provider.
char * post_code
String which contains the postal code.
int corsaro_geo_provider_associate_record(corsaro_t *corsaro, corsaro_geo_provider_t *provider, uint32_t addr, uint8_t mask, corsaro_geo_record_t *record)
Register a new prefix to record mapping for the given provider.
corsaro_geo_provider_t * geo_providers[CORSARO_GEO_PROVIDER_MAX]
Array of geolocation provider objects associated with this packet.
Structure which contains a geolocation record.
corsaro_geo_record_t *(* lookup_record)(corsaro_t *corsaro, struct corsaro_geo_datastructure *ds, uint32_t addr)
Pointer to lookup record function.
uint32_t * asn
Array of Autonomous System Numbers.
struct corsaro_geo_record * next
The next record in the list.
uint32_t metro_code
Metro code.
int continent_code
Continent Code.
const char * corsaro_geo_get_maxmind_country_name(int country_id)
Get the country name for the given maxmind country id.
corsaro_geo_provider_t * corsaro_geo_get_by_name(corsaro_t *corsaro, const char *name)
Retrieve the provider object for the given provider name.
int corsaro_geo_get_all_records(corsaro_geo_provider_t *provider, corsaro_geo_record_t ***records)
Get an array of all the geolocation records registered with the given provider.
#define ARR_CNT(a)
Count the number of elements in an arbitrary array.
enum corsaro_geo_datastructure_id corsaro_geo_datastructure_id_t
A unique identifier for each geolocation datastructure that corsaro supports.
void corsaro_log(const char *func, corsaro_t *corsaro, const char *format,...)
Write a formatted string to the logfile associated with an corsaro object.
int(* add_prefix)(corsaro_t *corsaro, struct corsaro_geo_datastructure *ds, uint32_t addr, uint8_t mask, corsaro_geo_record_t *record)
Pointer to add prefix function.
char * city
String which contains the city name.
enum corsaro_geo_provider_id corsaro_geo_provider_id_t
A unique identifier for each geolocation provider that corsaro supports.
int(* init)(corsaro_t *corsaro, struct corsaro_geo_datastructure *ds)
Pointer to init function.
const char * corsaro_geo_get_maxmind_iso3(int country_id)
Get the ISO-3166-1 3 character country code for the given maxmind country id.
Header file dealing with the corsaro geolocation subsystem.
corsaro_geo_record_t * corsaro_geo_init_record(corsaro_geo_provider_t *provider, uint32_t id)
Allocate an empty geolocation record for the given id.
const char ** corsaro_geo_get_provider_names()
Get an array of provider names.
Header file dealing with the internal corsaro functions.