示例#1
0
/*! char *
 * isc_net_ntop(af, src, dst, size)
 *	convert a network format address to presentation format.
 * \return
 *	pointer to presentation format address (`dst'), or NULL (see errno).
 * \author
 *	Paul Vixie, 1996.
 */
const char *
isc_net_ntop(int af, const void *src, char *dst, size_t size)
{
	switch (af) {
	case AF_INET:
		return (inet_ntop4(src, dst, size));
#ifdef AF_INET6
	case AF_INET6:
		return (inet_ntop6(src, dst, size));
#endif
	default:
		errno = EAFNOSUPPORT;
		return (NULL);
	}
	/* NOTREACHED */
}
示例#2
0
文件: ntop.c 项目: allanlei/lib-re
const char* inet_ntop(int af, const void *src, char *dst, size_t size)
{
	switch (af) {

	case AF_INET:
		return inet_ntop4(src, dst, size);

#ifdef HAVE_INET6
	case AF_INET6:
		return inet_ntop6(src, dst, size);
#endif

	default:
		DEBUG_WARNING("inet_ntop: unknown address family %d\n", af);
		return NULL;
	}
}
示例#3
0
/* char *
 * inet_ntop(af, src, dst, size)
 *	convert a network format address to presentation format.
 * return:
 *	pointer to presentation format address (`dst'), or NULL (see errno).
 * author:
 *	Paul Vixie, 1996.
 */
const char *
inet_ntop(int af, const void *src, char *dst, size_t size)
{

	switch (af) {
	case AF_INET:
		return (inet_ntop4(src, dst, size));
#ifdef INET6
	case AF_INET6:
		return (inet_ntop6(src, dst, size));
#endif
	default:
		WSASetLastError(WSAEAFNOSUPPORT);
		return (NULL);
	}
	/* NOTREACHED */
}
示例#4
0
/**
 * dump a jk_sockaddr_t in A.B.C.D:P in ASCII buffer
 *
 */
char *jk_dump_hinfo(jk_sockaddr_t *saddr, char *buf, size_t size)
{
    char pb[8];

    if (saddr->family == JK_INET) {
        inet_ntop4(saddr->ipaddr_ptr, buf, size);
    }
#if JK_HAVE_IPV6
    else {
        inet_ntop6(saddr->ipaddr_ptr, buf, size);
    }
#endif
    sprintf(pb, ":%d", saddr->port);

    strncat(buf, pb, size - strlen(buf) - 1);
    return buf;
}
示例#5
0
/* char *
 * inet_ntop(af, src, dst, size)
 *	convert a network format address to presentation format.
 * return:
 *	pointer to presentation format address (`dst'), or NULL (see errno).
 * author:
 *	Paul Vixie, 1996.
 */
const char *
inet_ntop(int af, const void *src, char *dst, size_t size)
{
	switch (af) {
	case AF_INET:
		return (inet_ntop4((const unsigned char *) src, dst, size));
#if HAVE_IPV6
	case AF_INET6:
		return (inet_ntop6((const unsigned char *) src, dst, size));
#endif
	default:
#ifndef WIN32
		errno = EAFNOSUPPORT;
#endif
		return (NULL);
	}
	/* NOTREACHED */
}
示例#6
0
/* char *
 * inet_ntop(af, src, dst, size)
 *	convert a network format address to presentation format.
 * return:
 *	pointer to presentation format address (`dst'), or NULL (see errno).
 * author:
 *	Paul Vixie, 1996.
 */
const char *
inet_ntop(int af, const void *src, char *dst, size_t size)
{
	switch (af) {
	case AF_INET:
		return (inet_ntop4(src, dst, size));
	case AF_INET6:
		return (inet_ntop6(src, dst, size));
	default:
#ifdef EAFNOSUPPORT
		errno = EAFNOSUPPORT;
#else
		errno = ENOSYS;
#endif
		return (NULL);
	}
	/* NOTREACHED */
}
示例#7
0
/* char *
 * inet_ntop(af, src, dst, size)
 *	convert a network format address to presentation format.
 * return:
 *	pointer to presentation format address (`dst'), or NULL (see errno).
 * author:
 *	Paul Vixie, 1996.
 */
