broadcast address of a network interface
broadcast address of a network interface
- Subject: broadcast address of a network interface
- From: Joel Reymont <email@hidden>
- Date: Mon, 9 Feb 2009 16:05:19 +0000
Folks,
I'm currently using this chunk of code (based on Quinn's post) to find
the first network interface suitable for broadcasting. The code bombs,
though, since ifa_broadaddr is 0.
How do I make a network broadcast address (.255) from the interface IP
address?
This is the iPhone and broadcasting to 255.255.255.255 won't work in
certain circumstances.
Thanks, Joel
---
#if ! defined(IFT_ETHER)
#define IFT_ETHER 0x6/* Ethernet CSMACD */
#endif
-(void)findBroadcastAddress {
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
if (getifaddrs(&addrs) == 0) {
cursor = addrs;
while (cursor != NULL) {
if ((cursor->ifa_addr->sa_family == AF_LINK)
&& (((const struct sockaddr_dl *)cursor->ifa_addr)-
>sdl_type == IFT_ETHER)
&& (cursor->ifa_flags & (IFF_UP|IFF_BROADCAST)) > 0) {
broadcastAddress = [NSData dataWithBytes:(const
struct sockaddr_dl *)cursor->ifa_broadaddr
length:sizeof(const
struct sockaddr_dl)];
break;
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
}
---
http://tinyco.de
--- Mac & iPhone
_______________________________________________
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