Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 36 lines (33 sloc) 0.72 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include "dns.h"
#include "dd.h"

int dd(const char *q,const char *base,char ip[4])
{
  int j;
  unsigned int x;

  for (j = 0;;++j) {
    if (dns_domain_equal(q,base)) return j;
    if (j >= 4) return -1;

    if (*q <= 0) return -1;
    if (*q >= 4) return -1;
    if ((q[1] < '0') || (q[1] > '9')) return -1;
    x = q[1] - '0';
    if (*q == 1) {
      ip[j] = x;
      q += 2;
      continue;
    }
    if (!x) return -1;
    if ((q[2] < '0') || (q[2] > '9')) return -1;
    x = x * 10 + (q[2] - '0');
    if (*q == 2) {
      ip[j] = x;
      q += 3;
      continue;
    }
    if ((q[3] < '0') || (q[3] > '9')) return -1;
    x = x * 10 + (q[3] - '0');
    if (x > 255) return -1;
    ip[j] = x;
    q += 4;
  }
}
Something went wrong with that request. Please try again.