summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_frame_relay.c
diff options
context:
space:
mode:
authorarchie <archie@FreeBSD.org>1999-11-02 23:18:01 +0000
committerarchie <archie@FreeBSD.org>1999-11-02 23:18:01 +0000
commita481e1e52bd7ec5a593408ac4a14285997f6d2b9 (patch)
tree933dc4cbd306643fb4cfaef4087fa80525fd8420 /sys/netgraph/ng_frame_relay.c
parent379a856804bca45181540d407b067f13b50206fa (diff)
downloadFreeBSD-src-a481e1e52bd7ec5a593408ac4a14285997f6d2b9.zip
FreeBSD-src-a481e1e52bd7ec5a593408ac4a14285997f6d2b9.tar.gz
Simplify checking/parsing of strings using strtoul(), isdigit(), etc.
Diffstat (limited to 'sys/netgraph/ng_frame_relay.c')
-rw-r--r--sys/netgraph/ng_frame_relay.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/sys/netgraph/ng_frame_relay.c b/sys/netgraph/ng_frame_relay.c
index a0466d0..6be8d17 100644
--- a/sys/netgraph/ng_frame_relay.c
+++ b/sys/netgraph/ng_frame_relay.c
@@ -246,9 +246,7 @@ static int
ngfrm_newhook(node_p node, hook_p hook, const char *name)
{
const sc_p sc = node->private;
- const char *cp;
- char c = '\0';
- int digits = 0;
+ const char *cp, *eptr;
int dlci = 0;
int ctxnum;
@@ -285,13 +283,12 @@ ngfrm_newhook(node_p node, hook_p hook, const char *name)
/* Must be a dlci hook at this point */
cp = name + strlen(NG_FRAMERELAY_HOOK_DLCI);
- while ((digits < 5) && ((c = *cp++) >= '0') && (c <= '9')) {
- dlci *= 10;
- dlci += c - '0';
- digits++;
- }
- if ((c != 0) || (digits == 5) || (dlci < 0) || (dlci > 1023))
+ if (!isdigit(*cp) || (cp[0] == '0' && cp[1] != '\0'))
+ return (EINVAL);
+ dlci = (int)strtoul(cp, &eptr, 10);
+ if (*eptr != '\0' || dlci < 0 || dlci > 1023)
return (EINVAL);
+
/*
* We have a dlci, now either find it, or allocate it. It's possible
* that we might have seen packets for it already and made an entry
OpenPOWER on IntegriCloud