Return to BSD News archive
Newsgroups: comp.unix.bsd
Path: sserve!manuel!munnari.oz.au!mips!mips!sdd.hp.com!usc!sol.ctr.columbia.edu!ira.uka.de!rz.uni-karlsruhe.de!stepsun.uni-kl.de!uklirb!posthorn!acht!sturm
From: sturm@acht.informatik.uni-kl.de (Peter Sturm)
Subject: I need the netmask within a process?
Message-ID: <sturm.714660382@acht>
Keywords: netmask
Sender: news@posthorn.informatik.uni-kl.de (News system account)
Nntp-Posting-Host: acht.informatik.uni-kl.de
Organization: University of Kaiserslautern, Germany
Date: Mon, 24 Aug 1992 12:46:22 GMT
Lines: 38
Hello!
Does anybody know how i can access the machine's netmask within a process?
The problem is, that i've written a demo program doing broadcast on
datagram sockets. For this purpose, a correct sockaddr_in structure has to
build for the receiving processes:
struct sockaddr_in consumers;
bzero(&consumers,sizeof consumers);
consumers.sin_family = AF_INET;
consumers.sin_addr.s_addr = X;
consumers.sin_port = htons(SOME_PORT_NUMBER);
where X is constructed out of the machine's ip number and the network mask:
X = ip_number & netmask | 0xffffffff & ~netmask
If i use a hand-coded netmask (0xffffff00 on our network), the program
works fine. But how can i retrieve this netmask using ordinary system calls
or library calls?
On a SUN workstation, there's a include file in_var.h at /usr/include/netinet
which contains the declaration of a structure in_ifaddr. This structure seems
to have a field describing the netmask, but i have no idea how to obtain
such a structure with useful content.
Any suggestions are welcome,
Peter Sturm
-----------------------------------------------------------------------------
Peter Sturm Tel. 0631/205-3288
University of Kaiserslautern Fax. 0631/205-3558
Computer Science Department
P.O. Box 3049
6750 Kaiserslautern Email: sturm@informatik.uni-kl.de
Germany
-----------------------------------------------------------------------------