2007-01-20 07:32:02 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. *
|
|
|
|
* *
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
|
|
|
* copy of this software and associated documentation files (the *
|
|
|
|
* "Software"), to deal in the Software without restriction, including *
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish, *
|
|
|
|
* distribute, distribute with modifications, sublicense, and/or sell *
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is *
|
|
|
|
* furnished to do so, subject to the following conditions: *
|
|
|
|
* *
|
|
|
|
* The above copyright notice and this permission notice shall be included *
|
|
|
|
* in all copies or substantial portions of the Software. *
|
|
|
|
* *
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
|
|
|
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
|
|
* *
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright *
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the *
|
|
|
|
* sale, use or other dealings in this Software without prior written *
|
|
|
|
* authorization. *
|
|
|
|
****************************************************************************/
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* Author : Per Foreby, perf@efd.lth.se *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "form.priv.h"
|
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
MODULE_ID("$Id: fty_ipv4.c,v 1.8 2006/12/02 19:33:02 tom Exp $")
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
| Facility : libnform
|
|
|
|
| Function : static bool Check_IPV4_Field(
|
|
|
|
| FIELD * field,
|
|
|
|
| const void * argp)
|
|
|
|
|
|
|
|
|
| Description : Validate buffer content to be a valid IP number (Ver. 4)
|
|
|
|
|
|
|
|
|
| Return Values : TRUE - field is valid
|
|
|
|
| FALSE - field is invalid
|
|
|
|
+--------------------------------------------------------------------------*/
|
2007-01-20 07:32:02 +00:00
|
|
|
static bool
|
|
|
|
Check_IPV4_Field(FIELD *field, const void *argp GCC_UNUSED)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2007-01-20 07:32:02 +00:00
|
|
|
char *bp = field_buffer(field, 0);
|
1999-08-24 01:06:48 +00:00
|
|
|
int num = 0, len;
|
|
|
|
unsigned int d1, d2, d3, d4;
|
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
if (isdigit(UChar(*bp))) /* Must start with digit */
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
|
|
|
num = sscanf(bp, "%u.%u.%u.%u%n", &d1, &d2, &d3, &d4, &len);
|
|
|
|
if (num == 4)
|
2007-01-20 07:32:02 +00:00
|
|
|
{
|
|
|
|
bp += len; /* Make bp point to what sscanf() left */
|
|
|
|
while (isspace(UChar(*bp)))
|
|
|
|
bp++; /* Allow trailing whitespace */
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
return ((num != 4 || *bp || d1 > 255 || d2 > 255
|
2007-01-20 07:32:02 +00:00
|
|
|
|| d3 > 255 || d4 > 255) ? FALSE : TRUE);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
| Facility : libnform
|
|
|
|
| Function : static bool Check_IPV4_Character(
|
|
|
|
| int c,
|
|
|
|
| const void *argp )
|
|
|
|
|
|
|
|
|
| Description : Check a character for unsigned type or period.
|
|
|
|
|
|
|
|
|
| Return Values : TRUE - character is valid
|
|
|
|
| FALSE - character is invalid
|
|
|
|
+--------------------------------------------------------------------------*/
|
2007-01-20 07:32:02 +00:00
|
|
|
static bool
|
|
|
|
Check_IPV4_Character(int c, const void *argp GCC_UNUSED)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2007-01-20 07:32:02 +00:00
|
|
|
return ((isdigit(UChar(c)) || (c == '.')) ? TRUE : FALSE);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
static FIELDTYPE typeIPV4 =
|
|
|
|
{
|
1999-08-24 01:06:48 +00:00
|
|
|
_RESIDENT,
|
2007-01-20 07:32:02 +00:00
|
|
|
1, /* this is mutable, so we can't be const */
|
1999-08-24 01:06:48 +00:00
|
|
|
(FIELDTYPE *)0,
|
|
|
|
(FIELDTYPE *)0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
Check_IPV4_Field,
|
|
|
|
Check_IPV4_Character,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2001-05-17 08:21:06 +00:00
|
|
|
NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_IPV4 = &typeIPV4;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
/* fty_ipv4.c ends here */
|