tizen 2.4 release
[external/c-ares.git] / acountry.c
1 /*
2  *
3  * IP-address/hostname to country converter.
4  *
5  * Problem; you want to know where IP a.b.c.d is located.
6  *
7  * Use ares_gethostbyname ("d.c.b.a.zz.countries.nerd.dk")
8  * and get the CNAME (host->h_name). Result will be:
9  *   CNAME = zz<CC>.countries.nerd.dk with address 127.0.x.y (ver 1) or
10  *   CNAME = <a.b.c.d>.zz.countries.nerd.dk with address 127.0.x.y (ver 2)
11  *
12  * The 2 letter country code is in <CC> and the ISO-3166 country
13  * number is in x.y (number = x*256 + y). Version 2 of the protocol is missing
14  * the <CC> number.
15  *
16  * Ref: http://countries.nerd.dk/more.html
17  *
18  * Written by G. Vanem <gvanem@broadpark.no> 2006, 2007
19  *
20  * NB! This program may not be big-endian aware.
21  *
22  * Permission to use, copy, modify, and distribute this
23  * software and its documentation for any purpose and without
24  * fee is hereby granted, provided that the above copyright
25  * notice appear in all copies and that both that copyright
26  * notice and this permission notice appear in supporting
27  * documentation, and that the name of M.I.T. not be used in
28  * advertising or publicity pertaining to distribution of the
29  * software without specific, written prior permission.
30  * M.I.T. makes no representations about the suitability of
31  * this software for any purpose.  It is provided "as is"
32  * without express or implied warranty.
33  */
34
35 #include "ares_setup.h"
36
37 #ifdef HAVE_STRINGS_H
38 #include <strings.h>
39 #endif
40
41 #if defined(WIN32) && !defined(WATT32)
42   #include <winsock.h>
43 #else
44   #include <arpa/inet.h>
45   #include <netinet/in.h>
46   #include <netdb.h>
47 #endif
48
49 #include "ares.h"
50 #include "ares_getopt.h"
51 #include "ares_nowarn.h"
52
53 #ifndef HAVE_STRDUP
54 #  include "ares_strdup.h"
55 #  define strdup(ptr) ares_strdup(ptr)
56 #endif
57
58 #ifndef HAVE_STRCASECMP
59 #  include "ares_strcasecmp.h"
60 #  define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
61 #endif
62
63 #ifndef HAVE_STRNCASECMP
64 #  include "ares_strcasecmp.h"
65 #  define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
66 #endif
67
68 #ifndef INADDR_NONE
69 #define INADDR_NONE 0xffffffff
70 #endif
71
72 static const char *usage      = "acountry [-vh?] {host|addr} ...\n";
73 static const char  nerd_fmt[] = "%u.%u.%u.%u.zz.countries.nerd.dk";
74 static const char *nerd_ver1  = nerd_fmt + 14;
75 static const char *nerd_ver2  = nerd_fmt + 11;
76 static int         verbose    = 0;
77
78 #define TRACE(fmt) do {               \
79                      if (verbose > 0) \
80                        printf fmt ;   \
81                    } WHILE_FALSE
82
83 static void wait_ares(ares_channel channel);
84 static void callback(void *arg, int status, int timeouts, struct hostent *host);
85 static void callback2(void *arg, int status, int timeouts, struct hostent *host);
86 static void find_country_from_cname(const char *cname, struct in_addr addr);
87
88 static void Abort(const char *fmt, ...)
89 {
90   va_list args;
91   va_start(args, fmt);
92   vfprintf(stderr, fmt, args);
93   va_end(args);
94   exit(1);
95 }
96
97 int main(int argc, char **argv)
98 {
99   ares_channel channel;
100   int    ch, status;
101
102 #if defined(WIN32) && !defined(WATT32)
103   WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK);
104   WSADATA wsaData;
105   WSAStartup(wVersionRequested, &wsaData);
106 #endif
107
108   status = ares_library_init(ARES_LIB_INIT_ALL);
109   if (status != ARES_SUCCESS)
110     {
111       fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
112       return 1;
113     }
114
115   while ((ch = ares_getopt(argc, argv, "dvh?")) != -1)
116     switch (ch)
117       {
118       case 'd':
119 #ifdef WATT32
120         dbug_init();
121 #endif
122         break;
123       case 'v':
124         verbose++;
125         break;
126       case 'h':
127       case '?':
128       default:
129         Abort(usage);
130       }
131
132   argc -= optind;
133   argv += optind;
134   if (argc < 1)
135      Abort(usage);
136
137   status = ares_init(&channel);
138   if (status != ARES_SUCCESS)
139     {
140       fprintf(stderr, "ares_init: %s\n", ares_strerror(status));
141       return 1;
142     }
143
144   /* Initiate the queries, one per command-line argument. */
145   for ( ; *argv; argv++)
146     {
147       struct in_addr addr;
148       char buf[100];
149
150       /* If this fails, assume '*argv' is a host-name that
151        * must be resolved first
152        */
153       if (ares_inet_pton(AF_INET, *argv, &addr) != 1)
154         {
155           ares_gethostbyname(channel, *argv, AF_INET, callback2, &addr);
156           wait_ares(channel);
157           if (addr.s_addr == INADDR_NONE)
158             {
159               printf("Failed to lookup %s\n", *argv);
160               continue;
161             }
162         }
163
164       sprintf(buf, nerd_fmt,
165               (unsigned int)(addr.s_addr >> 24),
166               (unsigned int)((addr.s_addr >> 16) & 255),
167               (unsigned int)((addr.s_addr >> 8) & 255),
168               (unsigned int)(addr.s_addr & 255));
169       TRACE(("Looking up %s...", buf));
170       fflush(stdout);
171       ares_gethostbyname(channel, buf, AF_INET, callback, buf);
172     }
173
174   wait_ares(channel);
175   ares_destroy(channel);
176
177   ares_library_cleanup();
178
179 #if defined(WIN32) && !defined(WATT32)
180   WSACleanup();
181 #endif
182
183   return 0;
184 }
185
186 /*
187  * Wait for the queries to complete.
188  */
189 static void wait_ares(ares_channel channel)
190 {
191   for (;;)
192     {
193       struct timeval *tvp, tv;
194       fd_set read_fds, write_fds;
195       int nfds;
196
197       FD_ZERO(&read_fds);
198       FD_ZERO(&write_fds);
199       nfds = ares_fds(channel, &read_fds, &write_fds);
200       if (nfds == 0)
201         break;
202       tvp = ares_timeout(channel, NULL, &tv);
203       select(nfds, &read_fds, &write_fds, NULL, tvp);
204       ares_process(channel, &read_fds, &write_fds);
205     }
206 }
207
208 /*
209  * This is the callback used when we have the IP-address of interest.
210  * Extract the CNAME and figure out the country-code from it.
211  */
212 static void callback(void *arg, int status, int timeouts, struct hostent *host)
213 {
214   const char *name = (const char*)arg;
215   const char *cname;
216   char buf[20];
217
218   (void)timeouts;
219
220   if (!host || status != ARES_SUCCESS)
221     {
222       printf("Failed to lookup %s: %s\n", name, ares_strerror(status));
223       return;
224     }
225
226   TRACE(("\nFound address %s, name %s\n",
227          ares_inet_ntop(AF_INET,(const char*)host->h_addr,buf,sizeof(buf)),
228          host->h_name));
229
230   cname = host->h_name;  /* CNAME gets put here */
231   if (!cname)
232     printf("Failed to get CNAME for %s\n", name);
233   else
234     find_country_from_cname(cname, *(struct in_addr*)host->h_addr);
235 }
236
237 /*
238  * This is the callback used to obtain the IP-address of the host of interest.
239  */
240 static void callback2(void *arg, int status, int timeouts, struct hostent *host)
241 {
242   struct in_addr *addr = (struct in_addr*) arg;
243
244   (void)timeouts;
245   if (!host || status != ARES_SUCCESS)
246     memset(addr, INADDR_NONE, sizeof(*addr));
247   else
248     memcpy(addr, host->h_addr, sizeof(*addr));
249 }
250
251 struct search_list {
252        int         country_number; /* ISO-3166 country number */
253        char        short_name[3];  /* A2 short country code */
254        const char *long_name;      /* normal country name */
255      };
256
257 static const struct search_list *list_lookup(int number, const struct search_list *list, int num)
258 {
259   while (num > 0 && list->long_name)
260     {
261       if (list->country_number == number)
262         return (list);
263       num--;
264       list++;
265     }
266   return (NULL);
267 }
268
269 /*
270  * Ref: ftp://ftp.ripe.net/iso3166-countrycodes.txt
271  */
272 static const struct search_list country_list[] = {
273        {   4, "af", "Afghanistan"                          },
274        { 248, "ax", "Ã…land Island"                         },
275        {   8, "al", "Albania"                              },
276        {  12, "dz", "Algeria"                              },
277        {  16, "as", "American Samoa"                       },
278        {  20, "ad", "Andorra"                              },
279        {  24, "ao", "Angola"                               },
280        { 660, "ai", "Anguilla"                             },
281        {  10, "aq", "Antarctica"                           },
282        {  28, "ag", "Antigua & Barbuda"                    },
283        {  32, "ar", "Argentina"                            },
284        {  51, "am", "Armenia"                              },
285        { 533, "aw", "Aruba"                                },
286        {  36, "au", "Australia"                            },
287        {  40, "at", "Austria"                              },
288        {  31, "az", "Azerbaijan"                           },
289        {  44, "bs", "Bahamas"                              },
290        {  48, "bh", "Bahrain"                              },
291        {  50, "bd", "Bangladesh"                           },
292        {  52, "bb", "Barbados"                             },
293        { 112, "by", "Belarus"                              },
294        {  56, "be", "Belgium"                              },
295        {  84, "bz", "Belize"                               },
296        { 204, "bj", "Benin"                                },
297        {  60, "bm", "Bermuda"                              },
298        {  64, "bt", "Bhutan"                               },
299        {  68, "bo", "Bolivia"                              },
300        {  70, "ba", "Bosnia & Herzegowina"                 },
301        {  72, "bw", "Botswana"                             },
302        {  74, "bv", "Bouvet Island"                        },
303        {  76, "br", "Brazil"                               },
304        {  86, "io", "British Indian Ocean Territory"       },
305        {  96, "bn", "Brunei Darussalam"                    },
306        { 100, "bg", "Bulgaria"                             },
307        { 854, "bf", "Burkina Faso"                         },
308        { 108, "bi", "Burundi"                              },
309        { 116, "kh", "Cambodia"                             },
310        { 120, "cm", "Cameroon"                             },
311        { 124, "ca", "Canada"                               },
312        { 132, "cv", "Cape Verde"                           },
313        { 136, "ky", "Cayman Islands"                       },
314        { 140, "cf", "Central African Republic"             },
315        { 148, "td", "Chad"                                 },
316        { 152, "cl", "Chile"                                },
317        { 156, "cn", "China"                                },
318        { 162, "cx", "Christmas Island"                     },
319        { 166, "cc", "Cocos Islands"                        },
320        { 170, "co", "Colombia"                             },
321        { 174, "km", "Comoros"                              },
322        { 178, "cg", "Congo"                                },
323        { 180, "cd", "Congo"                                },
324        { 184, "ck", "Cook Islands"                         },
325        { 188, "cr", "Costa Rica"                           },
326        { 384, "ci", "Cote d'Ivoire"                        },
327        { 191, "hr", "Croatia"                              },
328        { 192, "cu", "Cuba"                                 },
329        { 196, "cy", "Cyprus"                               },
330        { 203, "cz", "Czech Republic"                       },
331        { 208, "dk", "Denmark"                              },
332        { 262, "dj", "Djibouti"                             },
333        { 212, "dm", "Dominica"                             },
334        { 214, "do", "Dominican Republic"                   },
335        { 218, "ec", "Ecuador"                              },
336        { 818, "eg", "Egypt"                                },
337        { 222, "sv", "El Salvador"                          },
338        { 226, "gq", "Equatorial Guinea"                    },
339        { 232, "er", "Eritrea"                              },
340        { 233, "ee", "Estonia"                              },
341        { 231, "et", "Ethiopia"                             },
342        { 238, "fk", "Falkland Islands"                     },
343        { 234, "fo", "Faroe Islands"                        },
344        { 242, "fj", "Fiji"                                 },
345        { 246, "fi", "Finland"                              },
346        { 250, "fr", "France"                               },
347        { 249, "fx", "France, Metropolitan"                 },
348        { 254, "gf", "French Guiana"                        },
349        { 258, "pf", "French Polynesia"                     },
350        { 260, "tf", "French Southern Territories"          },
351        { 266, "ga", "Gabon"                                },
352        { 270, "gm", "Gambia"                               },
353        { 268, "ge", "Georgia"                              },
354        { 276, "de", "Germany"                              },
355        { 288, "gh", "Ghana"                                },
356        { 292, "gi", "Gibraltar"                            },
357        { 300, "gr", "Greece"                               },
358        { 304, "gl", "Greenland"                            },
359        { 308, "gd", "Grenada"                              },
360        { 312, "gp", "Guadeloupe"                           },
361        { 316, "gu", "Guam"                                 },
362        { 320, "gt", "Guatemala"                            },
363        { 324, "gn", "Guinea"                               },
364        { 624, "gw", "Guinea-Bissau"                        },
365        { 328, "gy", "Guyana"                               },
366        { 332, "ht", "Haiti"                                },
367        { 334, "hm", "Heard & Mc Donald Islands"            },
368        { 336, "va", "Vatican City"                         },
369        { 340, "hn", "Honduras"                             },
370        { 344, "hk", "Hong kong"                            },
371        { 348, "hu", "Hungary"                              },
372        { 352, "is", "Iceland"                              },
373        { 356, "in", "India"                                },
374        { 360, "id", "Indonesia"                            },
375        { 364, "ir", "Iran"                                 },
376        { 368, "iq", "Iraq"                                 },
377        { 372, "ie", "Ireland"                              },
378        { 376, "il", "Israel"                               },
379        { 380, "it", "Italy"                                },
380        { 388, "jm", "Jamaica"                              },
381        { 392, "jp", "Japan"                                },
382        { 400, "jo", "Jordan"                               },
383        { 398, "kz", "Kazakhstan"                           },
384        { 404, "ke", "Kenya"                                },
385        { 296, "ki", "Kiribati"                             },
386        { 408, "kp", "Korea (north)"                        },
387        { 410, "kr", "Korea (south)"                        },
388        { 414, "kw", "Kuwait"                               },
389        { 417, "kg", "Kyrgyzstan"                           },
390        { 418, "la", "Laos"                                 },
391        { 428, "lv", "Latvia"                               },
392        { 422, "lb", "Lebanon"                              },
393        { 426, "ls", "Lesotho"                              },
394        { 430, "lr", "Liberia"                              },
395        { 434, "ly", "Libya"                                },
396        { 438, "li", "Liechtenstein"                        },
397        { 440, "lt", "Lithuania"                            },
398        { 442, "lu", "Luxembourg"                           },
399        { 446, "mo", "Macao"                                },
400        { 807, "mk", "Macedonia"                            },
401        { 450, "mg", "Madagascar"                           },
402        { 454, "mw", "Malawi"                               },
403        { 458, "my", "Malaysia"                             },
404        { 462, "mv", "Maldives"                             },
405        { 466, "ml", "Mali"                                 },
406        { 470, "mt", "Malta"                                },
407        { 584, "mh", "Marshall Islands"                     },
408        { 474, "mq", "Martinique"                           },
409        { 478, "mr", "Mauritania"                           },
410        { 480, "mu", "Mauritius"                            },
411        { 175, "yt", "Mayotte"                              },
412        { 484, "mx", "Mexico"                               },
413        { 583, "fm", "Micronesia"                           },
414        { 498, "md", "Moldova"                              },
415        { 492, "mc", "Monaco"                               },
416        { 496, "mn", "Mongolia"                             },
417        { 500, "ms", "Montserrat"                           },
418        { 504, "ma", "Morocco"                              },
419        { 508, "mz", "Mozambique"                           },
420        { 104, "mm", "Myanmar"                              },
421        { 516, "na", "Namibia"                              },
422        { 520, "nr", "Nauru"                                },
423        { 524, "np", "Nepal"                                },
424        { 528, "nl", "Netherlands"                          },
425        { 530, "an", "Netherlands Antilles"                 },
426        { 540, "nc", "New Caledonia"                        },
427        { 554, "nz", "New Zealand"                          },
428        { 558, "ni", "Nicaragua"                            },
429        { 562, "ne", "Niger"                                },
430        { 566, "ng", "Nigeria"                              },
431        { 570, "nu", "Niue"                                 },
432        { 574, "nf", "Norfolk Island"                       },
433        { 580, "mp", "Northern Mariana Islands"             },
434        { 578, "no", "Norway"                               },
435        { 512, "om", "Oman"                                 },
436        { 586, "pk", "Pakistan"                             },
437        { 585, "pw", "Palau"                                },
438        { 275, "ps", "Palestinian Territory"                },
439        { 591, "pa", "Panama"                               },
440        { 598, "pg", "Papua New Guinea"                     },
441        { 600, "py", "Paraguay"                             },
442        { 604, "pe", "Peru"                                 },
443        { 608, "ph", "Philippines"                          },
444        { 612, "pn", "Pitcairn"                             },
445        { 616, "pl", "Poland"                               },
446        { 620, "pt", "Portugal"                             },
447        { 630, "pr", "Puerto Rico"                          },
448        { 634, "qa", "Qatar"                                },
449        { 638, "re", "Reunion"                              },
450        { 642, "ro", "Romania"                              },
451        { 643, "ru", "Russia"                               },
452        { 646, "rw", "Rwanda"                               },
453        { 659, "kn", "Saint Kitts & Nevis"                  },
454        { 662, "lc", "Saint Lucia"                          },
455        { 670, "vc", "Saint Vincent"                        },
456        { 882, "ws", "Samoa"                                },
457        { 674, "sm", "San Marino"                           },
458        { 678, "st", "Sao Tome & Principe"                  },
459        { 682, "sa", "Saudi Arabia"                         },
460        { 686, "sn", "Senegal"                              },
461        { 891, "cs", "Serbia and Montenegro"                },
462        { 690, "sc", "Seychelles"                           },
463        { 694, "sl", "Sierra Leone"                         },
464        { 702, "sg", "Singapore"                            },
465        { 703, "sk", "Slovakia"                             },
466        { 705, "si", "Slovenia"                             },
467        {  90, "sb", "Solomon Islands"                      },
468        { 706, "so", "Somalia"                              },
469        { 710, "za", "South Africa"                         },
470        { 239, "gs", "South Georgia"                        },
471        { 724, "es", "Spain"                                },
472        { 144, "lk", "Sri Lanka"                            },
473        { 654, "sh", "St. Helena"                           },
474        { 666, "pm", "St. Pierre & Miquelon"                },
475        { 736, "sd", "Sudan"                                },
476        { 740, "sr", "Suriname"                             },
477        { 744, "sj", "Svalbard & Jan Mayen Islands"         },
478        { 748, "sz", "Swaziland"                            },
479        { 752, "se", "Sweden"                               },
480        { 756, "ch", "Switzerland"                          },
481        { 760, "sy", "Syrian Arab Republic"                 },
482        { 626, "tl", "Timor-Leste"                          },
483        { 158, "tw", "Taiwan"                               },
484        { 762, "tj", "Tajikistan"                           },
485        { 834, "tz", "Tanzania"                             },
486        { 764, "th", "Thailand"                             },
487        { 768, "tg", "Togo"                                 },
488        { 772, "tk", "Tokelau"                              },
489        { 776, "to", "Tonga"                                },
490        { 780, "tt", "Trinidad & Tobago"                    },
491        { 788, "tn", "Tunisia"                              },
492        { 792, "tr", "Turkey"                               },
493        { 795, "tm", "Turkmenistan"                         },
494        { 796, "tc", "Turks & Caicos Islands"               },
495        { 798, "tv", "Tuvalu"                               },
496        { 800, "ug", "Uganda"                               },
497        { 804, "ua", "Ukraine"                              },
498        { 784, "ae", "United Arab Emirates"                 },
499        { 826, "gb", "United Kingdom"                       },
500        { 840, "us", "United States"                        },
501        { 581, "um", "United States Minor Outlying Islands" },
502        { 858, "uy", "Uruguay"                              },
503        { 860, "uz", "Uzbekistan"                           },
504        { 548, "vu", "Vanuatu"                              },
505        { 862, "ve", "Venezuela"                            },
506        { 704, "vn", "Vietnam"                              },
507        {  92, "vg", "Virgin Islands (British)"             },
508        { 850, "vi", "Virgin Islands (US)"                  },
509        { 876, "wf", "Wallis & Futuna Islands"              },
510        { 732, "eh", "Western Sahara"                       },
511        { 887, "ye", "Yemen"                                },
512        { 894, "zm", "Zambia"                               },
513        { 716, "zw", "Zimbabwe"                             }
514      };
515
516 /*
517  * Check if start of 'str' is simply an IPv4 address.
518  */
519 #define BYTE_OK(x) ((x) >= 0 && (x) <= 255)
520
521 static int is_addr(char *str, char **end)
522 {
523   int a0, a1, a2, a3, num, rc = 0, length = 0;
524
525   num = sscanf(str,"%3d.%3d.%3d.%3d%n",&a0,&a1,&a2,&a3,&length);
526   if( (num == 4) &&
527       BYTE_OK(a0) && BYTE_OK(a1) && BYTE_OK(a2) && BYTE_OK(a3) &&
528       length >= (3+4))
529     {
530       rc = 1;
531       *end = str + length;
532     }
533   return rc;
534 }
535
536 /*
537  * Find the country-code and name from the CNAME. E.g.:
538  *   version 1: CNAME = zzno.countries.nerd.dk with address 127.0.2.66
539  *              yields ccode_A" = "no" and cnumber 578 (2.66).
540  *   version 2: CNAME = <a.b.c.d>.zz.countries.nerd.dk with address 127.0.2.66
541  *              yields cnumber 578 (2.66). ccode_A is "";
542  */
543 static void find_country_from_cname(const char *cname, struct in_addr addr)
544 {
545   const struct search_list *country;
546   char  ccode_A2[3], *ccopy, *dot_4;
547   int   cnumber, z0, z1, ver_1, ver_2;
548   unsigned long ip;
549
550   ip = ntohl(addr.s_addr);
551   z0 = TOLOWER(cname[0]);
552   z1 = TOLOWER(cname[1]);
553   ccopy = strdup(cname);
554   dot_4 = NULL;
555
556   ver_1 = (z0 == 'z' && z1 == 'z' && !strcasecmp(cname+4,nerd_ver1));
557   ver_2 = (is_addr(ccopy,&dot_4) && !strcasecmp(dot_4,nerd_ver2));
558
559   if (ver_1)
560     {
561       const char *dot = strchr(cname, '.');
562       if ((z0 != 'z' && z1 != 'z') || dot != cname+4)
563         {
564           printf("Unexpected CNAME %s (ver_1)\n", cname);
565           if (ccopy)
566                   free(ccopy);
567           return;
568         }
569     }
570   else if (ver_2)
571     {
572       z0 = TOLOWER(dot_4[1]);
573       z1 = TOLOWER(dot_4[2]);
574       if (z0 != 'z' && z1 != 'z')
575         {
576           printf("Unexpected CNAME %s (ver_2)\n", cname);
577           if (ccopy)
578                   free(ccopy);
579           return;
580         }
581     }
582   else
583     {
584       printf("Unexpected CNAME %s (ver?)\n", cname);
585       if (ccopy)
586               free(ccopy);
587       return;
588     }
589
590   if (ver_1)
591     {
592       ccode_A2[0] = (char)TOLOWER(cname[2]);
593       ccode_A2[1] = (char)TOLOWER(cname[3]);
594       ccode_A2[2] = '\0';
595     }
596   else
597     ccode_A2[0] = '\0';
598
599   cnumber = ip & 0xFFFF;
600
601   TRACE(("Found country-code `%s', number %d\n",
602          ver_1 ? ccode_A2 : "<n/a>", cnumber));
603
604   country = list_lookup(cnumber, country_list,
605                         sizeof(country_list) / sizeof(country_list[0]));
606   if (!country)
607     printf("Name for country-number %d not found.\n", cnumber);
608   else
609     {
610       if (ver_1)
611         {
612           if ((country->short_name[0] != ccode_A2[0]) ||
613               (country->short_name[1] != ccode_A2[1]) ||
614               (country->short_name[2] != ccode_A2[2]))
615             printf("short-name mismatch; %s vs %s\n",
616                    country->short_name, ccode_A2);
617         }
618       printf("%s (%s), number %d.\n",
619              country->long_name, country->short_name, cnumber);
620     }
621   free(ccopy);
622 }
623