/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Common (shared) routines used by in.routed daemon and the
* the rtquery utility program
*/
#include "defs.h"
#include <ctype.h>
/* Return the classical netmask for an IP address. */
in_addr_t /* host byte order */
{
if (addr == 0) /* default route has mask 0 */
return (0);
return (IN_CLASSA_NET);
return (IN_CLASSB_NET);
return (IN_CLASSC_NET);
return (IN_CLASSE_NET);
}
/*
* Get a network number as a name or a number, with an optional "/xx"
* netmask.
*/
boolean_t /* 0=bad */
{
int i;
char *mname, *p;
/*
* The "name" argument of this function can be one of
* the follwoing:
* b) network name
* d) network number
* f) host IP address
* g) "default"
*
* Detect and separate "1.2.3.4/24"
*/
return (_B_FALSE);
hname[i] = '\0';
mname++;
}
else
return (_B_FALSE);
}
/* Left-align the host-byte-order result from above. */
} else {
return (_B_FALSE);
if (mask != 0)
}
/* must have mask of 0 with default */
return (_B_FALSE);
/* no host bits allowed in a network number */
return (_B_FALSE);
/* require non-zero network number */
return (_B_FALSE);
return (_B_FALSE);
return (_B_FALSE);
return (_B_TRUE);
}
/*
* Convert string to printable characters
*/
char *
{
/*
* Authentication schemes for RIPv2 uses the space of an
* 20-octet route entry.
*/
uchar_t c;
len--;
c = *srcp++;
if (isprint(c) && c != '\\') {
*prcp++ = c;
continue;
}
*prcp++ = '\\';
else
}
*prcp = '\0';
return (buf);
}
/* like strtok(), but honoring backslash and not changing the source string */
int /* 0=ok, -1=bad */
const char *delims, /* for these delimiters */
char *delimp, /* 0 or put found delimiter here */
char *buf, /* copy token to here */
int lim) /* at most this many bytes */
{
const char *p;
if (*pc == '\0')
return (-1);
while (lim != 0) {
c = *pc++;
if (c == '\0')
break;
c = *pc++;
switch (c) {
case 'n':
c = '\n';
break;
case 'r':
c = '\r';
break;
case 't':
c = '\t';
break;
case 'b':
c = '\b';
}
if (c >= '0' && c <= '7') {
c -= '0';
}
}
} else {
for (p = delims; *p != '\0'; ++p) {
if (*p == c || isspace(c) && *p == ' ')
goto exit;
}
}
*buf++ = c;
--lim;
}
exit:
if (lim == 0)
return (-1);
*delimp = c; /* return delimiter */
return (0);
}
/*
* Find the option buffer in the msg corresponding to cmsg_type.
*/
void *
{
}
}
return (NULL);
}