UDP Broadcast uses random source ports
UDP Broadcast uses random source ports
- Subject: UDP Broadcast uses random source ports
- From: email@hidden
- Date: Wed, 31 Aug 2011 00:05:40 -0700
The source port of my outgoing UDP replys seem to change on each
broadcast message. The messages always seem to hit the right port on the
receiving device. Everything seems to function fine except for this
issue. Here is the code that I am using.
int broadcast = 1;
int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
// this call is what allows broadcast packets to be sent:
if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &broadcast,
sizeof broadcast) == -1) {
NSLog(@"setsockopt: Fail!");
}
CFSocketRef sockRef =
CFSocketCreateWithNative(kCFAllocatorDefault, sockfd,
kCFSocketNoCallBack, NULL, NULL);
if (sockRef) {
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(kPortNumber); // 6454
addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
CFDataRef addrData = CFDataCreate(NULL, (unsigned char
*)&addr, sizeof(addr));
CFSocketError result = CFSocketSendData(sockRef, addrData,
(CFDataRef)pollReply, 0.0);
if (result != kCFSocketSuccess)
{
NSLog(@"CFSocketSendData: Fail!");
}
//NSLog(@"CFSocketSendData: Success!");
CFRelease(sockRef);
CFRelease(addrData);
}
My local address is 10.0.10.6, the server address is 10.0.10.136. The
Local port shows up as 56360. I am wanting it to be 6454 consistently.
The poll and reply messages are below.
From 10.0.10.136(6454) To 10.0.10.255(6454) ArtPoll, Enquiry to
Art-Net device(s)
Raw Data = { [41], [72], [74], [2D], [4E], [65], [74], [00],
[00], [20], [00], [0E], [06], [00], [00], [00], [7C], [4D], [93], [01],
[7C], [4D], [00], [00], [56], [46], [46], [6C], [65], [78], [4E], [6F],
... } //Data )
From 10.0.10.6(56360) To 255.255.255.255(6454) ArtPollReply,
Reply to ArtPoll
Raw Data = { [41], [72], [74], [2D], [4E], [65], [74], [00],
[00], [21], [0A], [00], [0A], [06], [36], [19], [01], [01], [00], [00],
[0B], [70], [00], [00], [56], [46], [46], [6C], [65], [78], [4E], [6F],
... } //Data )
>> Error in source port number
Thanks, Chad Williams
_______________________________________________
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