Beispiel #1
0
int uv_inet_pton(int af, const char* src, void* dst) {
  if (src == NULL || dst == NULL)
    return UV_EINVAL;

  switch (af) {
  case AF_INET:
    return (inet_pton4(src, dst));
  case AF_INET6: {
    int len;
    char tmp[UV__INET6_ADDRSTRLEN], *s, *p;
    s = (char*) src;
    p = strchr(src, '%');
    if (p != NULL) {
      s = tmp;
      len = p - src;
      if (len > UV__INET6_ADDRSTRLEN-1)
        return UV_EINVAL;
      memcpy(s, src, len);
      s[len] = '\0';
    }
    return inet_pton6(s, dst);
  }
  default:
    return UV_EAFNOSUPPORT;
  }
  /* NOTREACHED */
}
Beispiel #2
0
static int inet_pton6(const char *src, unsigned char *dst) {
  static const char xdigits_l[] = "0123456789abcdef",
                    xdigits_u[] = "0123456789ABCDEF";
  unsigned char tmp[sizeof(struct in6_addr)], *tp, *endp, *colonp;
  const char *xdigits, *curtok;
  int ch, seen_xdigits;
  unsigned int val;

  memset((tp = tmp), '\0', sizeof tmp);
  endp = tp + sizeof tmp;
  colonp = NULL;
  /* Leading :: requires some special handling. */
  if (*src == ':')
    if (*++src != ':')
      return UV_EINVAL;
  curtok = src;
  seen_xdigits = 0;
  val = 0;
  while ((ch = *src++) != '\0') {
    const char *pch;

    if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
      pch = strchr((xdigits = xdigits_u), ch);
    if (pch != NULL) {
      val <<= 4;
      val |= (pch - xdigits);
      if (++seen_xdigits > 4)
        return UV_EINVAL;
      continue;
    }
    if (ch == ':') {
      curtok = src;
      if (!seen_xdigits) {
        if (colonp)
          return UV_EINVAL;
        colonp = tp;
        continue;
      } else if (*src == '\0') {
        return UV_EINVAL;
      }
      if (tp + sizeof(uint16_t) > endp)
        return UV_EINVAL;
      *tp++ = (unsigned char) (val >> 8) & 0xff;
      *tp++ = (unsigned char) val & 0xff;
      seen_xdigits = 0;
      val = 0;
      continue;
    }
    if (ch == '.' && ((tp + sizeof(struct in_addr)) <= endp)) {
      int err = inet_pton4(curtok, tp);
      if (err == 0) {
        tp += sizeof(struct in_addr);
        seen_xdigits = 0;
        break;  /*%< '\\0' was seen by inet_pton4(). */
      }
    }
    return UV_EINVAL;
  }
Beispiel #3
0
/* int
 * inet_pton6(src, dst)
 *	convert presentation level address to network order binary form.
 * return:
 *	1 if `src' is a valid [RFC1884 2.2] address, else 0.
 * notice:
 *	(1) does not touch `dst' unless it's returning 1.
 *	(2) :: in a full address is silently ignored.
 * credit:
 *	inspired by Mark Andrews.
 * author:
 *	Paul Vixie, 1996.
 */
static int
inet_pton6(const char *src, unsigned char *dst)
{
	static const char xdigits_l[] = "0123456789abcdef",
			  xdigits_u[] = "0123456789ABCDEF";
	unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
	const char *xdigits, *curtok;
	int ch, saw_xdigit;
	unsigned int val;

	memset((tp = tmp), '\0', NS_IN6ADDRSZ);
	endp = tp + NS_IN6ADDRSZ;
	colonp = NULL;
	/* Leading :: requires some special handling. */
	if (*src == ':')
		if (*++src != ':')
			return (0);
	curtok = src;
	saw_xdigit = 0;
	val = 0;
	while ((ch = *src++) != '\0') {
		const char *pch;

		if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
			pch = strchr((xdigits = xdigits_u), ch);
		if (pch != NULL) {
			val <<= 4;
			val |= (pch - xdigits);
			if (val > 0xffff)
				return (0);
			saw_xdigit = 1;
			continue;
		}
		if (ch == ':') {
			curtok = src;
			if (!saw_xdigit) {
				if (colonp)
					return (0);
				colonp = tp;
				continue;
			} else if (*src == '\0')
				return (0);
			if (tp + NS_INT16SZ > endp)
				return (0);
			*tp++ = (unsigned char) (val >> 8) & 0xff;
			*tp++ = (unsigned char) val & 0xff;
			saw_xdigit = 0;
			val = 0;
			continue;
		}
		if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
		    inet_pton4(curtok, tp, 1) > 0) {
			tp += NS_INADDRSZ;
			saw_xdigit = 0;
			break;	/* '\0' was seen by inet_pton4(). */
		}
		return (0);
	}
Beispiel #4
0
/* int
 * inet_pton6(src, dst)
 *	convert presentation level address to network order binary form.
 * return:
 *	1 if `src' is a valid [RFC1884 2.2] address, else 0.
 * notice:
 *	(1) does not touch `dst' unless it's returning 1.
 *	(2) :: in a full address is silently ignored.
 * credit:
 *	inspired by Mark Andrews.
 * author:
 *	Paul Vixie, 1996.
 */
static int
inet_pton6(const char *src, unsigned char *dst)
{
	uint8_t tmp[16], *tp, *endp, *colonp;
	const char *curtok;
	int ch, saw_xdigit;
	unsigned val;

	memset((tp = tmp), '\0', sizeof tmp);
	endp = tp + sizeof tmp;
	colonp = NULL;
	/* Leading :: requires some special handling. */
	if (*src == ':')
		if (*++src != ':')
			return (0);
	curtok = src;
	saw_xdigit = 0;
	val = 0;
	while ((ch = *src++) != '\0') {
		if (ch == ':') {
			curtok = src;
			if (!saw_xdigit) {
				if (colonp)
					return (0);
				colonp = tp;
				continue;
			} else if (*src == '\0') {
				return (0);
			}
			if (tp + 2 > endp)
				return (0);
			*tp++ = (unsigned char) (val >> 8) & 0xff;
			*tp++ = (unsigned char) val & 0xff;
			saw_xdigit = 0;
			val = 0;
			continue;
		}
		if (ch == '.' && ((tp + 4) <= endp) &&
		    inet_pton4(curtok, tp) > 0) {
			tp += 4;
			saw_xdigit = 0;
			break;	/* '\0' was seen by inet_pton4(). */
		}

		if ('0' <= ch && ch <= '9')
			ch = ch - '0';
		else if ('A' <= ch && ch <= 'F')
			ch = ch - 'A' + 10;
		else if ('a' <= ch && ch <= 'f')
			ch = ch - 'a' + 10;
		else
			return (0);
		val <<= 4;
		val |= ch;
		if (val > 0xffff)
			return (0);
		saw_xdigit = 1;
	}
Beispiel #5
0
int inet_pton(int af, const char *src, char *dst)
{
	switch (af) {
	case AF_INET:
		return (inet_pton4(src, dst));

	default:
		errno = EAFNOSUPPORT;
		return -1;
	}
}
Beispiel #6
0
int uv_inet_pton(int af, const char* src, void* dst) {
  if (src == NULL || dst == NULL)
    return UV_EINVAL;

  switch (af) {
  case AF_INET:
    return (inet_pton4(src, dst));
  default:
    return UV_EAFNOSUPPORT;
  }
  /* NOTREACHED */
}
Beispiel #7
0
int portable_pton(int af, char* src, void* dst)
{
    switch (af) {
        case AF_INET:
            return (inet_pton4(src, dst));
        case AF_INET6:
            return (inet_pton6(src, dst));
        default:
            return EAFNOSUPPORT;
    }
    /* NOTREACHED */
}
Beispiel #8
0
result_t net_base::isIPv4(exlib::string ip, bool& retVal)
{
    result_t hr;

    retVal = true;
    const char* src = ip.c_str();
    unsigned char dst[sizeof(struct in6_addr)];
    hr = inet_pton4(src, dst);
    if (hr != 0)
        retVal = false;
    return 0;
}
Beispiel #9
0
int
inet_pton(int af, const char* src, void *dst)
{
  switch (af) {
    case AF_INET:
      return (inet_pton4(src, dst) );
//    case AF_INET6:
//      return (inet_pton6(src, dst) );
    default: 
      errno = EAFNOSUPPORT;
      return(-1);
  }
}
Beispiel #10
0
/*%
 *	convert from presentation format (which usually means ASCII printable)
 *	to network format (which is usually some kind of binary format).
 * \return
 *	1 if the address was valid for the specified address family
 *	0 if the address wasn't valid (`dst' is untouched in this case)
 *	-1 if some other error occurred (`dst' is untouched in this case, too)
 * \author
 *	Paul Vixie, 1996.
 */
int
isc_net_pton(int af, const char *src, void *dst) {
	switch (af) {
	case AF_INET:
		return (inet_pton4(src, dst));
	case AF_INET6:
		return (inet_pton6(src, dst));
	default:
		errno = EAFNOSUPPORT;
		return (-1);
	}
	/* NOTREACHED */
}
Beispiel #11
0
int inet_pton(int af, const char *src, void *dst)
{
  switch (af) {
  case AF_INET:
    return (inet_pton4(src, (unsigned char *)dst));
#ifdef ENABLE_IPV6
  case AF_INET6:
    return (inet_pton6(src, (unsigned char *)dst));
#endif
  default:
    SET_ERRNO(EAFNOSUPPORT);
    return (-1);
  }
  /* NOTREACHED */
}
Beispiel #12
0
int os_inet_pton(int af,
	  const char *src,
	  void *dst)
{
	switch (af) {
	case AF_INET:
		return (inet_pton4(src, (unsigned char *)dst));
	case AF_INET6:
		return (inet_pton6(src, (unsigned char *)dst));
	default:
		errno = WSAEAFNOSUPPORT;
		return (-1);
	}
	/* NOTREACHED */
}
Beispiel #13
0
/** inet_pton() replacement.
 *
 * Convert from presentation format in @a src (which usually means ASCII printable)
 * to network format in @a dst (which is usually some kind of binary format).
 *
 * @param af[in] address family
 * @param src[in] string containing address to convert
 * @param dst[out] return-value network address
 *                 (struct in_addr or struct in_addr6)
 *
 * @retval 1 if the address was valid for the specified address family
 * @retval 0 if the address wasn't valid (`dst' is untouched in this case)
 * @retval -1 if some other error occurred (`dst' is untouched in this case, too)
 *
 * @author Paul Vixie, 1996.
 *
 * @NEW_1_12_9
 */
int
su_inet_pton(int af, const char * src, void * dst)
{
	switch (af) {
	case AF_INET:
		return (inet_pton4(src, dst));
#if HAVE_SIN6
	case AF_INET6:
		return (inet_pton6(src, dst));
#endif
	default:
		su_seterrno(EAFNOSUPPORT);
		return (-1);
	}
	/* NOTREACHED */
}
Beispiel #14
0
/* int
 * isc_net_pton(af, src, dst)
 *      convert from presentation format (which usually means ASCII printable)
 *      to network format (which is usually some kind of binary format).
 * return:
 *      1 if the address was valid for the specified address family
 *      0 if the address wasn't valid (`dst' is untouched in this case)
 * author:
 *      Paul Vixie, 1996.
 */
int
inet_pton(int af,
          const char *src,
          void *dst) {
    switch ( af ) {
        case AF_INET:
            return(inet_pton4(src, (unsigned char *) dst));
#ifdef HAVE_IPV6
        case AF_INET6:
            return(inet_pton6(src, (unsigned char *) dst));
#endif
        default:
            return 0;
    }
    /* NOTREACHED */
}
Beispiel #15
0
int inet_pton(int af, const char* src, void* dst)
{
	switch (af) {
		case AF_INET:
			return inet_pton4(src, (unsigned char *)dst);

#if defined(AF_INET6)
		case AF_INET6:
			/*return inet_pton6(src, (unsigned char *)dst); */
#endif

		default:
			return 0;
	}
	/* NOTREACHED */
}
Beispiel #16
0
/* int
 * inet_pton(af, src, dst)
 *	convert from presentation format (which usually means ASCII printable)
 *	to network format (which is usually some kind of binary format).
 * return:
 *	1 if the address was valid for the specified address family
 *	0 if the address wasn't valid (`dst' is untouched in this case)
 *	-1 if some other error occurred (`dst' is untouched in this case, too)
 * author:
 *	Paul Vixie, 1996.
 */
int
inet_pton(int af, const char *src, void *dst)
{

	switch (af) {
	case AF_INET:
		return (inet_pton4(src, dst, 1));
#ifdef INET6
	case AF_INET6:
		return (inet_pton6(src, dst));
#endif /* INET6 */
	default:
		errno = EAFNOSUPPORT;
		return (-1);
	}
	/* NOTREACHED */
}
Beispiel #17
0
/* int
 * inet_pton(af, src, dst)
 *      convert from presentation format (which usually means ASCII printable)
 *      to network format (which is usually some kind of binary format).
 * return:
 *      1 if the address was valid for the specified address family
 *      0 if the address wasn't valid (`dst' is untouched in this case)
 *      -1 if some other error occurred (`dst' is untouched in this case, too)
 * author:
 *      Paul Vixie, 1996.
 */
SWITCH_DECLARE(int) switch_inet_pton(int af, const char *src, void *dst)
{
	switch (af) {
	case AF_INET:
		return (inet_pton4(src, (unsigned char *) dst));
#ifdef ENABLE_IPV6
#ifndef AF_INET6
#define AF_INET6        (AF_MAX+1)	/* just to let this compile */
#endif
	case AF_INET6:
		return (inet_pton6(src, (unsigned char *) dst));
#endif
	default:
		errno = EAFNOSUPPORT;
		return (-1);
	}
	/* NOTREACHED */
}
Beispiel #18
0
/* int
 * inet_pton(af, src, dst)
 *	convert from presentation format (which usually means ASCII printable)
 *	to network format (which is usually some kind of binary format).
 * return:
 *	1 if the address was valid for the specified address family
 *	0 if the address wasn't valid (`dst' is untouched in this case)
 *	-1 if some other error occurred (`dst' is untouched in this case, too)
 * author:
 *	Paul Vixie, 1996.
 */
int
Curl_inet_pton(int af, const char *src, void *dst)
{
	switch (af) {
	case AF_INET:
		return (inet_pton4(src, dst));
#ifdef ENABLE_IPV6
#ifndef	AF_INET6
#define	AF_INET6	AF_MAX+1	/* just to let this compile */
#endif
	case AF_INET6:
		return (inet_pton6(src, dst));
#endif
	default:
		errno = EAFNOSUPPORT;
		return (-1);
	}
	/* NOTREACHED */
}
Beispiel #19
0
int
ce_inet_pton(int af,
	       const char *src, 
	       void *dst)
{
	switch (af) 
	{
		case AF_INET:
			return (inet_pton4(src, (unsigned char*)dst));
	#if APR_HAVE_IPV6
		case AF_INET6:
		return (inet_pton6(src, dst));
	#endif
		default:
		errno = EAFNOSUPPORT;
		return (-1);
	}
	/* NOTREACHED */
}
Beispiel #20
0
static int ip4_addr(const char* ip, int port, struct sockaddr_in* addr) {
  memset(addr, 0, sizeof(*addr));
  addr->sin_family = AF_INET;
  addr->sin_port = port;
  return inet_pton4(ip, (unsigned char *)&(addr->sin_addr.s_addr));
}