static int bind_rtp(struct mgcp_config *cfg, struct mgcp_rtp_end *rtp_end, int endpno) { if (create_bind(cfg->source_addr, &rtp_end->rtp, rtp_end->local_port) != 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to create RTP port: %s:%d on 0x%x\n", cfg->source_addr, rtp_end->local_port, endpno); goto cleanup0; } if (create_bind(cfg->source_addr, &rtp_end->rtcp, rtp_end->local_port + 1) != 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to create RTCP port: %s:%d on 0x%x\n", cfg->source_addr, rtp_end->local_port + 1, endpno); goto cleanup1; } set_ip_tos(rtp_end->rtp.fd, cfg->endp_dscp); set_ip_tos(rtp_end->rtcp.fd, cfg->endp_dscp); rtp_end->rtp.when = BSC_FD_READ; if (osmo_fd_register(&rtp_end->rtp) != 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to register RTP port %d on 0x%x\n", rtp_end->local_port, endpno); goto cleanup2; } rtp_end->rtcp.when = BSC_FD_READ; if (osmo_fd_register(&rtp_end->rtcp) != 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to register RTCP port %d on 0x%x\n", rtp_end->local_port + 1, endpno); goto cleanup3; } return 0; cleanup3: osmo_fd_unregister(&rtp_end->rtp); cleanup2: close(rtp_end->rtcp.fd); rtp_end->rtcp.fd = -1; cleanup1: close(rtp_end->rtp.fd); rtp_end->rtp.fd = -1; cleanup0: return -1; }
void open_socket_inet(device_dev_t* if_device, options_t *options) { // TODO: not yet ready !!! ip_port_t srv_addr; // address to connect the probe to struct addrinfo* a_res; // address results struct addrinfo a_hint; // address results // parse address input string '<ip>:<port>' srv_addr = parse_ip_port(if_device->device_name); LOGGER_info("INET socket: '%s:%s'", srv_addr.ip, srv_addr.port); // TODO: IPv4 support IPv6 is added later memset( &a_hint, 0, sizeof(a_hint) ); a_hint.ai_family = options->ai_family; //AF_INET; // AF_INET6; //a_hint.ai_socktype = SOCK_STREAM; //SOCK_DGRAM; a_hint.ai_socktype = SOCK_DGRAM; //SOCK_STREAM; a_hint.ai_flags = AI_PASSIVE; // server socket //a_hint.ai_flags |= AI_ADDRCONFIG; //a_hint.ai_flags |= AI_V4MAPPED; a_hint.ai_protocol = IPPROTO_UDP; // udp protocol // get all availabe address for the given ip port //int rv = getaddrinfo(srv_addr.ip, srv_addr.port, &a_hint, &a_res); int rv = getaddrinfo(NULL, srv_addr.port, &a_hint, &a_res); if( 0 != rv ) { perror( "Socket error in getaddrinfo()" ); perror( gai_strerror(rv) ); exit(1); } // print the return addresses print_addrinfo( a_res ); if( NULL != a_res ) { //LOGGER_info( "connect" ); LOGGER_info( "bind" ); int socket = -1; // create a socket for the returned service //if_device->device_handle.socket = create_connect( a_res ); socket = create_bind( a_res ); if(-1 == socket ) { //perror("socket create_connect error"); perror("socket create_bind error"); exit(1); } if_device->device_handle.socket = socket; if_device->dh.fd = socket; if_device->dispatch = socket_dispatch_inet; // send 'hello' TODO: for test only //write( if_device->device_handle.socket, "HELLO!", 6 ); //write( if_device->device_handle.socket, "", 1 ); // TODO: some rework is still needed // register read handling to ev_handler LOGGER_debug("Register io handling for interface: %s", if_device->device_name); setNONBlocking(if_device); int fd = get_file_desc(if_device); LOGGER_debug("File Descriptor: %d", fd); /* storing a reference of packet device to be passed via watcher on a packet event so we know which device to read the packet from */ // TODO: implement an own packet watcher callback LOGGER_info("register event io: read inet socket interface (%s)", if_device->device_name); ev_watcher* watcher = event_register_io_r(EV_DEFAULT_ packet_watcher_cb, fd); watcher->data = (device_dev_t *) if_device; } // TODO: for UDP send initial message ? return; }