const char *
inet_ntop(int af, const void *src, char *dst, int size)
{
	if (size < 0) {
		errno = ENOSPC;
		return NULL;
	}
	switch (af) {
	case AF_INET:
		return (inet_ntop4(src, dst, size));
	case AF_INET6:
		return (inet_ntop6(src, dst, size));
	default:
		errno = EAFNOSUPPORT;
		return (NULL);
	}
	/* NOTREACHED */
}
示例#8
0
/* char *
 * inet_ntop(af, src, dst, size)
 *	convert a network format address to presentation format.
 * return:
 *	pointer to presentation format address (`dst'), or NULL (see errno).
 * author:
 *	Paul Vixie, 1996.
 */
const char *
inet_ntop(int af, const void *src, char *dst, socklen_t size)
{

	_DIAGASSERT(src != NULL);
	_DIAGASSERT(dst != NULL);

	switch (af) {
	case AF_INET:
		return (inet_ntop4(src, dst, size));
	case AF_INET6:
		return (inet_ntop6(src, dst, size));
	default:
		errno = EAFNOSUPPORT;
		return (NULL);
	}
	/* NOTREACHED */
}
示例#9
0
/* char *
 * inetntop(af, src, dst, size)
 *	convert a network format address to presentation format.
 * return:
 *	pointer to presentation format address (`dst'), or NULL (see errno).
 * author:
 *	Paul Vixie, 1996.
 */
const char *
inetntop(int af, const void *src, char *dst, unsigned int size)
{
  switch (af)
  {
    case AF_INET:
      return inet_ntop4(src, dst, size);
#ifdef IPV6
    case AF_INET6:
      if (IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)src) ||
          IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)src))
        return inet_ntop4((unsigned char *)&((const struct in6_addr *)src)->s6_addr[12], dst, size);
      else 
        return inet_ntop6(src, dst, size);
#endif
    default:
      return NULL;
  }
  /* NOTREACHED */
}
int run_tests() {
    int i;
    int success = 0, total = 0;
    for (i = 0; i < (sizeof(test_cases) / sizeof(test_cases[0])); i++) {
        struct in6_addr addr, correct;
        uint8_t buf[512];
        char *rv;
        ieee154_addr_t l2addr;
        total++;

        inet_pton6(test_cases[i].address, &correct);

        ieee154_parse(test_cases[i].l2addr, &l2addr);
        ieee154_print(&l2addr, buf, 512);
        printf("%s\n", buf);
        printf("in6_addr: %s\n", test_cases[i].address);
        rv = unpack_address(&addr, test_cases[i].dispatch, test_cases[i].context,
                            test_cases[i].buf, &l2addr, test_cases[i].panid);

        inet_ntop6(&addr, buf, 512);
        printf("result: %s length: %li\n", buf, rv - test_cases[i].buf);

        if (test_cases[i].len != rv - test_cases[i].buf) {
            printf("case %u: result len: %li expected: %i\n",
                   i, rv - test_cases[i].buf, test_cases[i].len);
            continue;
        }

        if (memcmp(&addr, &correct, 16) != 0) {
            printf("case %u: unexpected result\n", i);
            print_buffer(correct.s6_addr, 16);
            print_buffer(addr.s6_addr, 16);
            continue;
        }

        success++;
    }
    printf("%s: %i/%i tests succeeded\n", __FILE__, success, total);
    if (success == total) return 0;
    return 1;
}
示例#11
0
/*
 * Now parsed information should be placed in config manager
 * in accordance with information provided by interface manager
 */
