Mildly exotic socket related system call problem - anyone help?

Chris Torek chris at umcp-cs.UUCP
Mon May 26 17:31:12 AEST 1986


In article <189 at comp.lancs.ac.uk> david at comp.lancs.ac.uk
(David Coffield) writes:
>... I need to get a machine address from the user e.g. "150.0.0.11"
>(in that format, as a string) and compare the network number of that
>address with the network number of the address of the machine on
>which the program is executing.

I would suggest using `inet_addr()' and then `inet_netof()', but:

>Now about a year ago I discovered that "inet_addr" caused core dumps
>every time you called it ...

I presume you have declared them and used them like so:

	u_long inet_addr();
	int inet_netof();	/* assumes int holds >= 24 bits, but... */
	int net;
	struct in_addr t;

	t.s_addr = inet_addr(string);
	net = inet_netof(t);

>So, questions as follows:
>1. Can anyone suggest a way round this problem?

Well, you can simply run atoi() on the first number to discover
whether the network is class A (< 128), B (128 to 191), or C
(>= 192).  If B, you need the next number; if C, the next two.
You then have the network.  Apply the same procedure to the
local address, and compare the strings.

>2. Does 4.3 have fixed "inet*" routines??

Yes.

>3. If so can anyone mail me a copy of working ones???

Hrum.

>4. Was 3. an illegal question????

Probably.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.unix.wizards mailing list