in_addr_t anubis_random_ip_address(const char *expression) { //get param anubis_srand(); char *buffer = anubis_parse_param("random_ip_address", expression); if(!buffer) return 0; in_addr_t addr; if(strlen(buffer) == 0) { do { addr = (in_addr_t)random(); }//end do while(addr == INADDR_ANY || addr == INADDR_BROADCAST || IN_MULTICAST(addr) || IN_PRIVATE(addr) || IN_EXPERIMENTAL(addr) || IN_LOOPBACK(addr) || IN_ZERONET(addr) || IN_LOCAL_GROUP(addr)); return addr; }//end if else { anubis_err("random_ip_address(): \"%s\" unknown parameter\n", buffer); return 0; }//end if }//end anubis_random_ip_address
/* Check if valid address */ static int valid_addr(struct in_addr *ina) { in_addr_t addr; addr = ntohl(ina->s_addr); if (IN_ZERONET(addr) || IN_LOOPBACK(addr) || IN_LINKLOCAL(addr)) return 0; return 1; }
static int sa_getlocal(struct sockaddr_in *u, struct sockaddr_in *k) { if (sa_get(u, k)) return -1; if (ntohs(k->sin_port) < 1024 && !super()) { udata.u_error = EACCES; return -1; } if (k->sin_addr.s_addr != INADDR_ANY && !IN_LOOPBACK(k->sin_addr.s_addr) && k->sin_addr.s_addr != our_address) { udata.u_error = EADDRNOTAVAIL; return -1; } return 0; }
static uint32_t RIP_is_valid_rte( RIP_ENTRY_PTR rte ) { /* Body */ uint32_t metric = mqx_ntohl(rte->METRIC); _ip_address netaddr = mqx_ntohl(rte->NETADDR); if (mqx_ntohs(rte->FAMILY) != RIP_AF_INET) return 0; if (metric > RIP_MAX_METRIC || metric < RIP_MIN_METRIC) return 0; if (IN_MULTICAST(netaddr) || IN_EXPERIMENTAL(netaddr)) return 0; if (IN_LOOPBACK(netaddr)) return 0; { _ip_address nexthop = mqx_ntohl(rte->NEXTHOP); if (nexthop!= 0) { if (IP_is_local(NULL, nexthop)) { return 0; } } } return 1; } /* Endbody */
struct rds_transport *rds_trans_get_preferred(__be32 addr) { struct rds_transport *ret = NULL; struct rds_transport *trans; unsigned int i; if (IN_LOOPBACK(ntohl(addr))) return &rds_loop_transport; down_read(&rds_trans_sem); for (i = 0; i < RDS_TRANS_COUNT; i++) { trans = transports[i]; if (trans && (trans->laddr_check(addr) == 0) && (!trans->t_owner || try_module_get(trans->t_owner))) { ret = trans; break; } } up_read(&rds_trans_sem); return ret; }
/* Get the IP address from interface */ static RC_TYPE do_ip_check_interface(DYN_DNS_CLIENT *p_self) { struct ifreq ifr; in_addr_t new_ip; char *new_ip_str; int i; if (p_self == NULL) { return RC_INVALID_POINTER; } if (p_self->check_interface) { logit(LOG_INFO, MODULE_TAG "Checking for IP# change, querying interface %s", p_self->check_interface); int sd = socket(PF_INET, SOCK_DGRAM, 0); if (sd < 0) { int code = os_get_socket_error(); logit(LOG_WARNING, MODULE_TAG "Failed opening network socket: %s", strerror(code)); return RC_IP_OS_SOCKET_INIT_FAILED; } memset(&ifr, 0, sizeof(struct ifreq)); ifr.ifr_addr.sa_family = AF_INET; snprintf(ifr.ifr_name, IFNAMSIZ, p_self->check_interface); if (ioctl(sd, SIOCGIFADDR, &ifr) != -1) { new_ip = ntohl(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr); new_ip_str = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr); } else { int code = os_get_socket_error(); logit(LOG_ERR, MODULE_TAG "Failed reading IP address of interface %s: %s", p_self->check_interface, strerror(code)); return RC_ERROR; } close(sd); } else { return RC_ERROR; } if (IN_ZERONET(new_ip) || IN_LOOPBACK(new_ip) || IN_LINKLOCAL(new_ip) || IN_MULTICAST(new_ip) || IN_EXPERIMENTAL(new_ip)) { logit(LOG_WARNING, MODULE_TAG "Interface %s has invalid IP# %s", p_self->check_interface, new_ip_str); return RC_ERROR; } int anychange = 0; for (i = 0; i < p_self->info_count; i++) { DYNDNS_INFO_TYPE *info = &p_self->info[i]; info->my_ip_has_changed = strcmp(info->my_ip_address.name, new_ip_str) != 0; if (info->my_ip_has_changed) { anychange++; strcpy(info->my_ip_address.name, new_ip_str); } } if (!anychange) { logit(LOG_INFO, MODULE_TAG "No IP# change detected, still at %s", new_ip_str); } return RC_OK; }