Cross Reference: inet_network.c
xref
: /
osnet-11
/
usr
/
src
/
lib
/
libresolv2
/
common
/
inet
/
inet_network.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
2
N/A
/*
2
N/A
* Copyright (c) 1983, 1993
2
N/A
* The Regents of the University of California. All rights reserved.
2
N/A
*
2
N/A
* Redistribution and use in source and binary forms, with or without
2
N/A
* modification, are permitted provided that the following conditions
2
N/A
* are met:
2
N/A
* 1. Redistributions of source code must retain the above copyright
2
N/A
* notice, this list of conditions and the following disclaimer.
2
N/A
* 2. Redistributions in binary form must reproduce the above copyright
2
N/A
* notice, this list of conditions and the following disclaimer in the
2
N/A
* documentation
and
/
or
other materials provided with the distribution.
2
N/A
* 3. All advertising materials mentioning features or use of this software
2
N/A
* must display the following acknowledgement:
2
N/A
* This product includes software developed by the University of
2
N/A
* California, Berkeley and its contributors.
2
N/A
* 4. Neither the name of the University nor the names of its contributors
2
N/A
* may be used to endorse or promote products derived from this software
2
N/A
* without specific prior written permission.
2
N/A
*
2
N/A
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2
N/A
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2
N/A
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2
N/A
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2
N/A
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2
N/A
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2
N/A
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2
N/A
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2
N/A
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2
N/A
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2
N/A
* SUCH DAMAGE.
2
N/A
*/
2
N/A
2
N/A
#
if
defined
(
LIBC_SCCS
) && !
defined
(
lint
)
2
N/A
static
const
char
sccsid
[] =
"@(#)
inet_network.c
8.1 (Berkeley) 6/4/93"
;
2
N/A
#
endif
/* LIBC_SCCS and not lint */
2
N/A
2
N/A
#
include
"
port_before.h
"
2
N/A
2
N/A
#
include
<
sys
/
types.h
>
2
N/A
#
include
<
netinet
/
in.h
>
2
N/A
#
include
<
arpa
/
inet.h
>
2
N/A
#
include
<
ctype.h
>
2
N/A
2
N/A
#
include
"
port_after.h
"
2
N/A
2
N/A
/*%
2
N/A
* Internet network address interpretation routine.
2
N/A
* The library routines call this routine to interpret
2
N/A
* network numbers.
2
N/A
*/
2
N/A
u_long
2
N/A
inet_network
(
cp
)
2
N/A
register
const
char
*
cp
;
2
N/A
{
2
N/A
register
u_long
val
,
base
, n, i;
2
N/A
register
char
c;
2
N/A
u_long
parts
[
4
], *
pp
=
parts
;
2
N/A
int
digit
;
2
N/A
2
N/A
again
:
2
N/A
val
= 0;
base
=
10
;
digit
= 0;
2
N/A
if
(*
cp
==
'0'
)
2
N/A
digit
=
1
,
base
=
8
,
cp
++;
2
N/A
if
(*
cp
==
'x'
|| *
cp
==
'X'
)
2
N/A
base
=
16
,
cp
++;
2
N/A
while
((c = *
cp
) != 0) {
2
N/A
if
(
isdigit
((
unsigned
char
)c)) {
2
N/A
if
(
base
==
8U
&& (c ==
'8'
|| c ==
'9'
))
2
N/A
return
(
INADDR_NONE
);
2
N/A
val
= (
val
*
base
) + (c -
'0'
);
2
N/A
cp
++;
2
N/A
digit
=
1
;
2
N/A
continue
;
2
N/A
}
2
N/A
if
(
base
==
16U
&&
isxdigit
((
unsigned
char
)c)) {
2
N/A
val
= (
val
<<
4
) +
2
N/A
(c +
10
- (
islower
((
unsigned
char
)c) ?
'a'
:
'A'
));
2
N/A
cp
++;
2
N/A
digit
=
1
;
2
N/A
continue
;
2
N/A
}
2
N/A
break
;
2
N/A
}
2
N/A
if
(!
digit
)
2
N/A
return
(
INADDR_NONE
);
2
N/A
if
(
pp
>=
parts
+
4
||
val
>
0xffU
)
2
N/A
return
(
INADDR_NONE
);
2
N/A
if
(*
cp
==
'.'
) {
2
N/A
*
pp
++ =
val
,
cp
++;
2
N/A
goto
again
;
2
N/A
}
2
N/A
if
(*
cp
&& !
isspace
(*
cp
&
0xff
))
2
N/A
return
(
INADDR_NONE
);
2
N/A
*
pp
++ =
val
;
2
N/A
n =
pp
-
parts
;
2
N/A
if
(n >
4U
)
2
N/A
return
(
INADDR_NONE
);
2
N/A
for
(
val
= 0, i = 0; i < n; i++) {
2
N/A
val
<<=
8
;
2
N/A
val
|=
parts
[i] &
0xff
;
2
N/A
}
2
N/A
return
(
val
);
2
N/A
}
2
N/A
2
N/A
/*! \file */