<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for veys.com</title>
	<atom:link href="http://veys.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://veys.com</link>
	<description>if I only had a tagline.</description>
	<lastBuildDate>Wed, 10 Mar 2010 07:32:26 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on Time to broadcast, iPhone style by Nick</title>
		<link>http://veys.com/2009/06/27/time-to-broadcast-iphone-style/comment-page-1/#comment-2746</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Wed, 10 Mar 2010 07:32:26 +0000</pubDate>
		<guid isPermaLink="false">http://veys.com/?p=346#comment-2746</guid>
		<description>I can&#039;t stress enough staying in ObjC-land for iPhone development.  I had to drop to C to get the netmask, etc only because the NSHost API isn&#039;t present in the iPhone SDK.

And luckily, someone else has written a nice little UDP library for it as well: http://code.google.com/p/cocoaasyncsocket

Using that, in some of my code (which this post was also written for), sending a UDP broadcast is as simple as:

&lt;code&gt;
    // initialization
    socket = [[AsyncUdpSocket alloc] initWithDelegate:self];
    NSError *error = nil;
    if (![socket enableBroadcast:YES error:&amp;error]) {
        NSLog(@&quot;Failed to enable broadcast: &#039;%@&#039;&quot;, error);
    }
&lt;/code&gt;

and

&lt;code&gt;
    // use
    unsigned char bytes[] = {0};
    NSData *data = [NSData dataWithBytes:bytes length:sizeof(bytes)];
    if (![socket sendData:data toHost:broadcastHost port:33848 withTimeout:2.0 tag:DISCOVERY_TAG]) {
        NSLog(@&quot;Failed to send data to broadcast host &#039;%@&#039;&quot;, broadcastHost);
        return;
    }

    // casually do other stuff, the UDP is asynchronous
    [socket receiveWithTimeout:10.0 tag:DISCOVERY_TAG];
&lt;/code&gt;

Finally, a callback like:

&lt;code&gt;
- (BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port {
    if (DISCOVERY_TAG != tag) {
        return NO;
    }

    // queue up work unit for data received
    // ....
    [[NSNotificationCenter defaultCenter] postNotificationName:@&quot;udp.work.recv&quot; object:self];
    [socket receiveWithTimeout:10.0 tag:DISCOVERY_TAG];
    return YES;
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I can&#8217;t stress enough staying in ObjC-land for iPhone development.  I had to drop to C to get the netmask, etc only because the NSHost API isn&#8217;t present in the iPhone SDK.</p>
<p>And luckily, someone else has written a nice little UDP library for it as well: <a href="http://code.google.com/p/cocoaasyncsocket" rel="nofollow">http://code.google.com/p/cocoaasyncsocket</a></p>
<p>Using that, in some of my code (which this post was also written for), sending a UDP broadcast is as simple as:</p>
<p><code><br />
    // initialization<br />
    socket = [[AsyncUdpSocket alloc] initWithDelegate:self];<br />
    NSError *error = nil;<br />
    if (![socket enableBroadcast:YES error:&amp;error]) {<br />
        NSLog(@"Failed to enable broadcast: '%@'", error);<br />
    }<br />
</code></p>
<p>and</p>
<p><code><br />
    // use<br />
    unsigned char bytes[] = {0};<br />
    NSData *data = [NSData dataWithBytes:bytes length:sizeof(bytes)];<br />
    if (![socket sendData:data toHost:broadcastHost port:33848 withTimeout:2.0 tag:DISCOVERY_TAG]) {<br />
        NSLog(@"Failed to send data to broadcast host '%@'", broadcastHost);<br />
        return;<br />
    }</p>
<p>    // casually do other stuff, the UDP is asynchronous<br />
    [socket receiveWithTimeout:10.0 tag:DISCOVERY_TAG];<br />
</code></p>
<p>Finally, a callback like:</p>
<p><code><br />
- (BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port {<br />
    if (DISCOVERY_TAG != tag) {<br />
        return NO;<br />
    }</p>
<p>    // queue up work unit for data received<br />
    // ....<br />
    [[NSNotificationCenter defaultCenter] postNotificationName:@"udp.work.recv" object:self];<br />
    [socket receiveWithTimeout:10.0 tag:DISCOVERY_TAG];<br />
    return YES;<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Time to broadcast, iPhone style by Tim DeBenedictis</title>
		<link>http://veys.com/2009/06/27/time-to-broadcast-iphone-style/comment-page-1/#comment-2745</link>
		<dc:creator>Tim DeBenedictis</dc:creator>
		<pubDate>Wed, 10 Mar 2010 01:47:00 +0000</pubDate>
		<guid isPermaLink="false">http://veys.com/?p=346#comment-2745</guid>
		<description>I have not tested your code yet, but it appears to solve at least *part* of a problem that I&#039;ve got.

The other part is, I need to actually send a UDP broadcast message to the WiFi broadcast address, from my iPhone, and listen for a response.  I&#039;ve found a bunch of examples, mostly linux-based, but all of them fail on the iPhone.  Here&#039;s my code - what fails is listed below it:

{
	struct sockaddr_in saddr = { 0 };
	struct sockaddr_in raddr = { 0 };
	
	int sock;
	int on = 1;
    
	// open socket
	if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
	{
		return ( TEL_SOCKET_OPEN_ERROR );
	}

	// enable udp broadcast
	if ( setsockopt ( sock, SOL_SOCKET, SO_BROADCAST, &amp;on, sizeof on ) &lt; 0 ) 
	{
		close ( sock );
		return ( TEL_SOCKET_OPEN_ERROR );
	}
	
	// setup source port / destination address

	saddr.sin_len = sizeof ( saddr );
	saddr.sin_family = AF_INET;
	saddr.sin_port = htons(4031);
	saddr.sin_addr.s_addr = inet_addr ( &quot;10.255.255.255&quot; ); // htonl(INADDR_BROADCAST);
	
	// bind outgoing port
	
	if (bind(sock, (sockaddr *) &amp;saddr, sizeof(saddr)) &lt; 0)
	{
		perror ( &quot;bind&quot; );
//		return ( TEL_SOCKET_OPEN_ERROR );
	}
	
	raddr.sin_len = sizeof ( raddr );
	raddr.sin_family = AF_INET;
	raddr.sin_port = htons(4031);
	raddr.sin_addr.s_addr = inet_addr ( &quot;10.255.255.255&quot; ); // htonl(INADDR_BROADCAST);

	const char *buf = &quot;skyfi?&quot;;
	if (sendto(sock, buf, strlen(buf), 0, (sockaddr *) &amp;raddr, sizeof(raddr)) &lt; 0)
	{
		perror ( &quot;sendto&quot; );
		return ( TEL_SOCKET_WRITE_ERROR );
	}
	
	sleep ( 1 );
	
	char	reply[256] = { 0 };
	int		replen = 0;
	
	replen = recvfrom ( sock, reply, sizeof ( reply ), 0, NULL, 0 );
	if ( replen &lt; 1 )
	{
		return ( TEL_SOCKET_READ_ERROR );
	}
		
	return ( TEL_NO_ERROR );
}

The above code always fails at the sendto() call, and errno is set to 49 (EADDRNOTAVAIL).  perror() gives me sendto: Can&#039;t assign requested address.  I happen to know that the WiFi network broadcast address is 10.255.255.255 - that&#039;s why that value is hard coded.  But I still can&#039;t send to it.  Arrrgh!

Incidentally, your code (if it works) would solve the other part of my problem, which is finding the broadcast address in the first place.

Thanks in advance,

-Tim</description>
		<content:encoded><![CDATA[<p>I have not tested your code yet, but it appears to solve at least *part* of a problem that I&#8217;ve got.</p>
<p>The other part is, I need to actually send a UDP broadcast message to the WiFi broadcast address, from my iPhone, and listen for a response.  I&#8217;ve found a bunch of examples, mostly linux-based, but all of them fail on the iPhone.  Here&#8217;s my code &#8211; what fails is listed below it:</p>
<p>{<br />
	struct sockaddr_in saddr = { 0 };<br />
	struct sockaddr_in raddr = { 0 };</p>
<p>	int sock;<br />
	int on = 1;</p>
<p>	// open socket<br />
	if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)<br />
	{<br />
		return ( TEL_SOCKET_OPEN_ERROR );<br />
	}</p>
<p>	// enable udp broadcast<br />
	if ( setsockopt ( sock, SOL_SOCKET, SO_BROADCAST, &amp;on, sizeof on ) &lt; 0 )<br />
	{<br />
		close ( sock );<br />
		return ( TEL_SOCKET_OPEN_ERROR );<br />
	}</p>
<p>	// setup source port / destination address</p>
<p>	saddr.sin_len = sizeof ( saddr );<br />
	saddr.sin_family = AF_INET;<br />
	saddr.sin_port = htons(4031);<br />
	saddr.sin_addr.s_addr = inet_addr ( &quot;10.255.255.255&quot; ); // htonl(INADDR_BROADCAST);</p>
<p>	// bind outgoing port</p>
<p>	if (bind(sock, (sockaddr *) &amp;saddr, sizeof(saddr)) &lt; 0)<br />
	{<br />
		perror ( &quot;bind&quot; );<br />
//		return ( TEL_SOCKET_OPEN_ERROR );<br />
	}</p>
<p>	raddr.sin_len = sizeof ( raddr );<br />
	raddr.sin_family = AF_INET;<br />
	raddr.sin_port = htons(4031);<br />
	raddr.sin_addr.s_addr = inet_addr ( &quot;10.255.255.255&quot; ); // htonl(INADDR_BROADCAST);</p>
<p>	const char *buf = &quot;skyfi?&quot;;<br />
	if (sendto(sock, buf, strlen(buf), 0, (sockaddr *) &amp;raddr, sizeof(raddr)) &lt; 0)<br />
	{<br />
		perror ( &quot;sendto&quot; );<br />
		return ( TEL_SOCKET_WRITE_ERROR );<br />
	}</p>
<p>	sleep ( 1 );</p>
<p>	char	reply[256] = { 0 };<br />
	int		replen = 0;</p>
<p>	replen = recvfrom ( sock, reply, sizeof ( reply ), 0, NULL, 0 );<br />
	if ( replen &lt; 1 )<br />
	{<br />
		return ( TEL_SOCKET_READ_ERROR );<br />
	}</p>
<p>	return ( TEL_NO_ERROR );<br />
}</p>
<p>The above code always fails at the sendto() call, and errno is set to 49 (EADDRNOTAVAIL).  perror() gives me sendto: Can&#039;t assign requested address.  I happen to know that the WiFi network broadcast address is 10.255.255.255 &#8211; that&#039;s why that value is hard coded.  But I still can&#039;t send to it.  Arrrgh!</p>
<p>Incidentally, your code (if it works) would solve the other part of my problem, which is finding the broadcast address in the first place.</p>
<p>Thanks in advance,</p>
<p>-Tim</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on NSURLConnection + startImmediately:NO == boom? by sam</title>
		<link>http://veys.com/2008/08/17/nsurlconnection-startimmediatelyno-boom/comment-page-1/#comment-2743</link>
		<dc:creator>sam</dc:creator>
		<pubDate>Mon, 01 Feb 2010 15:10:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.veys.com/?p=320#comment-2743</guid>
		<description>Cheers mate, helped me out a lot</description>
		<content:encoded><![CDATA[<p>Cheers mate, helped me out a lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Restoring from a Samba-based Time Machine backup (kinda) by nick</title>
		<link>http://veys.com/2009/08/16/restoring-from-a-samba-based-time-machine-backup-kinda/comment-page-1/#comment-2738</link>
		<dc:creator>nick</dc:creator>
		<pubDate>Tue, 08 Dec 2009 22:11:23 +0000</pubDate>
		<guid isPermaLink="false">http://veys.com/?p=354#comment-2738</guid>
		<description>That would definitely be something to try.  It looks like it&#039;s pretty trivial to &lt;a href=&quot;http://www.askbjoernhansen.com/2007/10/27/setup_samba_for_bonjour_networking_with_os_x_105_l.html&quot; rel=&quot;nofollow&quot;&gt;advertise the samba service using Avahi&lt;/a&gt;.

However much I hope to never again need this information, sadly I&#039;m sure I will.</description>
		<content:encoded><![CDATA[<p>That would definitely be something to try.  It looks like it&#8217;s pretty trivial to <a href="http://www.askbjoernhansen.com/2007/10/27/setup_samba_for_bonjour_networking_with_os_x_105_l.html" rel="nofollow">advertise the samba service using Avahi</a>.</p>
<p>However much I hope to never again need this information, sadly I&#8217;m sure I will.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Some Airsoft Turret play by John Baxendale</title>
		<link>http://veys.com/2008/02/22/some-airsoft-turret-play/comment-page-1/#comment-2737</link>
		<dc:creator>John Baxendale</dc:creator>
		<pubDate>Tue, 08 Dec 2009 18:11:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.veys.com/blog/?p=57#comment-2737</guid>
		<description>That&#039;s just awesome - top job!</description>
		<content:encoded><![CDATA[<p>That&#8217;s just awesome &#8211; top job!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Restoring from a Samba-based Time Machine backup (kinda) by John Baxendale</title>
		<link>http://veys.com/2009/08/16/restoring-from-a-samba-based-time-machine-backup-kinda/comment-page-1/#comment-2736</link>
		<dc:creator>John Baxendale</dc:creator>
		<pubDate>Tue, 08 Dec 2009 18:09:20 +0000</pubDate>
		<guid isPermaLink="false">http://veys.com/?p=354#comment-2736</guid>
		<description>Hi,

Thanks for this article it&#039;s just saved me some work and messing around - that is always welcome :)

I think possibly the reason that you need to mount the share manually is nothing to do with the fact the backup directory is a Samba share, but more to do with the fact that you&#039;re not announcing it via ZeroConf/Bonjour.

I&#039;ve come to this conclusion because I&#039;ve just had a similar problem trying to restore a backup from an AirPort Extreme to a Hackintosh. The problem though, as far as I can tell, is that the Apple boot DVD doesn&#039;t properly enable Bonjour on the Hackintosh Macs (something to do with the UUID string for the host not being determined properly which breaks Bonjour).

I&#039;m reasonably sure if the share were to be announced via Bonjour the Mac would pick it up and happily restore from it, regardless of whether it&#039;s delivered over SMB/CIFS or AFP.

It&#039;s a hunch! :)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Thanks for this article it&#8217;s just saved me some work and messing around &#8211; that is always welcome <img src='http://veys.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I think possibly the reason that you need to mount the share manually is nothing to do with the fact the backup directory is a Samba share, but more to do with the fact that you&#8217;re not announcing it via ZeroConf/Bonjour.</p>
<p>I&#8217;ve come to this conclusion because I&#8217;ve just had a similar problem trying to restore a backup from an AirPort Extreme to a Hackintosh. The problem though, as far as I can tell, is that the Apple boot DVD doesn&#8217;t properly enable Bonjour on the Hackintosh Macs (something to do with the UUID string for the host not being determined properly which breaks Bonjour).</p>
<p>I&#8217;m reasonably sure if the share were to be announced via Bonjour the Mac would pick it up and happily restore from it, regardless of whether it&#8217;s delivered over SMB/CIFS or AFP.</p>
<p>It&#8217;s a hunch! <img src='http://veys.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on NSURLConnection + startImmediately:NO == boom? by Devon</title>
		<link>http://veys.com/2008/08/17/nsurlconnection-startimmediatelyno-boom/comment-page-1/#comment-2735</link>
		<dc:creator>Devon</dc:creator>
		<pubDate>Tue, 03 Nov 2009 10:31:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.veys.com/?p=320#comment-2735</guid>
		<description>Wow, that really helped me out. Thanks for that, would probably have taken weeks to figure out.</description>
		<content:encoded><![CDATA[<p>Wow, that really helped me out. Thanks for that, would probably have taken weeks to figure out.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
