/* * readport() * Loop that polls on the network file descriptor */ int SoundIP::readstream(uint8_t *buffer) { struct pollfd pfd; int n, plen, rv; struct sockaddr_storage z; socklen_t len = sizeof(z); plen = 4096; if (stream < 0) return 0; if (portmode_udp) { rv = recvfrom(stream, buffer, plen, MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)&z, &len); if (rv < 0) return 0; //rv = connect(stream, (struct sockaddr *)&z, len); //udp_connected = true; return ( read(stream, buffer, plen) ); } /* Setup Network FD */ pfd.fd = stream; pfd.events = POLLIN; n = poll(&pfd, 1, -1); if (n <= 0) { closestream(); return n; } if (pfd.revents & POLLIN) { n = read(stream, buffer, plen); if (n == 0) { closestream(); } } else n = 0; return n; }
/// /// .wav を読み込む void Wav::load( const FilePath& filepath ) { // ファイルを開いてサイズを取得 openstream(filepath); // サイズ分のメモリを確保 data_ = (uint8_t*)T3_SYS_ALLOC(size_); datastrage_allocated_ = true; // 読み込み readstream(data_, size_); // ファイルを閉じる closestream(); }
int pread_DPMI (struct timeval *ptime, int *plen, int *ptlen, void **pphys, int *pphystype, struct ip **ppip, void **pplast) { cap_head *caphead; int rpStatus; char *data; struct ether_header *ether; // we use ``while'' rather than ``if'' since we may discard non-IP packets while ((rpStatus = read_post (&dpmi.myStream, &data, dpmi.myFilter)) != 0) { caphead = (cap_head *) data; ptime->tv_usec = caphead->ts.tv_psec / 1000 / 1000; ptime->tv_sec = caphead->ts.tv_sec; ether = (struct ether_header *) (data + sizeof (cap_head)); *plen = caphead->len; /* Lenght of the packet on the wire */ *ptlen = caphead->caplen; /* Portion of the Lenght of captured packet present in this sample */ *pphys = ether; *pphystype = PHYS_ETHER; *ppip = (struct ip *) (data + sizeof (cap_head) + sizeof (struct ethhdr)); *pplast = (char *) data + *ptlen + sizeof (cap_head); /* if it's not IP, then skip it */ if ((ntohs (ether->ether_type) != ETHERTYPE_IP) && (ntohs (ether->ether_type) != ETHERTYPE_IPV6)) { if (debug > 2) fprintf (fp_stderr, "pread_tcpdump: not an IP packet\n"); continue; } // this is used depending on internal_wired value // char nic[8]; // Identifies the CI where the frame was caught // char mampid[8]; // Identifies the MP where the frame was caught, if (dpmi.first || first) { // unless, otherwise specified, the first frame // is assumed to be ``incoming'', and thus determines // the incoming CI:MP couple dpmi.inCI = strdup (caphead->nic); dpmi.inMP = strdup (caphead->mampid); dpmi.first = first = FALSE; } coming_in = !strcmp (caphead->nic, dpmi.inCI) && !strcmp (caphead->mampid, dpmi.inMP); // ok, so we read the packet and returned // ppip and pplast pointers to tstat return 1; } closestream (&dpmi.myStream); return 0; }