This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Receive all IP packets with NDK

Hello,

I'm trying to use the NDK to process all incoming IP packets in a TMDSEVM6670LE, and for that I'm using the socket API as described in SPRU524i section 3.3.

My problem is that I cannot even receive UDP datagrams when using a SOCK_RAW socket. I have verified that *the code works* when SOCK_DGRAM is used instead. So, how should I configure the NDK to give me the packets?

The code is modified from mcsdk_2_01_02_06/examples/ndk/helloWorld/, I have replaced the UDP task there with this one:

ret = fdOpenSession(TaskSelf());
if (ret == 0) {
	/* Error */
	System_printf("Error opening fd session.\n");
	return;
}

s = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
if (s == INVALID_SOCKET) {
	System_printf("Error: socket creation returns %d\n",
		fdError());
}

struct sockaddr_in sin;
struct in_addr sina = {
	INADDR_ANY
};
memset(&sin, 0, sizeof(struct sockaddr_in));
sin.sin_family = AF_INET;
sin.sin_addr = sina;
sin.sin_port = htons(1025);
ret = bind(s, (PSA)&sin, sizeof(struct sockaddr_in));
if (ret == -1) {
	System_printf("Error: socket bind returns %d\n",
		fdError());
}


int val = 1;
ret = setsockopt(s, IPPROTO_IP, IP_HDRINCL, &val, sizeof(val));
if (ret == -1) {
	System_printf("Error: socket setsockopt returns %d\n",
		fdError());
}


UInt8 *buf;
HANDLE buf_hnd;
while (1) {
	ret = recvnc(s, &buf, MSG_WAITALL, &buf_hnd);

	recvncfree(buf_hnd);
}

fdCloseSession(TaskSelf());

Can this be done with SOCK_RAW? If not, AF_RAWETH with SOCK_RAWETH seemed the next logical choice, but section 3.5.2 says that I cannot use IP protocols there. I don't mind receiving the ethernet headers as well, all I care is that IP packets can be processed by my application.

  • Hi,

    You can find the client example project at the mcsdk package. And also find the routine to demonstrate packet receive using recvnc() API  and AF_RAWETH family sockets are available in the client.c file.

    C:\ti\mcsdk_2_01_02_06\examples\ndk\client

  • Pubesh,

    I am familiar with the mcsdk client example. However, if I understand it correctly, the 'raweth' tasks are creating sockets for ethertype 0x300. My application requires the processing of standard IPv4 packets, similar to how a gateway would work. Therefore, no change should be required on other hosts in the network.

    My question is more general: what kind of API should I use so that my application can receive all packets entering the interface?

  • Hi,

    Please refer the TI Network Developer's Kit (NDK) API Reference Guide(spru524h) and User's Guide(spru523h)
    Go through the section "Raw Ethernet Data Prioritization - Socket Priority Use Case" in the API reference guide.
    You check the EtherSetPktFilter API, it may be used with passing the valid filter value.

  • Hi Pubesh,

    I have not yet tested your suggestion. Let me see if I understand it correctly: if I use the EtherSetPktFilter API and set it to ETH_PKTFLT_ALL, I should be able to read all incoming ethernet frames?

    How should I use that? Do I have to create an Ether object myself, or do I fetch it from some other API?

  • Hi,

    To try out the example, use the Windows test application found in the WINAPPS directory of the NDK root. The application is command driven and requires a target IP address, such as: helloWorld 192.63.10.5
    This sends Hello World! through a UDP socket connection, and reads the transmitted information by the
    stack.