static int nifs, debug_done;
static int debug_done;
Index2Nam(int idx){  /*   * XXX: Maybe we should select() on the routing socket so that we can   *      notice interfaces that come & go (PCCARD support).   *      Or we could even support a signal that resets these so that   *      the PCCARD insert/remove events can signal ppp.   */  static char **ifs;		/* Figure these out once */  static int nifs, debug_done;	/* Figure out how many once, and debug once */  if (idx > nifs || (idx > 0 && ifs[idx-1] == NULL)) {    int mib[6], have, had;    size_t needed;    char *buf, *ptr, *end;    struct sockaddr_dl *dl;    struct if_msghdr *ifm;    if (ifs) {      free(ifs);      ifs = NULL;      nifs = 0;    }    debug_done = 0;    mib[0] = CTL_NET;    mib[1] = PF_ROUTE;    mib[2] = 0;    mib[3] = 0;    mib[4] = NET_RT_IFLIST;    mib[5] = 0;    if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) {      log_Printf(LogERROR, "Index2Nam: sysctl: estimate: %s\n",                 strerror(errno));      return NumStr(idx, NULL, 0);    }    if ((buf = malloc(needed)) == NULL)      return NumStr(idx, NULL, 0);    if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {      free(buf);      return NumStr(idx, NULL, 0);    }    end = buf + needed;    have = 0;    for (ptr = buf; ptr < end; ptr += ifm->ifm_msglen) {      ifm = (struct if_msghdr *)ptr;      if (ifm->ifm_type != RTM_IFINFO)        continue;      dl = (struct sockaddr_dl *)(ifm + 1);      if (ifm->ifm_index > 0) {        if (ifm->ifm_index > have) {          char **newifs;          had = have;          have = ifm->ifm_index + 5;          if (had)            newifs = (char **)realloc(ifs, sizeof(char *) * have);          else            newifs = (char **)malloc(sizeof(char *) * have);          if (!newifs) {            log_Printf(LogDEBUG, "Index2Nam: %s\n", strerror(errno));            nifs = 0;            if (ifs) {              free(ifs);              ifs = NULL;            }            free(buf);            return NumStr(idx, NULL, 0);          }          ifs = newifs;          memset(ifs + had, '\0', sizeof(char *) * (have - had));        }        if (ifs[ifm->ifm_index-1] == NULL) {          ifs[ifm->ifm_index-1] = (char *)malloc(dl->sdl_nlen+1);          memcpy(ifs[ifm->ifm_index-1], dl->sdl_data, dl->sdl_nlen);          ifs[ifm->ifm_index-1][dl->sdl_nlen] = '\0';          if (nifs < ifm->ifm_index)            nifs = ifm->ifm_index;        }      } else if (log_IsKept(LogDEBUG))        log_Printf(LogDEBUG, "Skipping out-of-range interface %d!\n",                  ifm->ifm_index);    }    free(buf);  }  if (log_IsKept(LogDEBUG) && !debug_done) {    int f;    log_Printf(LogDEBUG, "Found the following interfaces:\n");    for (f = 0; f < nifs; f++)      if (ifs[f] != NULL)        log_Printf(LogDEBUG, " Index %d, name \"%s\"\n", f+1, ifs[f]);    debug_done = 1;  }  if (idx < 1 || idx > nifs || ifs[idx-1] == NULL)    return NumStr(idx, NULL, 0);  return ifs[idx-1];}