Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

program that broadcasts

Status
Not open for further replies.

Themuppeteer

Programmer
Apr 4, 2001
449
BE
I wanna write a progra mthat broadcass a message over the network.But I'm having a problems...

I'm using udp
and my "sockaddr_in" var is build like this:

struct sockaddr_in to;
to.sin_family = AF_INET;
to.sin_addr.s_addr= inet_addr("255.255.255.255");
to.sin_port=htons(9000);
cout<<sendto(sockfd,buffer,strlen(buffer),0,
(struct sockaddr*)(&to),sizeof(sockaddr_in))<<endl;
close(sockfd);

(With sockfd being initialized well)
When I take IP 255.255.255.255 sendto returns -1,but when
I take somthing else 127.0.0.1 (works )or 150.158.x.y (works with certain ip's)

Can anyone explain please? And especially how to broadcast ?
(and to accept a broadcast)

thnx a lot!


Belgium 2 - Japan 0 !! X-) Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
hi ,
u have to use setsockopt (),
one of the option is BROADCAST
that will solve ur problem.
ashish
 
Thnx a lot !
I'd give you a star,but you're not a member... (might be a good time to become one X-)) Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top