int simple_pton(const char* addr, void* result){
	if(STRING_IS_IPV6(addr)){
		return ipv6_pton(addr, result);
	}else{
		return ipv4_pton(addr, result);
	}
}
Esempio n. 2
0
File: ip.c Progetto: j3guile/OpenAM
/**
 * Initialize and read an ipv4 presentation, returning in bpits the number of bits
 * 
 * @return AM_FALSE if the presentation cannot be read as an ipv4 address in CIDR notation
 */
static am_bool_t read_ip(const char * p, struct in_addr * n, int * pbits) {
    *pbits = ipv4_pton(p, n);
    if (*pbits == -1) {
        return AM_FALSE;
    }
    return AM_TRUE;
}
int ipv4_addrinit(struct sockaddr* addr, const char* address, int port){
	struct sockaddr_in* addr4 = (struct sockaddr_in*)addr;
	simple_bzero(addr4, sizeof(*addr4));
	addr4->sin_family = AF_INET;
	addr4->sin_port = htons(port);
	if(ipv4_pton(address, &addr4->sin_addr) <= 0){
		return -1;
	}
	return 0;
}