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.

AM3359 Raw Ethernet Sockets Programming

i use sys/bios and ndk on a project about   Raw Ethernet Sockets Programming.

but i find someting wired.

when i send a packet , i can only send a fewer , and when i cannot send more, in detail:

when my packet size is 1000,i can only send 11 packets.

when my packet size is 500, i can only send 23 packets.

when my packet size is 100,i can only send 78 packets.

it seems like that memory problems?

my main code is :

     SOCKET 	s;
     Uint32  rawether_type = 0xC021;
    int bytes;
//  unsigned short phy;

    UINT8 	src_mac[6]= { 0xff, 0xee, 0x00, 0x00, 0xee, 0xfe };
    UINT8 	dst_mac[6]= { 0x10, 0x22, 0x33, 0x44, 0x78, 0x4a };

    unsigned int i;

    //等待网络完成连接link-up
    Task_sleep(5000);

    //打开文件环境
	fdOpenSession(TaskSelf());//使用socket应用函数时必须执行该语句

	//创建一个原始套接字
	s = socket(AF_RAWETH, SOCK_RAWETH, rawether_type);//前两个参数在原始以太网套接字时必须是固定的这两个,后面一个是协议类型,某些不支持,但可以自定义,0x300即就是自定义协议,属于EtherType中实验段的协议
	if(s == INVALID_SOCKET)
	{
		printf("\ncreate socket error");
		printf("\nsocket>>	%d", fdError());
		fdCloseSession (TaskSelf());
	}

	//配置硬件接口
	val = 1;
	retVal = setsockopt(s, SOL_SOCKET, SO_IFDEVICE, &val, sizeof(val));//使用原始以太网套接字时SO_IFDEVICE必须设置成功
	if(retVal)
	{
		printf("\nsetsockopt_IFDEVICE>>	%d", fdError());
		printf("\nerror in setsockopt ");
	}

	//配置套接字优先级
	val = 3;
	retVal = setsockopt(s, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val));
	if(retVal)
		printf("error in setsockopt \n");

	//配置接收缓存器的大小
	val = 8192;
	retVal = setsockopt(s, SOL_SOCKET, SO_RCVBUF, &val, sizeof(val));
	if(retVal)
	{
		printf("\nsetsockopt_RCVBUF>>	%d", fdError());
		printf("\nerror in setsockopt ");
	}

	//配置等待接收超时
	to.tv_sec  = 0;
	to.tv_usec = 0;
	setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
	setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );

//	发送数据部分

	//分配数据空间
	if ((pBuffer = mmBulkAlloc (sizeof(char) * 1024)) == NULL)
	{
		printf("OOM ?? \n");
		TaskExit();
	}

	//IP头部数据
	bData[0] = 0x00;	//IPv4版本头部第一个字节必为0x45
	for (i = 1; i < 20; i++)
		bData[i] = 0x10 + i;

	ptr_eth_header = (ETHHDR*)pBuffer;

	//填充MAC帧头部
	mmCopy (ptr_eth_header->SrcMac, src_mac, 6);//填充源MAC地址
	mmCopy (ptr_eth_header->DstMac, dst_mac, 6);//填充目的MAC地址
	ptr_eth_header->Type = HNC16(rawether_type);//填充网络协议
	mmCopy(pBuffer + ETHHDR_SIZE, bData, 20);//填充IP头部分

	while(1)
	{
	
	   retVal = send(s, pBuffer, 1000, 0);
	   if(retVal < 0)
		{
			printf("\nsend error  %d", fdError());
		}

		Task_sleep(1);	//延时发送,满足MAC连续发送需要一定的间隔的要求


	}

this is the API i use :

                                                    
	 				 	
	 send()			[socket.c]
		 					 
       RawEthSockSend()	        [rawethsock.c]
		 					
       RawEthTxPacket()	        [raw eth.c]
		 					
       NIMUSendPacket()		[nimu.c]

 	send {CpswEmacSend()}	[cpsw_nimu_eth.c]
							
 	CpswHwPktTxNext()       [cpsw_ethdriver.c]
							
 	Cpsw_sendPacket()	[cpsw_impl.c]