bool openavbAdpOpenSocket(const char* ifname, U16 vlanID, U8 vlanPCP) { AVB_TRACE_ENTRY(AVB_TRACE_ADP); hdr_info_t hdr; #ifndef UBUNTU // This is the normal case for most of our supported platforms rxSock = openavbRawsockOpen(ifname, TRUE, FALSE, ETHERTYPE_8021Q, ADP_FRAME_LEN, ADP_NUM_BUFFERS); #else rxSock = openavbRawsockOpen(ifname, TRUE, FALSE, ETHERTYPE_AVTP, ADP_FRAME_LEN, ADP_NUM_BUFFERS); #endif txSock = openavbRawsockOpen(ifname, FALSE, TRUE, ETHERTYPE_AVTP, ADP_FRAME_LEN, ADP_NUM_BUFFERS); if (txSock && rxSock && openavbRawsockGetAddr(txSock, ADDR_PTR(&intfAddr)) && ether_aton_r(ADP_PROTOCOL_ADDR, &adpAddr) && openavbRawsockRxMulticast(rxSock, TRUE, ADDR_PTR(&adpAddr))) { if (!openavbRawsockRxAVTPSubtype(rxSock, OPENAVB_ADP_AVTP_SUBTYPE | 0x80)) { AVB_LOG_DEBUG("RX AVTP Subtype not supported"); } memset(&hdr, 0, sizeof(hdr_info_t)); hdr.shost = ADDR_PTR(&intfAddr); hdr.dhost = ADDR_PTR(&adpAddr); hdr.ethertype = ETHERTYPE_AVTP; if (vlanID != 0 || vlanPCP != 0) { hdr.vlan = TRUE; hdr.vlan_pcp = vlanPCP; hdr.vlan_vid = vlanID; AVB_LOGF_DEBUG("VLAN pcp=%d vid=%d", hdr.vlan_pcp, hdr.vlan_vid); } if (!openavbRawsockTxSetHdr(txSock, &hdr)) { AVB_LOG_ERROR("TX socket Header Failure"); openavbAdpCloseSocket(); AVB_TRACE_EXIT(AVB_TRACE_ADP); return false; } AVB_TRACE_EXIT(AVB_TRACE_ADP); return true; } AVB_LOG_ERROR("Invalid socket"); openavbAdpCloseSocket(); AVB_TRACE_EXIT(AVB_TRACE_ADP); return false; }
int main(int argc, char* argv[]) { GError *error = NULL; GOptionContext *context; context = g_option_context_new("- rawsock listenr"); g_option_context_add_main_entries(context, entries, NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { printf("error: %s\n", error->message); exit(1); } if (interface == NULL) { printf("error: must specify network interface\n"); exit(2); } void* rs = openavbRawsockOpen(interface, TRUE, FALSE, ethertype, 0, MAX_NUM_FRAMES); if (!rs) { printf("error: failed to open raw socket (are you root?)\n"); exit(3); } hdr_info_t hdr; U8 *pBuf, *pFrame, tmp8; U32 offset, len; U16 uid, i; long nTotal = 0, nRecv[NUM_STREAMS]; for (i = 0; i < NUM_STREAMS; i++) nRecv[i] = 0; struct timespec now, report; clock_gettime(CLOCK_MONOTONIC, &report); report.tv_sec += REPORT_SECONDS; while (bRunning) { pBuf = openavbRawsockGetRxFrame(rs, 1000, &offset, &len); if (pBuf) { pFrame = pBuf + offset; offset = openavbRawsockRxParseHdr(rs, pBuf, &hdr); if ((int)offset < 0) { printf("error parsing frame header"); } else { #ifndef UBUNTU if (hdr.ethertype == ETHERTYPE_8021Q) { // Oh! Need to look past the VLAN tag U16 vlan_bits = ntohs(*(U16 *)(pFrame + offset)); hdr.vlan = TRUE; hdr.vlan_vid = vlan_bits & 0x0FFF; hdr.vlan_pcp = (vlan_bits >> 13) & 0x0007; offset += 2; hdr.ethertype = ntohs(*(U16 *)(pFrame + offset)); offset += 2; } #endif if (hdr.ethertype == ETHERTYPE_AVTP) { //dumpFrame(pFrame + offset, len - offset, &hdr); // Look for stream data frames // (ignore control frames, including MAAP) tmp8 = *(pFrame + offset); if ((tmp8 & 0x80) == 0) { // Find the unique ID in the streamID uid = htons(*(U16*)(pFrame + offset + 10)); if (uid < NUM_STREAMS) nRecv[uid]++; nTotal++; } } } openavbRawsockRelRxFrame(rs, pBuf); } clock_gettime(CLOCK_MONOTONIC, &now); if (timespec_cmp(&now, &report) >= 0) { printf("total=%ld\t", nTotal); nTotal = 0; for (i = 0; i < NUM_STREAMS-1; i++) { if (nRecv[i] > 0) { printf("%d=%ld\t", i, nRecv[i]); nRecv[i] = 0; } } printf("\n"); report.tv_sec += REPORT_SECONDS; } }