#include "three.h"
#define NT_BUFSIZ 64
int NumMBufs = 3;
M_CL_CONFIG myMclConfig = /* mBlk configuration table */
{
0, 0, NULL, 0
};
CL_DESC myClDescTbl [] = /* network cluster pool configuration table */
{
/*
clusterSize num memArea memSize
----------- ---- ------- -------
*/
{NT_BUFSIZ, 3, 0x1000, 1000}
};
int myClDescTblNumEnt = (NELEMENTS(myClDescTbl));
void threedemo()
{
/* Set up a net Pool */
CL_POOL_ID mpClPoolId;
NET_POOL netPool;
NET_POOL_ID pNetPool = &netPool;
M_BLK_ID pMblk;
M_BLK_ID pMblk1;
M_BLK_ID pMblk2;
int len=0;
int len1=0;
char * pNewCluster;
char * pNewCluster1;
char * pNewCluster2;
CL_BLK_ID pClBlk;
CL_BLK_ID pClBlk1;
CL_BLK_ID pClBlk2;
char copyBuf[1600];
char a[14] = {0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x01,0x08,0x00};
char b[20] = {0x45, 0x00, 0x00,0x1e,
0x01,0x00,
0x40,0x00,
0x20,0x20,
0xda,0x79,
0xc0,0xa8,0xff,0x01,
0xc0,0xa8,0xff,0x01};
char c[10] = {0x1f,0x40,0x0f,0xa0,0x00,0x0a,0x76,0xb5,0x02,0x12};
myMclConfig.mBlkNum = NumMBufs;
myMclConfig.clBlkNum = NumMBufs;
myMclConfig.memSize = (myMclConfig.mBlkNum * (MSIZE + sizeof (long))) +
(myMclConfig.clBlkNum * (CL_BLK_SZ + sizeof(long)));
/* allocate memory pool */
if ((myMclConfig.memArea = (char *) memalign (sizeof(long),
myMclConfig.memSize))
== NULL)
{
return;
}
myClDescTbl[0].clNum = NumMBufs;
myClDescTbl[0].memSize = (myClDescTbl[0].clNum * (NT_BUFSIZ + 8))
+ sizeof(int);
myClDescTbl[0].memArea = malloc ( myClDescTbl[0].memSize );
if (netPoolInit(pNetPool, &myMclConfig,
&myClDescTbl[0], myClDescTblNumEnt, NULL) == ERROR)
{
return ;
}
/* Store the cluster pool id as others need it later. */
mpClPoolId = clPoolIdGet(pNetPool,NT_BUFSIZ, FALSE);
pNewCluster = netClusterGet (pNetPool,mpClPoolId);
if(pNewCluster == NULL)
{
return;
}
bcopy(a,pNewCluster,14);
pClBlk = netClBlkGet (pNetPool, M_DONTWAIT);
if(pClBlk == NULL)
{
return;
}
pMblk = mBlkGet (pNetPool, M_DONTWAIT,MT_DATA);
if( pMblk == NULL)
{
return;
}
netClBlkJoin (pClBlk, pNewCluster, 14, NULL, 0, 0, 0);
netMblkClJoin (pMblk, pClBlk);
pMblk->mBlkHdr.mLen = 14;
pMblk->mBlkHdr.mNext = NULL; /*十字链表尾指针为空*/
pMblk->mBlkHdr.mNextPkt = NULL; /*十字链表尾指针为空*/
/* data of the 2*/
pNewCluster1 = netClusterGet (pNetPool,mpClPoolId);
if(pNewCluster1== NULL)
{
return;
}
bcopy(b,pNewCluster1,20);
pClBlk1 = netClBlkGet (pNetPool, M_DONTWAIT);
if(pClBlk1 == NULL)
{
return;
}
pMblk1 = mBlkGet (pNetPool, M_DONTWAIT,MT_DATA);
if( pMblk1 == NULL)
{
return;
}
netClBlkJoin (pClBlk1, pNewCluster1, 20, NULL, 0, 0, 0);
netMblkClJoin (pMblk1, pClBlk1);
pMblk1->mBlkHdr.mLen = 20;
pMblk1->mBlkHdr.mNext = NULL; /*十字链表尾指针为空*/
pMblk1->mBlkHdr.mNextPkt = NULL; /*十字链表尾指针为空*/
/*data of 3*/
pNewCluster2 = netClusterGet (pNetPool,mpClPoolId);
if(pNewCluster2== NULL)
{
return;
}
bcopy(c,pNewCluster2,10);
pClBlk2 = netClBlkGet (pNetPool, M_DONTWAIT);
if(pClBlk2 == NULL)
{
return;
}
pMblk2 = mBlkGet (pNetPool, M_DONTWAIT,MT_DATA);
if( pMblk2 == NULL)
{
return;
}
netClBlkJoin (pClBlk2, pNewCluster2, 10, NULL, 0, 0, 0);
netMblkClJoin (pMblk2, pClBlk2);
pMblk2->mBlkHdr.mLen = 10;
pMblk2->mBlkHdr.mNext = NULL; /*十字链表尾指针为空*/
pMblk2->mBlkHdr.mNextPkt = NULL; /*十字链表尾指针为空*/
pMblk->mBlkHdr.mNext=pMblk1;
pMblk1->mBlkHdr.mNext=pMblk2;
len = netMblkToBufCopy (pMblk, (char *)copyBuf, NULL);
for(len1=0;len1<len;len1++)
{
printf("0x %x ",copyBuf[len1]);
}
}