david@comp.lancs.ac.uk (David Coffield) (05/25/86)
I can never understand people that post incomplete firs
(Bit of humour there).
The problem is this:
in the midst of using sockets 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.
Should be simple ...
Now about a year ago I discovered that "inet_addr" caused core dumps
every time you called it - so I abandoned it's use and got round the
problem. For what I want to do now I should use its stablemate (RED alert)
"inet_network" but heaven knows what that one's returning.
("inet_ntof" returns the wrong answer but at least it does it
consistently).
So, questions as follows:
1. Can anyone suggest a way round this problem?
2. Does 4.3 have fixed "inet*" routines??
3. If so can anyone mail me a copy of working ones???
4. Was 3. an illegal question????
The aim of the exercise is merely to validate user input -
if I can't get round it I'll just have to accept possibly ropey input.
Any help much appreciated.
David
--
uucp: ...!mcvax!ukc!dcl-cs!david post: Department of Computing
arpa: david%lancs.comp@ucl.cs University of Lancaster, UK
janet: david@uk.ac.lancs.comp phone: +44 524 65201 x 4599chris@umcp-cs.UUCP (Chris Torek) (05/26/86)
In article <189@comp.lancs.ac.uk> david@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@umcp-cs ARPA: chris@mimsy.umd.edu