Prev: UDP broadcast
Next: Create staple diagrams from a text file (containing numbers)from command line?
From: cerr on 2 Feb 2010 13:55 Hi There, I would like to send a UDP broadcast datagram to all my network peers. I've tried using following code: struct sockaddr_in addr; int BrdcstSock; string message = "Hello, World!"; if ((BrdcstSock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { std::cerr << "PIDClient: Error creating socket.\n"; return; } /* set up destination address */ memset(&addr,0x00,sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr("192.168.101.255"); addr.sin_port=htons(6767); while (1) { if (sendto(BrdcstSock, message.c_str(), strlen(message.c_str()), 0, (struct sockaddr *) &addr, sizeof(addr)) != message.size()){ cout << "Error:" << strerror(errno) << endl; return; } else { cout << "sent:" << message << endl; } sleep(3); } However, I do not see these packets with Wireshark and neither am I seeing an error on the shell but i properly see "sent: Hello, World!" appearing... :( What's going on here, any clues? Thanks for hints and suggestions! -- roN
From: David Schwartz on 2 Feb 2010 14:16 On Feb 2, 10:55 am, cerr <ron.egg...(a)gmail.com> wrote: > However, I do not see these packets with Wireshark and neither am I > seeing an error on the shell but i properly see "sent: Hello, World!" > appearing... :( > What's going on here, any clues? You forgot to enable broadcasts. For all the system knows, your program selected a broadcast address accidentally (or worse, was maliciously duped into doing so). Punch 'SO_BROADCAST' into your favorite search engine. DS
From: cerr on 2 Feb 2010 14:38 On Feb 2, 11:16 am, David Schwartz <dav...(a)webmaster.com> wrote: > On Feb 2, 10:55 am, cerr <ron.egg...(a)gmail.com> wrote: > > > However, I do not see these packets with Wireshark and neither am I > > seeing an error on the shell but i properly see "sent: Hello, World!" > > appearing... :( > > What's going on here, any clues? > > You forgot to enable broadcasts. For all the system knows, your > program selected a broadcast address accidentally (or worse, was > maliciously duped into doing so). Punch 'SO_BROADCAST' into your > favorite search engine. > > DS Thanks David, I've done that. Ended up putting follwing after my socket creation: if(setsockopt(BrdcstSock,SOL_SOCKET,SO_BROADCAST,&opt,sizeof(opt))){ cout << "Error setsockopt():" << strerror(errno) << endl; return; } No change tho :( still can't see anything with Wireshark :o (yes, filters are turned off ;) ) Any other ideas?
From: Ersek, Laszlo on 2 Feb 2010 15:05 In article <31074a8e-344d-41a8-a71a-996fe5e7593e(a)y7g2000prc.googlegroups.com>, cerr <ron.eggler(a)gmail.com> writes: > I've done that. Ended up putting follwing after my socket creation: > if(setsockopt(BrdcstSock,SOL_SOCKET,SO_BROADCAST,&opt,sizeof(opt))){ > cout << "Error setsockopt():" << strerror(errno) << endl; > return; > } 1. Did you set "opt" to a nonzero value first? 2. Diagnostics should rather go to stderr or cerr. 3. Do *not* google. Choose a version of the SUS for the project and stick to it. http://www.opengroup.org/onlinepubs/007908775/xns/setsockopt.html http://www.opengroup.org/onlinepubs/000095399/functions/setsockopt.html http://www.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html All of SUSv2, SUSv3, SUSv4 are made available as tarballs. http://www.opengroup.org/onlinepubs/007908775/download/ http://www.opengroup.org/onlinepubs/000095399/download/ http://www.opengroup.org/onlinepubs/9699919799/download/ Extract them onto your hard disk, and index them with one of the many desktop search programs (or write a simple one yourself). Cheers, lacos
From: cerr on 2 Feb 2010 16:18 On Feb 2, 12:05 pm, la...(a)ludens.elte.hu (Ersek, Laszlo) wrote: > In article <31074a8e-344d-41a8-a71a-996fe5e75...(a)y7g2000prc.googlegroups.com>, cerr <ron.egg...(a)gmail.com> writes: > > > I've done that. Ended up putting follwing after my socket creation: > > if(setsockopt(BrdcstSock,SOL_SOCKET,SO_BROADCAST,&opt,sizeof(opt))){ > > cout << "Error setsockopt():" << strerror(errno) << endl; > > return; > > } > > 1. Did you set "opt" to a nonzero value first? Yes, sorry didn't paste that, i have defined opt like: int opt=1; > > 2. Diagnostics should rather go to stderr or cerr. Right, i can change that but would not change anything on the actual problem, eh? > > 3. Do *not* google. Choose a version of the SUS for the project and > stick to it. I actually did look at the man page but also googled for a solution... [snip] > Extract them onto your hard disk, and index them with one of the many > desktop search programs (or write a simple one yourself). Yep, thanks :)
|
Next
|
Last
Pages: 1 2 3 Prev: UDP broadcast Next: Create staple diagrams from a text file (containing numbers)from command line? |