static APR_INLINE apt_bool_t mpf_rtp_data_send(mpf_rtp_stream_t *rtp_stream, rtp_transmitter_t *transmitter, const mpf_frame_t *frame) { apt_bool_t status = TRUE; memcpy( transmitter->packet_data + transmitter->packet_size, frame->codec_frame.buffer, frame->codec_frame.size); transmitter->packet_size += frame->codec_frame.size; if(++transmitter->current_frames == transmitter->packet_frames) { rtp_header_t *header = (rtp_header_t*)transmitter->packet_data; header->sequence = htons(++transmitter->last_seq_num); RTP_TRACE("> RTP time=%6u ssrc=%8x pt=%3u %cts=%9u seq=%5hu\n", (apr_uint32_t)apr_time_usec(apr_time_now()), transmitter->sr_stat.ssrc, header->type, (header->marker == 1) ? '*' : ' ', header->timestamp, transmitter->last_seq_num); header->timestamp = htonl(header->timestamp); if(apr_socket_sendto( rtp_stream->rtp_socket, rtp_stream->rtp_r_sockaddr, 0, transmitter->packet_data, &transmitter->packet_size) == APR_SUCCESS) { transmitter->sr_stat.sent_packets++; transmitter->sr_stat.sent_octets += (apr_uint32_t)transmitter->packet_size - sizeof(rtp_header_t); } else { status = FALSE; } transmitter->current_frames = 0; } return status; }
static apt_bool_t mrcp_client_control_message_signal( connection_task_msg_data_type_e type, mrcp_connection_agent_t *agent, mrcp_control_channel_t *channel, mrcp_control_descriptor_t *descriptor, mrcp_message_t *message) { apr_size_t size; connection_task_msg_data_t task_msg_data; if(!agent->control_sock) { return FALSE; } size = sizeof(connection_task_msg_data_t); task_msg_data.type = type; task_msg_data.agent = agent; task_msg_data.channel = channel; task_msg_data.descriptor = descriptor; task_msg_data.message = message; if(apr_socket_sendto(agent->control_sock,agent->control_sockaddr,0,(const char*)&task_msg_data,&size) != APR_SUCCESS) { apt_log(APT_PRIO_WARNING,"Failed to Signal Control Message"); return FALSE; } return TRUE; }
SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len) { if (!where || !buf || !len || !*len) { return SWITCH_STATUS_GENERR; } return apr_socket_sendto(sock, where, flags, buf, len); }
static void tell_workers_to_exit(void) { apr_size_t len; int i = 0; for (i = 0 ; i < ap_max_child_assigned; i++){ len = 4; if (apr_socket_sendto(udp_sock, udp_sa, 0, "die!", &len) != APR_SUCCESS) break; } }
static void send_msg(apr_socket_t **sockarray, apr_sockaddr_t **sas, int which, abts_case *tc) { apr_size_t len = 5; apr_status_t rv; ABTS_PTR_NOTNULL(tc, sockarray[which]); rv = apr_socket_sendto(sockarray[which], sas[which], 0, "hello", &len); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_SIZE_EQUAL(tc, strlen("hello"), len); }
static void send_msg(apr_socket_t **sockarray, apr_sockaddr_t **sas, int which, CuTest *tc) { apr_size_t len = 5; apr_status_t rv; CuAssertPtrNotNull(tc, sockarray[which]); rv = apr_socket_sendto(sockarray[which], sas[which], 0, "hello", &len); CuAssertIntEquals(tc, APR_SUCCESS, rv); CuAssertIntEquals(tc, strlen("hello"), len); }
/* Send compound RTCP packet (SR/RR + SDES + BYE) */ static apt_bool_t mpf_rtcp_bye_send(mpf_rtp_stream_t *rtp_stream, apt_str_t *reason) { char buffer[MAX_RTCP_PACKET_SIZE]; apr_size_t length = 0; rtcp_packet_t *rtcp_packet; if(!rtp_stream->rtcp_socket || !rtp_stream->rtcp_l_sockaddr || !rtp_stream->rtcp_r_sockaddr) { /* session is not initialized */ return FALSE; } if(rtp_stream->base->direction != STREAM_DIRECTION_NONE) { /* update periodic (prior) history */ rtp_periodic_history_update(&rtp_stream->receiver); } rtcp_packet = (rtcp_packet_t*) (buffer + length); length += rtcp_report_generate(rtp_stream,rtcp_packet,sizeof(buffer)-length); rtcp_packet = (rtcp_packet_t*) (buffer + length); length += rtcp_sdes_generate(rtp_stream,rtcp_packet,sizeof(buffer)-length); rtcp_packet = (rtcp_packet_t*) (buffer + length); length += rtcp_bye_generate(rtp_stream,rtcp_packet,sizeof(buffer)-length,reason); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Send Compound RTCP Packet [BYE] [%"APR_SIZE_T_FMT" bytes] %s:%hu -> %s:%hu", length, rtp_stream->rtcp_l_sockaddr->hostname, rtp_stream->rtcp_l_sockaddr->port, rtp_stream->rtcp_r_sockaddr->hostname, rtp_stream->rtcp_r_sockaddr->port); if(apr_socket_sendto( rtp_stream->rtcp_socket, rtp_stream->rtcp_r_sockaddr, 0, buffer, &length) != APR_SUCCESS) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Send Compound RTCP Packet [BYE] [%"APR_SIZE_T_FMT" bytes] %s:%hu -> %s:%hu", length, rtp_stream->rtcp_l_sockaddr->hostname, rtp_stream->rtcp_l_sockaddr->port, rtp_stream->rtcp_r_sockaddr->hostname, rtp_stream->rtcp_r_sockaddr->port); return FALSE; } return TRUE; }
static apt_bool_t mrcp_client_agent_task_terminate(apt_task_t *task) { apt_bool_t status = FALSE; mrcp_connection_agent_t *agent = apt_task_object_get(task); if(agent->control_sock) { connection_task_msg_data_t task_msg_data; apr_size_t size = sizeof(connection_task_msg_data_t); task_msg_data.type = CONNECTION_TASK_MSG_TERMINATE; if(apr_socket_sendto(agent->control_sock,agent->control_sockaddr,0,(const char*)&task_msg_data,&size) == APR_SUCCESS) { status = TRUE; } else { apt_log(APT_PRIO_WARNING,"Failed to Send Control Message"); } } return status; }
term_t bif_sendto4(term_t Sock, term_t RemIP, term_t RemPort, term_t Bin, process_t *ctx) { apr_status_t rs; port_t *port; apr_socket_t *sock; const char *host; int udp_port; apr_sockaddr_t *sa; apr_pool_t *p; if (!is_port(Sock)) return A_BADARG; if (!is_binary(RemIP) || !is_int(RemPort)) return A_BADARG; if (!is_binary(Bin)) return A_BADARG; port = port_lookup(prp_serial(Sock)); if (port == 0) return A_CLOSED; if (!port->is_socket(port)) return A_BADARG; sock = port->get_socket(port); host = (const char *)bin_data(RemIP); udp_port = (apr_port_t)int_value(RemPort); apr_pool_create(&p, 0); rs = apr_sockaddr_info_get(&sa, host, APR_INET, udp_port, 0, p); if (rs == 0) { apr_size_t len = (apr_size_t)int_value(bin_size(Bin)); rs = apr_socket_sendto(sock, sa, 0, (const char *)bin_data(Bin), &len); } if (rs != 0) { apr_pool_destroy(p); return decipher_status(rs); } result(A_OK); return AI_OK; }
static APR_INLINE apt_bool_t mpf_rtp_event_send(mpf_rtp_stream_t *rtp_stream, rtp_transmitter_t *transmitter, const mpf_frame_t *frame) { char packet_data[20]; apr_size_t packet_size = sizeof(rtp_header_t) + sizeof(mpf_named_event_frame_t); rtp_header_t *header = (rtp_header_t*) packet_data; mpf_named_event_frame_t *named_event = (mpf_named_event_frame_t*)(header+1); rtp_header_prepare( transmitter, header, rtp_stream->base->tx_event_descriptor->payload_type, (frame->marker == MPF_MARKER_START_OF_EVENT) ? 1 : 0, transmitter->timestamp_base); *named_event = frame->event_frame; named_event->edge = (frame->marker == MPF_MARKER_END_OF_EVENT) ? 1 : 0; header->sequence = htons(++transmitter->last_seq_num); RTP_TRACE("> RTP time=%6lu ssrc=%8lx pt=%3u %cts=%9lu seq=%5u event=%2u dur=%3u %c\n", (apr_uint32_t)apr_time_usec(apr_time_now()), transmitter->sr_stat.ssrc, header->type, (header->marker == 1) ? '*' : ' ', header->timestamp, transmitter->last_seq_num, named_event->event_id, named_event->duration, (named_event->edge == 1) ? '*' : ' '); header->timestamp = htonl(header->timestamp); named_event->duration = htons((apr_uint16_t)named_event->duration); if(apr_socket_sendto( rtp_stream->rtp_socket, rtp_stream->rtp_r_sockaddr, 0, packet_data, &packet_size) != APR_SUCCESS) { return FALSE; } transmitter->sr_stat.sent_packets++; transmitter->sr_stat.sent_octets += sizeof(mpf_named_event_frame_t); return TRUE; }
static void sendto_receivefrom_helper(abts_case *tc, const char *addr, int family) { apr_status_t rv; apr_socket_t *sock = NULL; apr_socket_t *sock2 = NULL; char sendbuf[STRLEN] = "APR_INET, SOCK_DGRAM"; char recvbuf[80]; char *ip_addr; apr_port_t fromport; apr_sockaddr_t *from; apr_sockaddr_t *to; apr_size_t len = 30; rv = apr_socket_create(&sock, family, SOCK_DGRAM, 0, p); #if APR_HAVE_IPV6 if ((family == APR_INET6) && APR_STATUS_IS_EAFNOSUPPORT(rv)) { ABTS_NOT_IMPL(tc, "IPv6 not enabled"); return; } #endif ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); if (rv != APR_SUCCESS) return; rv = apr_socket_create(&sock2, family, SOCK_DGRAM, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); if (rv != APR_SUCCESS) return; rv = apr_sockaddr_info_get(&to, addr, family, 7772, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_sockaddr_info_get(&from, addr, family, 7771, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_opt_set(sock, APR_SO_REUSEADDR, 1); APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket", rv); rv = apr_socket_opt_set(sock2, APR_SO_REUSEADDR, 1); APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket2", rv); rv = apr_socket_bind(sock, to); APR_ASSERT_SUCCESS(tc, "Could not bind socket", rv); if (rv != APR_SUCCESS) return; rv = apr_socket_bind(sock2, from); APR_ASSERT_SUCCESS(tc, "Could not bind second socket", rv); if (rv != APR_SUCCESS) return; len = STRLEN; rv = apr_socket_sendto(sock2, to, 0, sendbuf, &len); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_SIZE_EQUAL(tc, STRLEN, len); /* fill the "from" sockaddr with a random address from another * family to ensure that recvfrom sets it up properly. */ #if APR_HAVE_IPV6 if (family == APR_INET) rv = apr_sockaddr_info_get(&from, "3ffE:816e:abcd:1234::1", APR_INET6, 4242, 0, p); else #endif rv = apr_sockaddr_info_get(&from, "127.1.2.3", APR_INET, 4242, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); len = 80; rv = apr_socket_recvfrom(from, sock, 0, recvbuf, &len); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_SIZE_EQUAL(tc, STRLEN, len); ABTS_STR_EQUAL(tc, "APR_INET, SOCK_DGRAM", recvbuf); apr_sockaddr_ip_get(&ip_addr, from); fromport = from->port; ABTS_STR_EQUAL(tc, addr, ip_addr); ABTS_INT_EQUAL(tc, 7771, fromport); apr_socket_close(sock); apr_socket_close(sock2); }
static void sendto_receivefrom(abts_case *tc, void *data) { apr_status_t rv; apr_socket_t *sock = NULL; apr_socket_t *sock2 = NULL; char sendbuf[STRLEN] = "APR_INET, SOCK_DGRAM"; char recvbuf[80]; char *ip_addr; apr_port_t fromport; apr_sockaddr_t *from; apr_sockaddr_t *to; apr_size_t len = 30; int family; const char *addr; #if APR_HAVE_IPV6 family = APR_INET6; addr = "::1"; rv = apr_socket_create(&sock, family, SOCK_DGRAM, 0, p); if (V6_NOT_ENABLED(rv)) { #endif family = APR_INET; addr = "127.0.0.1"; rv = apr_socket_create(&sock, family, SOCK_DGRAM, 0, p); #if APR_HAVE_IPV6 } #endif ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_create(&sock2, family, SOCK_DGRAM, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_sockaddr_info_get(&to, addr, APR_UNSPEC, 7772, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_sockaddr_info_get(&from, addr, APR_UNSPEC, 7771, 0, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_opt_set(sock, APR_SO_REUSEADDR, 1); APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket", rv); rv = apr_socket_opt_set(sock2, APR_SO_REUSEADDR, 1); APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket2", rv); rv = apr_socket_bind(sock, to); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_socket_bind(sock2, from); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); len = STRLEN; rv = apr_socket_sendto(sock2, to, 0, sendbuf, &len); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, STRLEN, len); len = 80; rv = apr_socket_recvfrom(from, sock, 0, recvbuf, &len); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); ABTS_INT_EQUAL(tc, STRLEN, len); ABTS_STR_EQUAL(tc, "APR_INET, SOCK_DGRAM", recvbuf); apr_sockaddr_ip_get(&ip_addr, from); fromport = from->port; ABTS_STR_EQUAL(tc, addr, ip_addr); ABTS_INT_EQUAL(tc, 7771, fromport); apr_socket_close(sock); apr_socket_close(sock2); }
apr_status_t ma_advertise_server(server_rec *server, int type) { char buf[MA_BSIZE]; char dat[APR_RFC822_DATE_LEN]; char add[40]; unsigned char msig[APR_MD5_DIGESTSIZE]; unsigned char ssig[APR_MD5_DIGESTSIZE * 2 + 1]; const char *asl; char *p = buf; int i, c = 0; apr_size_t l = MA_BSIZE - 8; apr_size_t n = 0; apr_md5_ctx_t md; mod_advertise_config *mconf = ap_get_module_config(server->module_config, &advertise_module); ma_sequence++; if (ma_sequence < 1) ma_sequence = 1; sprintf(buf, "%" APR_INT64_T_FMT, ma_sequence); ap_recent_rfc822_date(dat, apr_time_now()); asl = ap_get_status_line(ma_advertise_stat); /* Create MD5 digest * salt + date + sequence + srvid */ apr_md5_init(&md); apr_md5_update(&md, magd->ssalt, APR_MD5_DIGESTSIZE); apr_md5_update(&md, dat, strlen(dat)); apr_md5_update(&md, buf, strlen(buf)); apr_md5_update(&md, magd->srvid + 1, strlen(magd->srvid) - 1); apr_md5_final(msig, &md); /* Convert MD5 digest to hex string */ for (i = 0; i < APR_MD5_DIGESTSIZE; i++) { ssig[c++] = hex[msig[i] >> 4]; ssig[c++] = hex[msig[i] & 0x0F]; } ssig[c] = '\0'; n = apr_snprintf(p, l, MA_ADVERTISE_SERVER_FMT, asl, dat, ma_sequence, ssig, magd->srvid + 1); if (type == MA_ADVERTISE_SERVER) { char *ma_advertise_srvs = mconf->ma_advertise_srvs; if (strchr(ma_advertise_srvs, ':') != NULL) { apr_snprintf(add, 40, "[%s]", mconf->ma_advertise_srvs); ma_advertise_srvs = add; } l -= n; n += apr_snprintf(p + n, l, "X-Manager-Address: %s:%u" CRLF "X-Manager-Url: %s" CRLF "X-Manager-Protocol: %s" CRLF "X-Manager-Host: %s" CRLF, ma_advertise_srvs, mconf->ma_advertise_srvp, mconf->ma_advertise_srvh, mconf->ma_advertise_srvm, server->server_hostname); } strcat(p, CRLF); n += 2; return apr_socket_sendto(ma_mgroup_socket, ma_mgroup_sa, 0, buf, &n); }
/* deprecated */ apr_status_t apr_sendto(apr_socket_t *sock, apr_sockaddr_t *where, apr_int32_t flags, const char *buf, apr_size_t *len) { return apr_socket_sendto(sock, where, flags, buf, len); }