int ooBindPort (OOH323PortType type, OOSOCKET socket, char *ip) { int initialPort, bindPort, ret; OOIPADDR ipAddrs; ast_mutex_lock(&bindPortLock); initialPort = ooGetNextPort (type); bindPort = initialPort; ret=ast_parse_arg(ip, PARSE_ADDR, &ipAddrs); while(1) { if((ret=ooSocketBind(socket, ipAddrs, bindPort))==0) { ast_mutex_unlock(&bindPortLock); return bindPort; } else { bindPort = ooGetNextPort (type); if (bindPort == initialPort) { ast_mutex_unlock(&bindPortLock); return OO_FAILED; } } } }
int ooBindOSAllocatedPort(OOSOCKET socket, char *ip) { OOIPADDR ipAddrs; int size, ret; struct sockaddr_in name; size = sizeof(struct sockaddr_in); ret= ooSocketStrToAddr (ip, &ipAddrs); if((ret=ooSocketBind(socket, ipAddrs, 0))==ASN_OK) { ret = ooSocketGetSockName(socket, &name, &size); if(ret == ASN_OK) { return name.sin_port; } } return OO_FAILED; }
int ooBindPort (OOH323PortType type, OOSOCKET socket, char *ip) { int initialPort, bindPort, ret; OOIPADDR ipAddrs; initialPort = ooGetNextPort (type); bindPort = initialPort; ret= ooSocketStrToAddr (ip, &ipAddrs); while(1) { if((ret=ooSocketBind(socket, ipAddrs, bindPort))==0) { return bindPort; } else { bindPort = ooGetNextPort (type); if (bindPort == initialPort) return OO_FAILED; } } }