Receiving UDP broadcasts
Receiving UDP broadcasts
- Subject: Receiving UDP broadcasts
- From: Ryan McGann <email@hidden>
- Date: Sat, 7 Jun 2003 15:53:50 -0700
Is there any special trick to receiving UDP broadcasts? When I run the
following code, I get nada. But I can see the UDP broadcast packets
coming in via tcpdump. The packets are being sent by an SNMP aware
router. I am on the same subnet as the router (it's my DHCP server),
and I am running the process as root. BTW, I tried using recvfrom
instead of CFSocket and get the same results (or lack thereof).
Thanks for any insight you can give.
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <CoreFoundation/CoreFoundation.h>
void SNMPSocketCallBack( CFSocketRef, CFSocketCallBackType, CFDataRef,
const void *, void * );
int main( int argc, int argv )
{
int theSocket;
struct sockaddr_in theAddress;
CFSocketContext theContext = { 0, NULL, NULL, NULL, NULL };
CFSocketRef theSocketRef;
CFRunLoopSourceRef theRLSourceRef;
theAddress.sin_addr.s_addr = INADDR_ANY;
theAddress.sin_len = 0;
theAddress.sin_family = AF_INET;
theAddress.sin_port = htons( 162 );
theSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
bind( theSocket, (struct sockaddr *) &theAddress, sizeof( theAddress )
);
theSocketRef = CFSocketCreateWithNative( NULL, theSocket,
kCFSocketReadCallBack, SNMPSocketCallBack, &theContext );
theRLSourceRef = CFSocketCreateRunLoopSource( NULL, mSNMPSocketRef, 0
);
CFRunLoopAddSource( CFRunLoopGetCurrent(), theRLSourceRef,
kCFRunLoopDefaultMode );
CFRelease( theRLSourceRef );
}
void
SNMPSocketCallBack(
CFSocketRef inSocketRef,
CFSocketCallBackType inCallBack,
CFDataRef inAddressRef,
const void *inDataRef,
void *inInfo )
{
printf( "SNMPSocketCallBack called\n" );
}
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.