🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4095

Re: UDP Broadcast

#4095
From: Bob Gonder
Date: Mon, 04 Apr 2005 16:31
24 lines
1880 bytes
Adam Griffin wrote:

>I need to broadcast a udp packet across my lan.  I get an invalid ip address 
>error when trying to with INADDR_ANY.  I can successfully call sendto if I 

INADDR_ANY, as the name implies, is for INput, or receiving a
broadcast. The Output address is

#define	UDP_GROUP	"255.255.255.255"
#define	UDP_PORT	12345 /*whatever you want to use*/

	SendSocket=socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP )) )
	/* turn on broadcast */
	t = TRUE;

setsockopt(SendSocket,SOL_SOCKET,SO_BROADCAST,(char*)&t,sizeof(t));
	/* set up destination address */
	memset( &SendAddr, 0, sizeof(SendAddr) );
	SendAddr.sin_family = AF_INET;
	SendAddr.sin_addr.s_addr = inet_addr( UDP_GROUP );
	SendAddr.sin_port = htons( UDP_PORT );
	/* now just sendto() our destination! */
	sendto( SendSocket, DataGram, sizeof(DataGram), 0,
		(struct sockaddr *) &SendAddr, sizeof(SendAddr) );
Technical Details
Message-ID: <feq251he7i11r2aee4bm4gobb18du0k09k@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <42515683@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,43dff4bcc440abe1
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: UDP Broadcast
Date: Mon, 04 Apr 2005 09:31:59 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <feq251he7i11r2aee4bm4gobb18du0k09k@4ax.com>
References: <42515683@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.77.144.88
X-Trace: newsgroups.borland.com 1112632317 67.77.144.88 (4 Apr 2005 09:31:57 -0800)
Lines: 26
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail