source: trunk/essentials/sys-libs/ncurses/form/fty_ipv4.c@ 3951

Last change on this file since 3951 was 2621, checked in by bird, 20 years ago

GNU ncurses 5.5

File size: 2.8 KB
Line 
1
2/*
3 * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
4 * You may freely copy it for use as a template for your own field types.
5 * If you develop a field type that might be of general use, please send
6 * it back to the ncurses maintainers for inclusion in the next version.
7 */
8/***************************************************************************
9* *
10* Author : Per Foreby, [email protected] *
11* *
12***************************************************************************/
13
14#include "form.priv.h"
15
16MODULE_ID("$Id: fty_ipv4.c,v 1.6 2004/05/29 19:13:48 tom Exp $")
17
18/*---------------------------------------------------------------------------
19| Facility : libnform
20| Function : static bool Check_IPV4_Field(
21| FIELD * field,
22| const void * argp)
23|
24| Description : Validate buffer content to be a valid IP number (Ver. 4)
25|
26| Return Values : TRUE - field is valid
27| FALSE - field is invalid
28+--------------------------------------------------------------------------*/
29static bool
30Check_IPV4_Field(FIELD *field, const void *argp GCC_UNUSED)
31{
32 char *bp = field_buffer(field, 0);
33 int num = 0, len;
34 unsigned int d1, d2, d3, d4;
35
36 if (isdigit(UChar(*bp))) /* Must start with digit */
37 {
38 num = sscanf(bp, "%u.%u.%u.%u%n", &d1, &d2, &d3, &d4, &len);
39 if (num == 4)
40 {
41 bp += len; /* Make bp point to what sscanf() left */
42 while (*bp && isspace(UChar(*bp)))
43 bp++; /* Allow trailing whitespace */