Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Source/CursesDialog/form/fty_ipv4.c
5017 views
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
16
MODULE_ID("$Id$")
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
+--------------------------------------------------------------------------*/
29
static bool Check_IPV4_Field(FIELD * field, const void * argp)
30
{
31
char *bp = field_buffer(field,0);
32
int num = 0, len;
33
unsigned int d1=256, d2=256, d3=256, d4=256;
34
35
argp=0; /* Silence unused parameter warning. */
36
37
if(isdigit((int)(*bp))) /* Must start with digit */
38
{
39
num = sscanf(bp, "%u.%u.%u.%u%n", &d1, &d2, &d3, &d4, &len);
40
if (num == 4)
41
{
42
bp += len; /* Make bp point to what sscanf() left */
43
while (*bp && isspace((int)(*bp)))
44
bp++; /* Allow trailing whitespace */
45
}
46
}
47
return ((num != 4 || *bp || d1 > 255 || d2 > 255
48
|| d3 > 255 || d4 > 255) ? FALSE : TRUE);
49
}
50
51
/*---------------------------------------------------------------------------
52
| Facility : libnform
53
| Function : static bool Check_IPV4_Character(
54
| int c,
55
| const void *argp )
56
|
57
| Description : Check a character for unsigned type or period.
58
|
59
| Return Values : TRUE - character is valid
60
| FALSE - character is invalid
61
+--------------------------------------------------------------------------*/
62
static bool Check_IPV4_Character(int c, const void * argp)
63
{
64
argp=0; /* Silence unused parameter warning. */
65
return ((isdigit(c) || (c=='.')) ? TRUE : FALSE);
66
}
67
68
static FIELDTYPE typeIPV4 = {
69
_RESIDENT,
70
1, /* this is mutable, so we can't be const */
71
(FIELDTYPE *)0,
72
(FIELDTYPE *)0,
73
NULL,
74
NULL,
75
NULL,
76
Check_IPV4_Field,
77
Check_IPV4_Character,
78
NULL,
79
NULL
80
};
81
82
FIELDTYPE* TYPE_IPV4 = &typeIPV4;
83
84
/* fty_ipv4.c ends here */
85
86