// Return the dotted Internet address. const char * ACE_INET_Addr::get_host_addr (void) const { ACE_TRACE ("ACE_INET_Addr::get_host_addr"); #if defined (ACE_HAS_IPV6) static char buf[INET6_ADDRSTRLEN]; return this->get_host_addr (buf, INET6_ADDRSTRLEN); #else /* ACE_HAS_IPV6 */ # if defined (ACE_VXWORKS) // It would be nice to be able to encapsulate this into // ACE_OS::inet_ntoa(), but that would lead to either inefficiencies // on vxworks or lack of thread safety. // // So, we use the way that vxworks suggests. ACE_INET_Addr *ncthis = const_cast<ACE_INET_Addr *> (this); inet_ntoa_b (this->inet_addr_.in4_.sin_addr, ncthis->buf_); return &buf_[0]; # else /* ACE_VXWORKS */ return ACE_OS::inet_ntoa (this->inet_addr_.in4_.sin_addr); # endif /* !ACE_VXWORKS */ #endif /* !ACE_HAS_IPV6 */ }
const char * ACE_INET_Addr::get_host_addr (char *dst, int size) const { #if defined (ACE_HAS_IPV6) if (this->get_type () == AF_INET6) { if (IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr)) { ACE_UINT32 addr; addr = this->get_ip_address(); addr = ACE_HTONL (addr); return ACE_OS::inet_ntop (AF_INET, &addr, dst, size); } # if defined (ACE_WIN32) if (0 == ::getnameinfo (reinterpret_cast<const sockaddr*> (&this->inet_addr_.in6_), this->get_size (), dst, size, 0, 0, // Don't want service name NI_NUMERICHOST)) return dst; ACE_OS::set_errno_to_wsa_last_error (); return 0; # else const char *ch = ACE_OS::inet_ntop (AF_INET6, &this->inet_addr_.in6_.sin6_addr, dst, size); #if defined (__linux__) if ((IN6_IS_ADDR_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr)) && this->inet_addr_.in6_.sin6_scope_id != 0) { char scope_buf[32]; ACE_OS::sprintf (scope_buf, "%%%u", this->inet_addr_.in6_.sin6_scope_id); if ((ACE_OS::strlen (ch)+ACE_OS::strlen (scope_buf)) < (size_t)size) { ACE_OS::strcat (dst, scope_buf); } } #endif return ch; # endif /* ACE_WIN32 */ } #endif /* ACE_HAS_IPV6 */ #if defined (VXWORKS) ACE_UNUSED_ARG (dst); ACE_UNUSED_ARG (size); // It would be nice to be able to encapsulate this into // ACE_OS::inet_ntoa(), but that would lead to either inefficiencies // on vxworks or lack of thread safety. // // So, we use the way that vxworks suggests. ACE_INET_Addr *ncthis = const_cast<ACE_INET_Addr *> (this); inet_ntoa_b(this->inet_addr_.in4_.sin_addr, ncthis->buf_); ACE_OS::strsncpy (dst, &buf_[0], size); return &buf_[0]; #else /* VXWORKS */ char *ch = ACE_OS::inet_ntoa (this->inet_addr_.in4_.sin_addr); ACE_OS::strsncpy (dst, ch, size); return ch; #endif }
const char * ACE_INET_Addr::get_host_addr (char *dst, int size) const { #if defined (ACE_HAS_IPV6) if (this->get_type () == AF_INET6) { // [email protected] - Aug-26, 2005 // I don't think this should be done because it results in a decimal address // representation which is not distinguishable from the IPv4 form which makes // it impossible to resolve back to an IPv6 INET_Addr without prior knowledge // that this was such an address to begin with. //if (IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr)) //{ // ACE_UINT32 addr; // addr = this->get_ip_address(); // addr = ACE_HTONL (addr); // return ACE_OS::inet_ntop (AF_INET, &addr, dst, size); //} # if defined (ACE_WIN32) if (0 == ::getnameinfo (reinterpret_cast<const sockaddr*> (&this->inet_addr_.in6_), this->get_size (), dst, size, 0, 0, // Don't want service name NI_NUMERICHOST)) return dst; ACE_OS::set_errno_to_wsa_last_error (); return 0; # else const char *ch = ACE_OS::inet_ntop (AF_INET6, &this->inet_addr_.in6_.sin6_addr, dst, size); #if defined (__linux__) if ((IN6_IS_ADDR_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr)) && this->inet_addr_.in6_.sin6_scope_id != 0) { char scope_buf[32]; ACE_OS::sprintf (scope_buf, "%%%u", this->inet_addr_.in6_.sin6_scope_id); if ((ACE_OS::strlen (ch)+ACE_OS::strlen (scope_buf)) < (size_t)size) { ACE_OS::strcat (dst, scope_buf); } } #endif return ch; # endif /* ACE_WIN32 */ } #endif /* ACE_HAS_IPV6 */ #if defined (ACE_VXWORKS) ACE_UNUSED_ARG (dst); ACE_UNUSED_ARG (size); // It would be nice to be able to encapsulate this into // ACE_OS::inet_ntoa(), but that would lead to either inefficiencies // on vxworks or lack of thread safety. // // So, we use the way that vxworks suggests. ACE_INET_Addr *ncthis = const_cast<ACE_INET_Addr *> (this); inet_ntoa_b(this->inet_addr_.in4_.sin_addr, ncthis->buf_); ACE_OS::strsncpy (dst, &buf_[0], size); return &buf_[0]; #else /* ACE_VXWORKS */ char *ch = ACE_OS::inet_ntoa (this->inet_addr_.in4_.sin_addr); ACE_OS::strsncpy (dst, ch, size); return ch; #endif }
static unsigned long spawn_erlang_epmd(ei_cnode *ec, char *alive, Erl_IpAddr adr, int flags, char *erl_or_epmd, char *args[], int port, int is_erlang) { #if defined(VXWORKS) FUNCPTR erlfunc; #else /* Windows */ STARTUPINFO sinfo; SECURITY_ATTRIBUTES sa; PROCESS_INFORMATION pinfo; #endif char *cmdbuf; int cmdlen; char *ptr; int i; int num_args; char *name_format; struct in_addr myaddr; struct in_addr *hisaddr = (struct in_addr *)adr; char iaddrbuf[IP_ADDR_CHARS + 1]; int ret; if(is_erlang){ get_addr(ei_thishostname(ec), &myaddr); #if defined(VXWORKS) inet_ntoa_b(myaddr, iaddrbuf); #else /* Windows */ if((ptr = inet_ntoa(myaddr)) == NULL) return 0; else strcpy(iaddrbuf,ptr); #endif } if ((flags & ERL_START_REMOTE) || (is_erlang && (hisaddr->s_addr != myaddr.s_addr))) { return 0; } else { num_args = enquote_args(args, &args); for(cmdlen = i = 0; args[i] != NULL; ++i) cmdlen += strlen(args[i]) + 1; #if !defined(VXWORKS) /* On VxWorks, we dont actually run a command, we call start_erl() */ if(!erl_or_epmd) #endif erl_or_epmd = (is_erlang) ? DEF_ERL_COMMAND : DEF_EPMD_COMMAND; if(is_erlang){ name_format = (flags & ERL_START_LONG) ? ERL_NAME_FMT : ERL_SNAME_FMT; cmdlen += strlen(erl_or_epmd) + (*erl_or_epmd != '\0') + strlen(name_format) + 1 + strlen(alive) + strlen(ERL_REPLY_FMT) + 1 + strlen(iaddrbuf) + 2 * FORMATTED_INT_LEN + 1; ptr = cmdbuf = malloc(cmdlen); if(*erl_or_epmd != '\0') ptr += sprintf(ptr,"%s ",erl_or_epmd); ptr += sprintf(ptr, name_format, alive); ptr += sprintf(ptr, " " ERL_REPLY_FMT, iaddrbuf, port, unique_id()); } else { /* epmd */ cmdlen += strlen(erl_or_epmd) + (*erl_or_epmd != '\0') + 1; ptr = cmdbuf = malloc(cmdlen); if(*erl_or_epmd != '\0') ptr += sprintf(ptr,"%s ",erl_or_epmd); else *(ptr++) = '\0'; } for(i= 0; args[i] != NULL; ++i){ *(ptr++) = ' '; strcpy(ptr,args[i]); ptr += strlen(args[i]); } free_args(args); if (flags & ERL_START_VERBOSE) { fprintf(stderr,"erl_call: commands are %s\n",cmdbuf); } /* OK, one single command line... */ #if defined(VXWORKS) erlfunc = lookup_function((is_erlang) ? ERLANG_SYM : EPMD_SYM); if(erlfunc == NULL){ if (flags & ERL_START_VERBOSE) { fprintf(stderr,"erl_call: failed to find symbol %s\n", (is_erlang) ? ERLANG_SYM : EPMD_SYM); } ret = 0; } else { /* Just call it, it spawns itself... */ ret = (unsigned long) (*erlfunc)((int) cmdbuf,0,0,0,0,0,0,0,0,0); if(ret == (unsigned long) ERROR) ret = 0; } #else /* Windows */ /* Hmmm, hidden or unhidden window??? */ memset(&sinfo,0,sizeof(sinfo)); sinfo.cb = sizeof(STARTUPINFO); sinfo.dwFlags = STARTF_USESHOWWINDOW /*| STARTF_USESTDHANDLES*/; sinfo.wShowWindow = SW_HIDE; /* Hidden! */ sinfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); sinfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); sinfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = /*TRUE*/ FALSE; if(!CreateProcess( NULL, cmdbuf, &sa, NULL, /*TRUE*/ FALSE, 0 | CREATE_NEW_CONSOLE, NULL, NULL, &sinfo, &pinfo)) ret = 0; else ret = (unsigned long) pinfo.hProcess; #endif free(cmdbuf); return ret; } /* NOTREACHED */ }
LOCAL int _routeNodeDelete ( struct rtentry * pRt, /* pointer to the rtentry structure */ int * pDeleted /* counts # of deleted routes */ ) { FAST struct sockaddr * destAddr = NULL; FAST struct sockaddr * gateAddr; int proto; long mask; #ifdef DEBUG char aStr [INET_ADDR_LEN]; char bStr [INET_ADDR_LEN]; char cStr [INET_ADDR_LEN]; #endif /* DEBUG */ destAddr = rt_key(pRt); /* get the destination address */ gateAddr = pRt->rt_gateway; /* get the gateway address */ #ifdef DEBUG inet_ntoa_b (((struct sockaddr_in *)destAddr)->sin_addr, aStr); logMsg ("_routeNodeDelete: Called for %s, if=%s%d, proto=%d, type = %s\n", (int)aStr, (int)(pRt->rt_ifp->if_name), pRt->rt_ifp->if_unit, RT_PROTO_GET (destAddr), (int)"NON_ARP", 0); #endif /* DEBUG */ /* * We delete only statically added routes, interface routes and ICMP * routes. All other routes belong to the respective routing protocols * that should be deleting them */ if ((proto = RT_PROTO_GET (destAddr)) != M2_ipRouteProto_other && proto != M2_ipRouteProto_local && proto != M2_ipRouteProto_icmp) return (0); /* If it is an interface route, get the interface address */ if (gateAddr->sa_family == AF_LINK) gateAddr = pRt->rt_ifa->ifa_addr; if (rt_mask (pRt) == NULL) { mask = 0; } else { mask = ((struct sockaddr_in *) rt_mask (pRt))->sin_addr.s_addr; } #ifdef DEBUG inet_ntoa_b (((struct sockaddr_in *)destAddr)->sin_addr, aStr); if (mask) inet_ntoa_b (((struct sockaddr_in *) rt_mask (pRt))->sin_addr, bStr); else bStr[0] = 0; inet_ntoa_b (((struct sockaddr_in *)gateAddr)->sin_addr, cStr); logMsg ("_routeNodeDelete: Deleting following route: dest = %s, nmask = %s," "gate = %s\n", (int)aStr, (int)bStr, (int)cStr, 0, 0, 0); #endif /* DEBUG */ /* Now delete the route */ mRouteEntryDelete (((struct sockaddr_in*)destAddr)->sin_addr.s_addr, ((struct sockaddr_in*)gateAddr)->sin_addr.s_addr, mask, TOS_GET (destAddr), pRt->rt_flags, proto); /* Increment the deletion counter */ ++(*pDeleted); return 0; }
LOCAL int routeNodeDelete ( struct radix_node * pRoute, /* pointer to the node structure */ void * pArg /* pointer to the interface */ ) { struct ifnet * ifp = (struct ifnet *)((int *)pArg)[0]; int type = ((int *)pArg)[1]; int * pDeleted = (int *)((int *)pArg)[2]; struct rtentry * pRt; FAST struct sockaddr * destAddr = NULL; FAST struct sockaddr * gateAddr; char aStr [INET_ADDR_LEN]; #ifdef ROUTER_STACK ROUTE_ENTRY * pHead; ROUTE_ENTRY * pDiffSave; ROUTE_ENTRY * pSameSave; ROUTE_ENTRY * pNext; #endif /* ROUTER_STACK */ pRt = (struct rtentry *)pRoute; destAddr = rt_key(pRt); /* get the destination address */ gateAddr = pRt->rt_gateway; /* get the gateway address */ #ifdef DEBUG inet_ntoa_b (((struct sockaddr_in *)destAddr)->sin_addr, aStr); logMsg ("routeNodeDelete: Called for %s, if=%s%d, proto=%d, type = %s\n", (int)aStr, (int)(pRt->rt_ifp->if_name), pRt->rt_ifp->if_unit, RT_PROTO_GET (destAddr), (int)(type == RT_ARP ? "ARP" : "NON_ARP"), 0); #endif /* DEBUG */ /* Just return if it is an ARP entry and we are not interested in it */ if (type != RT_ARP && ((pRt->rt_flags & RTF_HOST) && (pRt->rt_flags & RTF_LLINFO) && (pRt->rt_flags & RTF_GATEWAY) == 0 && gateAddr && (gateAddr->sa_family == AF_LINK))) return(0); /* Just return if we want an ARP entry, but this is not */ if (type == RT_ARP && !((pRt->rt_flags & RTF_HOST) && (pRt->rt_flags & RTF_LLINFO) && (pRt->rt_flags & RTF_GATEWAY) == 0 && gateAddr && (gateAddr->sa_family == AF_LINK))) return(0); /* * If it is an ARP entry and it passes through the interface, * delete the ARP entry */ if ((pRt->rt_flags & RTF_HOST) && (pRt->rt_flags & RTF_LLINFO) && (pRt->rt_flags & RTF_GATEWAY) == 0 && gateAddr && (gateAddr->sa_family == AF_LINK)) { if(pRt->rt_ifp == ifp) { inet_ntoa_b (((struct sockaddr_in *)destAddr)->sin_addr, aStr); #ifdef DEBUG logMsg ("routeNodeDelete: deleting ARP entry for %s\n", (int)aStr,0,0,0,0,0); #endif /* DEBUG */ _arpCmd (SIOCDARP, &((struct sockaddr_in *)destAddr)->sin_addr, NULL, NULL); /* Increment the deletion counter */ ++(*pDeleted); } return (0); } #ifdef ROUTER_STACK /* * Because of the way the duplicate route list is managed, we need to * delete all duplicate routes, before we delete the primary route. * So walk through all the duplicate routes if any, and delete them * if the interface matches. */ pHead = (ROUTE_ENTRY *)pRoute; pNext = pHead->sameNode.pFrwd; if (pNext == NULL) { pHead = pNext = pHead->diffNode.pFrwd; } while (pHead) { pDiffSave = pHead->diffNode.pFrwd; while (pNext) { /* Save the next pointer in case we delete this node */ pSameSave = pNext->sameNode.pFrwd; /* If this route passes through the interface, delete it */ if (pNext->rtEntry.rt_ifp == ifp) _routeNodeDelete ((struct rtentry *)pNext, pDeleted); pNext = pSameSave; } pHead = pNext = pDiffSave; } #endif /* ROUTER_STACK */ /* Now delete the primary route if it passes through the interface */ if (pRt->rt_ifp == ifp) _routeNodeDelete (pRt, pDeleted); return OK; }
static int ei_epmd_r4_port (struct in_addr *addr, const char *alive, int *dist, unsigned ms) { char buf[EPMDBUF]; char *s = buf; int len = strlen(alive) + 1; int fd; int ntype; int port; int dist_high, dist_low, proto; int res; #if defined(VXWORKS) char ntoabuf[32]; #endif if (len > sizeof(buf) - 3) { erl_errno = ERANGE; return -1; } put16be(s,len); put8(s,EI_EPMD_PORT2_REQ); strcpy(s,alive); /* connect to epmd */ if ((fd = ei_epmd_connect_tmo(addr,ms)) < 0) { return -1; } if ((res = ei_write_fill_t(fd, buf, len+2, ms)) != len+2) { closesocket(fd); erl_errno = (res == -2) ? ETIMEDOUT : EIO; return -1; } #ifdef VXWORKS /* FIXME use union/macro for level. Correct level? */ if (ei_tracelevel > 2) { inet_ntoa_b(*addr,ntoabuf); EI_TRACE_CONN2("ei_epmd_r4_port", "-> PORT2_REQ alive=%s ip=%s",alive,ntoabuf); } #else EI_TRACE_CONN2("ei_epmd_r4_port", "-> PORT2_REQ alive=%s ip=%s",alive,inet_ntoa(*addr)); #endif /* read first two bytes (response type, response) */ if ((res = ei_read_fill_t(fd, buf, 2, ms)) != 2) { EI_TRACE_ERR0("ei_epmd_r4_port","<- CLOSE"); erl_errno = (res == -2) ? ETIMEDOUT : EIO; closesocket(fd); return -2; /* version mismatch */ } s = buf; res = get8(s); if (res != EI_EPMD_PORT2_RESP) { /* response type */ EI_TRACE_ERR1("ei_epmd_r4_port","<- unknown (%d)",res); EI_TRACE_ERR0("ei_epmd_r4_port","-> CLOSE"); closesocket(fd); erl_errno = EIO; return -1; } /* got negative response */ if ((res = get8(s))) { /* got negative response */ EI_TRACE_ERR1("ei_epmd_r4_port","<- PORT2_RESP result=%d (failure)",res); closesocket(fd); erl_errno = EIO; return -1; } EI_TRACE_CONN1("ei_epmd_r4_port","<- PORT2_RESP result=%d (ok)",res); /* expecting remaining 8 bytes */ if ((res = ei_read_fill_t(fd,buf,8,ms)) != 8) { EI_TRACE_ERR0("ei_epmd_r4_port","<- CLOSE"); erl_errno = (res == -2) ? ETIMEDOUT : EIO; closesocket(fd); return -1; } closesocket(fd); s = buf; port = get16be(s); ntype = get8(s); proto = get8(s); dist_high = get16be(s); dist_low = get16be(s); EI_TRACE_CONN5("ei_epmd_r4_port", " port=%d ntype=%d proto=%d dist-high=%d dist-low=%d", port,ntype,proto,dist_high,dist_low); /* right network protocol? */ if (EI_MYPROTO != proto) { erl_errno = EIO; return -1; } /* is there overlap in our distribution versions? */ if ((EI_DIST_HIGH < dist_low) || (EI_DIST_LOW > dist_high)) { erl_errno = EIO; return -1; } /* choose the highest common version */ /* i.e. min(his-max, my-max) */ *dist = (dist_high > EI_DIST_HIGH ? EI_DIST_HIGH : dist_high); /* ignore the remaining fields */ return port; }
LOCAL BOOL routeEntryPrint(struct rtentry *pRoute, void *pRouteType, BOOL ipRouteFlag) { struct sockaddr *dest, *gateway; int type; char str[INET_ADDR_LEN]; unsigned long mask; /* Initialize locals */ dest = NULL; type = *((int *) pRouteType); /* If host routes and only network requested */ if ( (type == RT_SHOW_NET) && (pRoute->rt_flags & RTF_HOST) ) return FALSE; /* Get values */ dest = rt_key(pRoute); gateway = pRoute->rt_gateway; /* If host but not arp requested */ if ( (type & RT_SHOW_HST) && (gateway->sa_family == AF_LINK) && (pRoute->rt_flags & RTF_HOST) ) return FALSE; /* If only host requested */ if ( (type == RT_SHOW_HST) && ((pRoute->rt_flags & RTF_HOST) == 0) ) return FALSE; /* If arp requested and invalid link address */ if ( (type & RT_SHOW_ARP) && ((gateway->sa_family != AF_LINK) || (((struct sockaddr_dl *) gateway)->sdl_alen == 0)) ) return FALSE; /* If net requested and gateway address family is link */ if ( (type & RT_SHOW_NET) && (gateway->sa_family == AF_LINK) ) gateway = pRoute->rt_ifa->ifa_addr; /* If ip route request */ if (ipRouteFlag) { /* If internet address */ if (dest->sa_family == AF_INET) { inet_ntoa_b(((struct sockaddr_in *) dest)->sin_addr, str); printf("%-16s ", str); } /* End if internet address */ /* Else non-internet address */ else { printf("%-16s ", "not AF_INET"); } /* End else non-internet address */ } /* End if ip route request */ /* Else non-ip route request */ else { printf(" "); } /* End else non-ip route request */ /* If both net and host requested */ if ( (type & RT_SHOW_NET) && (type & RT_SHOW_HST) ) { /* If ip route request */ if (ipRouteFlag) { /* If null mask */ if ( rt_mask(pRoute) == NULL) { mask = 0x0; } /* End if null mask */ /* Else non-null mask */ else { mask = ((struct sockaddr_in *) rt_mask(pRoute))->sin_addr.s_addr; mask = ntohl(mask); } /* End else non-null mask */ /* Print mask */ printf("%#-10lx ", mask); } /* End if ip route request */ /* Else non-ip route request */ else { printf(" "); } /* End else non-ip route request */ } /* End if both net and host requested */ /* If link level gateway */ if (gateway->sa_family == AF_LINK) { printf(" "); } /* End if link level gateway */ /* Else non-link gateway */ else { /* If internet address */ if (gateway->sa_family == AF_INET) { inet_ntoa_b(((struct sockaddr_in *) gateway)->sin_addr, str); printf("%-16s ", str); } /* End if internet address */ /* Else non-internet address */ else { printf("%-16s ", "not AF_INET"); } /* End else non-internet address */ } /* End else non-link gateway */ /* Print the rest */ printf("%#-6hx ", pRoute->rt_flags); printf("%-5d ", pRoute->rt_refcnt); printf("%-10ld ", pRoute->rt_use); printf("%s%d\n", pRoute->rt_ifp->if_name, pRoute->rt_ifp->if_unit); return TRUE; }