void start_curl() { state = kDownloading; curl = curl_easy_init(); //assert(direct_ip.size()); std::string actual_url = redirect_url.size() ? redirect_url:url; char buf[1024]; sprintf(buf,"%s://%s%s%s", extract_proto(actual_url).c_str(), direct_ip.c_str(), extract_port(actual_url).c_str(), extract_path(actual_url).c_str()); curl_easy_setopt(curl, CURLOPT_URL, buf); sprintf(buf,"Host: %s%s",extract_host(actual_url).c_str(),extract_port(actual_url).c_str()); headers = curl_slist_append(headers,buf); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Request::GotData); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)this); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-airplay-agent/1.0"); curl_easy_setopt(curl,CURLOPT_CONNECTTIMEOUT, 15); curl_easy_setopt(curl,CURLOPT_TIMEOUT, 30); curl_easy_setopt(curl,CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION, 0); curl_easy_setopt(curl,CURLOPT_HEADERFUNCTION, Request::GotHeaderStatic); curl_easy_setopt(curl,CURLOPT_HEADERDATA, this); curl_easy_setopt(curl,CURLOPT_PROGRESSFUNCTION, Request::GotProgressStatic); curl_easy_setopt(curl,CURLOPT_PROGRESSDATA, (void *)this); //curl_easy_setopt(curl,CURLOPT_VERBOSE,1); if( curlsh ) curl_easy_setopt(curl,CURLOPT_SHARE,curlsh); if( curlm ) curl_multi_add_handle(curlm, curl); }
int natt_check_udp_encap(struct sockaddr *remote, struct sockaddr *local) { uint16_t port; uint16_t port_p; port_p = extract_port(remote); if (port_p == 0) { return -1; } port = extract_port(local); if (port == 0) { return -1; } if (port == IKEV2_UDP_PORT_NATT || port_p == IKEV2_UDP_PORT_NATT) { return TRUE; } return FALSE; }
/** =========================================================================== */ static void extract_host_port(osm_port_t *p_port, uint64_t *p_pkey_base_offset, uint64_t *p_pkey_offset, uint64_t *p_port_offset, uint64_t *p_link_offset, struct ssa_db_extract *p_ssa_db) { const osm_pkey_tbl_t *p_pkey_tbl; const ib_pkey_table_t *block; osm_physp_t *p_physp = p_port->p_physp; ib_net16_t pkey; uint16_t block_index, pkey_idx; p_pkey_tbl = osm_physp_get_pkey_tbl(p_physp); for (block_index = 0; block_index < p_pkey_tbl->used_blocks; block_index++) { block = osm_pkey_tbl_block_get(p_pkey_tbl, block_index); if (!block) continue; for (pkey_idx = 0; pkey_idx < IB_NUM_PKEY_ELEMENTS_IN_BLOCK; pkey_idx++) { pkey = block->pkey_entry[pkey_idx]; if (ib_pkey_is_invalid(pkey)) continue; p_ssa_db->p_pkey_tbl[*p_pkey_base_offset + *p_pkey_offset] = pkey; *p_pkey_offset = *p_pkey_offset + 1; } } if (*p_pkey_offset >= SSA_EXTRACT_PKEYS_MAX) { ssa_log_err(SSA_LOG_DEFAULT, "ERROR - truncating number of pkeys " "from %d to %d (maximum) for LID %u\n", *p_pkey_offset, SSA_EXTRACT_PKEYS_MAX - 1, ntohs(osm_physp_get_base_lid(p_physp))); *p_pkey_offset = SSA_EXTRACT_PKEYS_MAX - 1; } extract_port(p_physp, NULL, htonll(*p_pkey_base_offset * sizeof(pkey)), htons(*p_pkey_offset * sizeof(pkey)), p_port_offset, p_ssa_db); if (!osm_physp_get_remote(p_physp)) return; extract_link(p_physp, NULL, p_link_offset, p_ssa_db); }
int extract_host_port(char *str, char **host_ptr, unsigned char *ip, short *port_ptr) { char *h,*p; h=str; p=strchr(str,':'); if (p == NULL) { BIO_printf(bio_err,"no port defined\n"); return(0); } *(p++)='\0'; if ((ip != NULL) && !host_ip(str,ip)) goto err; if (host_ptr != NULL) *host_ptr=h; if (!extract_port(p,port_ptr)) goto err; return(1); err: return(0); }
/** * Probes and initializes. */ static int Open (vlc_object_t *obj) { demux_t *demux = (demux_t *)obj; int tp; /* transport protocol */ if (!strcmp (demux->psz_access, "dccp")) tp = IPPROTO_DCCP; else if (!strcmp (demux->psz_access, "rtptcp")) tp = IPPROTO_TCP; else if (!strcmp (demux->psz_access, "rtp")) tp = IPPROTO_UDP; else if (!strcmp (demux->psz_access, "udplite")) tp = IPPROTO_UDPLITE; else return VLC_EGENERIC; char *tmp = strdup (demux->psz_location); if (tmp == NULL) return VLC_ENOMEM; char *shost; char *dhost = strchr (tmp, '@'); if (dhost != NULL) { *(dhost++) = '\0'; shost = tmp; } else { dhost = tmp; shost = NULL; } /* Parses the port numbers */ int sport = 0, dport = 0; if (shost != NULL) sport = extract_port (&shost); if (dhost != NULL) dport = extract_port (&dhost); if (dport == 0) dport = 5004; /* avt-profile-1 port */ int rtcp_dport = var_CreateGetInteger (obj, "rtcp-port"); /* Try to connect */ int fd = -1, rtcp_fd = -1; switch (tp) { case IPPROTO_UDP: case IPPROTO_UDPLITE: fd = net_OpenDgram (obj, dhost, dport, shost, sport, tp); if (fd == -1) break; if (rtcp_dport > 0) /* XXX: source port is unknown */ rtcp_fd = net_OpenDgram (obj, dhost, rtcp_dport, shost, 0, tp); break; case IPPROTO_DCCP: #ifndef SOCK_DCCP /* provisional API (FIXME) */ # ifdef __linux__ # define SOCK_DCCP 6 # endif #endif #ifdef SOCK_DCCP var_Create (obj, "dccp-service", VLC_VAR_STRING); var_SetString (obj, "dccp-service", "RTPV"); /* FIXME: RTPA? */ fd = net_Connect (obj, dhost, dport, SOCK_DCCP, tp); #else msg_Err (obj, "DCCP support not included"); #endif break; case IPPROTO_TCP: fd = net_Connect (obj, dhost, dport, SOCK_STREAM, tp); break; } free (tmp); if (fd == -1) return VLC_EGENERIC; net_SetCSCov (fd, -1, 12); /* Initializes demux */ demux_sys_t *p_sys = malloc (sizeof (*p_sys)); if (p_sys == NULL) { net_Close (fd); if (rtcp_fd != -1) net_Close (rtcp_fd); return VLC_EGENERIC; } p_sys->chained_demux = NULL; #ifdef HAVE_SRTP p_sys->srtp = NULL; #endif p_sys->fd = fd; p_sys->rtcp_fd = rtcp_fd; p_sys->max_src = var_CreateGetInteger (obj, "rtp-max-src"); p_sys->timeout = var_CreateGetInteger (obj, "rtp-timeout") * CLOCK_FREQ; p_sys->max_dropout = var_CreateGetInteger (obj, "rtp-max-dropout"); p_sys->max_misorder = var_CreateGetInteger (obj, "rtp-max-misorder"); p_sys->thread_ready = false; p_sys->autodetect = true; demux->pf_demux = NULL; demux->pf_control = Control; demux->p_sys = p_sys; p_sys->session = rtp_session_create (demux); if (p_sys->session == NULL) goto error; #ifdef HAVE_SRTP char *key = var_CreateGetNonEmptyString (demux, "srtp-key"); if (key) { vlc_gcrypt_init (); p_sys->srtp = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10, SRTP_PRF_AES_CM, SRTP_RCC_MODE1); if (p_sys->srtp == NULL) { free (key); goto error; } char *salt = var_CreateGetNonEmptyString (demux, "srtp-salt"); int val = srtp_setkeystring (p_sys->srtp, key, salt ? salt : ""); free (salt); free (key); if (val) { msg_Err (obj, "bad SRTP key/salt combination (%s)", vlc_strerror_c(val)); goto error; } } #endif if (vlc_clone (&p_sys->thread, (tp != IPPROTO_TCP) ? rtp_dgram_thread : rtp_stream_thread, demux, VLC_THREAD_PRIORITY_INPUT)) goto error; p_sys->thread_ready = true; return VLC_SUCCESS; error: Close (obj); return VLC_EGENERIC; }
/** =========================================================================== */ static void extract_switch_port(osm_port_t *p_port, uint64_t *p_pkey_base_offset, uint64_t *p_pkey_offset, uint64_t *p_port_offset, uint64_t *p_link_offset, struct ssa_db_extract *p_ssa_db) { osm_node_t *p_node = p_port->p_physp->p_node; const osm_pkey_tbl_t *p_pkey_tbl; const ib_pkey_table_t *block; osm_physp_t *p_physp; uint32_t i; ib_net16_t pkey; uint16_t lid_ho, block_index, pkey_idx; for (i = 0; i < p_node->physp_tbl_size; i++) { p_physp = osm_node_get_physp_ptr(p_node, i); if (!p_physp) continue; /* TODO: add filtering for down ports */ if (i == 0) { lid_ho = ntohs(osm_physp_get_base_lid(p_physp)); p_pkey_tbl = osm_physp_get_pkey_tbl(p_physp); for (block_index = 0; block_index < p_pkey_tbl->used_blocks; block_index++) { block = osm_pkey_tbl_block_get(p_pkey_tbl, block_index); if (!block) continue; for (pkey_idx = 0; pkey_idx < IB_NUM_PKEY_ELEMENTS_IN_BLOCK; pkey_idx++) { pkey = block->pkey_entry[pkey_idx]; if (ib_pkey_is_invalid(pkey)) continue; p_ssa_db->p_pkey_tbl[*p_pkey_base_offset + *p_pkey_offset] = pkey; *p_pkey_offset = *p_pkey_offset + 1; } } if (*p_pkey_offset >= SSA_EXTRACT_PKEYS_MAX) { ssa_log_err(SSA_LOG_DEFAULT, "ERROR - truncating number of pkeys " "from %d to %d (maximum) for LID %u\n", *p_pkey_offset, SSA_EXTRACT_PKEYS_MAX - 1, lid_ho); *p_pkey_offset = SSA_EXTRACT_PKEYS_MAX - 1; } extract_port(p_physp, &lid_ho, htonll(*p_pkey_base_offset * sizeof(pkey)), htons(*p_pkey_offset * sizeof(pkey)), p_port_offset, p_ssa_db); } else { extract_port(p_physp, &lid_ho, 0, 0, p_port_offset, p_ssa_db); } if (!osm_physp_get_remote(p_physp)) continue; extract_link(p_physp, &lid_ho, p_link_offset, p_ssa_db); } }