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.

Help! some questions of NDK 2.0.0.0

hi,anyone~

    my project is run on 6747.i update my project with ndk 2.0.0.0 ,because i want to use the raw ethernet socket. I use raw ethernet socket to send  ARP packeges for detecting ip address collision.I send the ARP request to the other device. but there is a problem to me .how can i receive the ARP reply package? i use recvnc() function ,but it can't not recv the ARP reply package. i wonder weather  the reply package is captured by the tcp/ip stack? so i can't catch this reply package. can any one give a hand ?thanks a lot. my code is pasted below:[:)]

the code can send the ARP request correctly,and the target device sent a ARP reply correctly too.but the code can't receive the reply package.!!  help ~~ thanks again

int arpping(SkUInt32 test_ip, SkUInt32 from_ip, SkUInt8 *from_mac, char *interface1)
{
 UINT32 prevTime ;
 struct arpMsg arp;
 HANDLE hbuff;
 char * pbuf;
 SOCKET sraw = INVALID_SOCKET;
 UINT16 priority = 0;
 int    retVal, val;
 struct timeval to;
 
 /* 创建raw socket */
 sraw = socket(AF_RAWETH, SOCK_RAWETH, 0x300);
 if( sraw == INVALID_SOCKET )
 {
  ConPrintf("Fail socket %d\n", fdError());
  return -1;
 }
 /* 配置硬件接口 */
 val = 1;
 retVal = setsockopt(sraw, SOL_SOCKET, SO_IFDEVICE, &val, sizeof(val));
 if(retVal)
 {
  ConPrintf("error in setsockopt SO_IFDEVICE %d\n", fdError());
  fdClose(sraw);
  return -1;
 }
 /* 配置优先级 */
 val = 3;
 retVal = setsockopt(sraw, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val));
 if(retVal)
 {
  ConPrintf("error in setsockopt SO_PRIORITY %d\n", fdError());
  fdClose(sraw);
  return -1;
 }
 /* 配置接收超时 */
    to.tv_sec  = 0;
    to.tv_usec = 100*1000L;
 retVal = setsockopt( sraw, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );
 if(retVal)
 {
  ConPrintf("error in setsockopt SO_RCVTIMEO %d\n", fdError());
  fdClose(sraw);
  return -1;
 }
 
 memset(&arp, 0, sizeof(arp));
 memset(arp.h_dest, 0xff, 6);                    /* 目标MAC地址 */
 memcpy(arp.h_source, from_mac, 6);              /* 本地MAC地址 */
 arp.h_proto   = htons(0x0806);                  /* 协议类型 */
 arp.htype    = htons(0x0001);                 /* 硬件类型 */
 arp.ptype    = htons(0x0800);            /* 消息协议类型 */
 arp.hlen    = 6;                   /* MAC地址长度 */
 arp.plen    = 4;                              /* 协议地址长度 */
 arp.operation = htons(0x0001);                  /* ARP类型编码 */
 memcpy(arp.sHaddr, from_mac, 6);                /* 本地MAC地址 */
 memcpy(arp.sInaddr, &from_ip, sizeof(from_ip)); /* 本地IP地址 */
                                                 /* 目标MAC地址,填0 */
 memcpy(arp.tInaddr, &test_ip, sizeof(test_ip)); /* 目标IP地址 */
 /*
 发送ARP包
 可以使用RawEthTxPacket 也可以使用 send
 */
 #if 0
 RawEthTxPacket(sraw, (char*)&arp, sizeof(arp));
 #else
 retVal = send(sraw, (char*)&arp, sizeof(arp),0);
 if(retVal < 0)
 {
  ConPrintf("send error  %d\n", fdError());
 }
 #endif
 prevTime  = llTimerGetTime(0);
 /*5秒钟内接收ARP回包*/
 do
 {
  retVal = -1;
  //读取返回数据.
  memset(&arp, 0, sizeof(arp));
  retVal = recvnc(sraw, (void **)&pbuf, /*0*/MSG_DONTWAIT, &hbuff);
  ConPrintf("recv retVal  %d [%d]\n",retVal,fdError());
  if(retVal <= 0)
  {
   continue;
  }
  #if 0
  else if(retVal >= ARP_MSG_SIZE
   && arp.operation == htons(0x0002)
   && memcmp(arp.tHaddr, from_mac, 6) == 0
   && *((SkUInt32*) arp.sInaddr) == test_ip
  )
  {
   ConPrintf("recv from someone \n");
   break;
  }
  #endif
 }while (prevTime+5 > llTimerGetTime(0));
end:
 fdClose(sraw);
 return retVal;
}