Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-11-2010, 05:02 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 2
nostah is on a distinguished road
Default UDP header always has bad checksum

Hello!

I'm trying to send UDP datagrams from iphone app and have encountered a problem I cannot overcome.

The datagrams I send always have UDP header checksum set to 0 and are refused by destination device (networked controller). I have tried both BSD sockets and CFSocket with the same result. I have tried samples from Beej's tutorial - the same.

I have also conducted an experiment on ubuntu run inside virtual box. The same sample of bsd sendto() usage works fine there (= header has a checksum).

I have sniffed packets with wireshark in both cases. What's funny - wireshark on linux found checksum and the same packet cought on mac side had 0x0000 again. I guess that something might have been lost in translation by virtualbox bridge but still is strange to me.

Here is snip of my code (without error checking):
Code:
	int fd = socket(AF_INET, SOCK_DGRAM, 0);
	int broadcast = 1;
	setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (void *)&broadcast, sizeof(broadcast));
	
	struct sockaddr_in addr;
	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = ntohs(1234);
	addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
	addr.sin_len = sizeof(addr);
//	inet_pton(AF_INET, "10.0.1.222", &addr.sin_addr.s_addr);
	
	int num = sendto(fd, data, sizeof(data), 0, (struct sockaddr *)&addr, sizeof(addr));
What can be wrong here? "num" returned by sendto is correct and I can see all the data inside sniffed packets.

I have also written the same code in java, where it works without any problem and my destination device reacts correctly to sent packets.
nostah is offline   Reply With Quote
Reply

Bookmarks

Tags
network, sockets, udp

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 384
7 members and 377 guests
chemistry, daudrizek, HemiMG, jeroenkeij, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:56 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0