๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #7341

Re: Hacer un broadcast en C

#7341
From: Pascal Bourguignon
Date: Sun, 09 Mar 2003 01:41
39 lines
2158 bytes
"Mario de Sousa Dias" <mario_d@clix.pt> writes:

> Hello everyone....
> 
> I would like to know how to write very simple client program in C using
> sockets that tries to find out in which machine the server is. This is done
> using a broadcast (the server is on the same LAN).
> 
> I know that I must use setsockopt().

How do you know that?

% man setsockopt|grep -i broad ; echo $?
1

Sending a broadcast is just using an address with a host part all 1's.

So  if  you're interface  address  is  my_addr,  and your  netmask  is
my_mask, then you can build the broadcast address with:

    int my_broadcast = (my_addr & my_mask) | ( -1 & ( ~ my_mask ))

and use this as IP address.

Check inet(3) too.

And  if  you have  FreeS/WAN  installed,  you  may use  their  library
function ipsec_broadcastof(3).

> WHEN responding to the client, The server must include it's ๏ฟฝlevel๏ฟฝ. If
> possible I'd also like to know how to implement the server code...
> 
> Thank you...


-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
There is a fault in reality. Do not adjust your minds. -- Salman Rushdie
Technical Details
Message-ID: <878yvpxqmz.fsf@thalassa.informatimago.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!213.220.35.225!not-for-mail
References: <Yr0aa.4487$7_7.2683996@newsserver.ip.pt>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f86c8,853062bed1b51a53
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-03-08 17:42:00 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!213.220.35.225!not-for-mail
From: Pascal Bourguignon <pjb@informatimago.com>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Hacer un broadcast en C
Date: 09 Mar 2003 02:41:56 +0100
Organization: informatimago.com
Lines: 39
Sender: pascal@thalassa.informatimago.com
Message-ID: <878yvpxqmz.fsf@thalassa.informatimago.com>
References: <Yr0aa.4487$7_7.2683996@newsserver.ip.pt>
NNTP-Posting-Host: 213.220.35.225
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: fu-berlin.de 1047174118 65766260 213.220.35.225 (16 [41911])
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50