Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can not receive packages from opened socket




When using a PF_NDRV socket, you need to specify the types of packets you are interested in receiving. Check the net/ndrv.h header. There is an socket option you can use to specify demux descriptors. Those descriptors will be used to match incoming packets. If an incoming packet matches, your socket will get the packet. Your demux descriptors can not conflict with any other descriptors in use by protocols already attached to the interface (you can't get IP or AppleTalk packets if those protocols are attached to the interface).

-josh

On Oct 30, 2006, at 9:01 PM, Robin wrote:

Hi, All

I did my receive package as this, 1. open socket  2. bind . 3 receive package. But I can not get any packets from the opened socket by Airport Extreme card. The AP has sent many BROADCAST packets at the same time, I've caught them on the PC system. On the other side, I can send package successfully by this way. I't s very strange. 

This is my action, 

1. open socket // successfully
fd_recv = socket(AF_NDRV, SOCK_RAW, 0x0);//decided by the hardware

2. bind  // successfully
strcpy(gEnetDataPtr->saddr.sa_data, gedata[gCurrEnetEntry].bsdName);
gEnetDataPtr->saddr.sa_len = sizeof(struct sockaddr);
gEnetDataPtr->saddr.sa_family = AF_NDRV;
err = bind(gEnetDataPtr->fd_recv, &(gEnetDataPtr->saddr), sizeof(gEnetDataPtr->saddr));

3. receive data  // always get 0 bytes
int nFlag = MSG_TRUNC|= MSG_DONTWAIT;

fd_set set;
struct timeval tout;

addrlen = sizeof(m_bEtherNetData->saddr);
memset(&m_bEtherNetData->saddr,0, addrlen);
tout.tv_sec =0;
tout.tv_usec = 500000; //decided by the hardware

FD_ZERO(&set);
FD_SET(m_bEtherNetData->fd_recv, &set);
if(select(m_bEtherNetData->fd_recv + 1 , &set, NULL, NULL, &tout)> 0 && FD_ISSET(m_bEtherNetData->fd_recv, &set))
{
nRead = recvfrom(m_bEtherNetData->fd_recv, pRxPackage->PacketBuffer, pRxPackage->PacketBufferLength, nFlag , &(m_bEtherNetData->saddr), &addrlen);
fprintf (stderr, "receive package OK,  get %d byetes ... \n", nRead);
}else
{
nRead = -1;
fprintf (stderr, "receive package error ...\n");
}


I do not know what wrong it is, and I run the BSDLLC example, it can not get any packet too.

Does anyone know what else should I do ? Any suggestion is grateful!

Best regards,
Robin
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden

References: 
 >Can not receive packages from opened socket (From: Robin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.