Пример #1
0
ldns_rr_list *mrb_getname_rr_list(mrb_state *mrb, ldns_resolver *resolver,char *addr)
{
    char *rev = NULL,
         *query = NULL;
    const char *arpa = "in-addr.arpa";
    ldns_rdf *domain = NULL ;
    ldns_pkt *pkt = NULL;
    ldns_rr_list *records = NULL;


    rev = reverse_addr(addr);
    if(!rev)
    {
        return NULL;
    }

    query = (char *)malloc( strlen(rev) + strlen(arpa) + sizeof(char) * 4); 
    strcpy(query, rev);
    strcat(query,".");
    strcat(query,arpa);

    domain = ldns_dname_new_frm_str(query); 
    free(query);
    if(!domain)
    {
        return NULL;
    }

    pkt = ldns_resolver_query(resolver,
                             domain,
                             LDNS_RR_TYPE_PTR,
                             LDNS_RR_CLASS_IN,
                             LDNS_RD);
    ldns_rdf_deep_free(domain);
    if(!pkt)
    {
        return NULL;
    }

    records = ldns_pkt_rr_list_by_type(pkt, LDNS_RR_TYPE_PTR, LDNS_RR_CLASS_IN);
    ldns_pkt_free(pkt);
    if(!records)
    {
        return NULL;
    }

    return records;
}
Пример #2
0
void write_afwd (FILE *f, afwd_data *adrs, int count)
//*************************************************************************
//
// write data to afwd.bcm
//
//*************************************************************************
{
  char fp[CALLEN+1];
  int i;
  int len;

  while (1)
  {
    i = 0;
    while (! adrs[i].partner[0] && i < count) i++;
    if (i == count) break;
    strcpy(fp, adrs[i].partner);
    fprintf(f, "%s\n", fp);
    len = 0;
    while (i < count)
    {
      if (adrs[i].partner[0] && ! strcmp(fp, adrs[i].partner))
      {
        len += strlen(adrs[i].shortaddr) + 1;
        if (len > 40)
        {
          fputc(LF, f);
          len = strlen(adrs[i].shortaddr) + 1;
        }
        fprintf(f, " %s", reverse_addr(adrs[i].shortaddr));
        adrs[i].partner[0] = 0;
      }
      i++;
    }
    fputc(LF, f);
  }
}
Пример #3
0
void afwdlist (char *)
//*************************************************************************
//
// afwd.bcm is generated here ..
//
//*************************************************************************
{
  char name[20];

  strcpy(name, "afwdlist");
  if (! m.hadrstore || ! m.autofwdtime) return; //afwd disabled
  // Alle boxen durchsuchen
//  trace(report, "afwdlist", "scanning HADR");
  unsigned int found = 0, i = 0;
  if (! (found = scan_hadr())) return;
  // Sort file by reversed short addr
  char linetmp[LINELEN+1];
  char *xx;
  afwd_data *adrs = (afwd_data*) t_malloc(sizeof(afwd_data) * found, "hadr");
  if (! adrs)
  {
    trace(serious, name, "out of memory");
    putf("not enough memory");
    return;
  }
#ifdef DEBUG_AFWD
  trace(report, name, "reading entries in memory");
#endif
  FILE *f = s_fopen(AFWDTMP, "srt");
  if (f)
  {
    while (fgets(linetmp, LINELEN, f))
    {
      //fwdcall, shortheader
      xx = strchr(linetmp, ' ');
      *xx++ = 0;
      strcpy(adrs[i].partner, linetmp);
      strcpy(adrs[i].shortaddr, reverse_addr(xx));
      i++;
    }
    s_fclose(f);
  }
  else
  {
    trace(serious, name, ms(m_filenotopen), AFWDTMP);
    putf(ms(m_filenotopen), AFWDTMP);
    t_free(adrs);
    return;
  }
#ifdef DEBUG_AFWD
  trace(report, name, "read %u", i);
  trace(report, name, "sorting ..");
#endif
  qsort(adrs, i, sizeof(afwd_data), data_cmp);
  found = process_afwd_data(adrs, found);
#ifdef DEBUG_AFWD
  trace(report, name, "writing "AFWDLISTNAME);
#endif
  f = s_fopen(AFWDLISTNAME, "lwt");
  if (! f)
  {
    trace(serious, name, ms(m_filenotopen), AFWDLISTNAME);
    putf(ms(m_filenotopen), AFWDLISTNAME);
    t_free(adrs);
    return;
  }
  fprintf(f, "; OpenBCM AutoFwd File !!! DO NOT EDIT !!!\n");
  fprintf(f, "; This file is generated automatically. (use %s for manual editing!)\n", FWDLISTNAME);
  write_afwd(f, adrs, found);
  s_fclose(f);
  t_free(adrs);
  initafwdlist();
}