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.