bool TSrvCfgMgr::matchParsedSystemInterfaces(SrvParser *parser) {
    int cfgIfaceCnt;
    cfgIfaceCnt = parser->SrvCfgIfaceLst.count();
    Log(Debug) << cfgIfaceCnt << " interface(s) specified in " << SRVCONF_FILE << LogEnd;

    SPtr<TSrvCfgIface> cfgIface;
    SPtr<TIfaceIface>  ifaceIface;

    parser->SrvCfgIfaceLst.first();
    while(cfgIface=parser->SrvCfgIfaceLst.get()) {
	// for each interface from config file

	// map deny and allow list
    	cfgIface->mapAllowDenyList(parser->SrvCfgClientClassLst);

	// relay interface
	if (cfgIface->isRelay()) {
	    cfgIface->setID(this->NextRelayID++);
	    if (!this->setupRelay(cfgIface)) {
		return false;
	    }
	    this->addIface(cfgIface);

	    continue; // skip physical interface checking part
	}

	// physical interface
	if (cfgIface->getID()==-1) {
	    // ID==-1 means that user referenced to interface by name
	    ifaceIface = SrvIfaceMgr().getIfaceByName(cfgIface->getName());
	} else {
	    ifaceIface = SrvIfaceMgr().getIfaceByID(cfgIface->getID());
	}
	if (!ifaceIface) {
	    Log(Crit) << "Interface " << cfgIface->getFullName()
		      << " is not present in the system or does not support IPv6."
		      << LogEnd;
	    return false;
	}

	// Complete name and ID (one of them usually misses depending on
	// identifier used in config file.
	/// @todo: Client's class uses setIface{Name,ID}(). We should unite the
	// method names.
	cfgIface->setName(ifaceIface->getName());
	cfgIface->setID(ifaceIface->getID());


	// Check for link scope address presence
        if (!ifaceIface->countLLAddress()) {
            if (this->inactiveMode()) {
                Log(Notice) << "Interface " << ifaceIface->getFullName()
                            << " is not operational yet (does not have link scope address), skipping it for now." << LogEnd;
                this->addIface(cfgIface);
                this->makeInactiveIface(cfgIface->getID(), true); // move it to InactiveLst
		continue;
            }

	    Log(Crit) << "Interface " << ifaceIface->getName() << "/" << ifaceIface->getID()
		      << " is down or doesn't have any link scope address." << LogEnd;
	    return false;
        }

	// Check if the interface is during bring-up phase (i.e. DAD procedure for link-local addr is not complete yet)
	char tmp[64];
	ifaceIface->firstLLAddress();
	inet_ntop6(ifaceIface->getLLAddress(), tmp);
	if (is_addr_tentative(ifaceIface->getName(), ifaceIface->getID(), tmp) == LOWLEVEL_TENTATIVE_YES) {
	    Log(Notice) << "Interface " << ifaceIface->getFullName() << " has link-scope address " << tmp
			<< ", but it is currently tentative." << LogEnd;

	    if (this->inactiveMode()) {
		Log(Notice) << "Interface " << ifaceIface->getFullName()
			    << " is not operational yet (link-scope address is not ready), skipping it for now." << LogEnd;
		addIface(cfgIface);
		makeInactiveIface(cfgIface->getID(), true); // move it to InactiveLst
		continue;
	    }

	    Log(Crit) << "Interface " << ifaceIface->getFullName()
		      << " has tentative link-scope address (and inactive-mode is disabled)." << LogEnd;
	    return false;

	}

	this->addIface(cfgIface);
	Log(Info) << "Interface " << cfgIface->getFullName()
		  << " configuration has been loaded." << LogEnd;
    }
    return true;
}
示例#12
0
void printfUART_in6addr(struct in6_addr *a) {
  static char print_buf[64];
  inet_ntop6(a, print_buf, 64);
  printf(print_buf);
}
示例#13
0
void TIPv6Addr::setAddr(char* addr) {
    memcpy(Addr,addr,16);
    inet_ntop6(Addr,Plain);
}
示例#14
0
char* TIPv6Addr::getPlain() {
    inet_ntop6( Addr, Plain);
    return Plain;
}
示例#15
0
TIPv6Addr::TIPv6Addr() {
    memset(Addr,0,16);
    inet_ntop6(Addr,Plain);
}