1/*2* THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.3* You may freely copy it for use as a template for your own field types.4* If you develop a field type that might be of general use, please send5* it back to the ncurses maintainers for inclusion in the next version.6*/7/***************************************************************************8* *9* Author : Per Foreby, [email protected] *10* *11***************************************************************************/1213#include "form.priv.h"1415MODULE_ID("$Id$")1617/*---------------------------------------------------------------------------18| Facility : libnform19| Function : static bool Check_IPV4_Field(20| FIELD * field,21| const void * argp)22|23| Description : Validate buffer content to be a valid IP number (Ver. 4)24|25| Return Values : TRUE - field is valid26| FALSE - field is invalid27+--------------------------------------------------------------------------*/28static bool Check_IPV4_Field(FIELD * field, const void * argp)29{30char *bp = field_buffer(field,0);31int num = 0, len;32unsigned int d1=256, d2=256, d3=256, d4=256;3334argp=0; /* Silence unused parameter warning. */3536if(isdigit((int)(*bp))) /* Must start with digit */37{38num = sscanf(bp, "%u.%u.%u.%u%n", &d1, &d2, &d3, &d4, &len);39if (num == 4)40{41bp += len; /* Make bp point to what sscanf() left */42while (*bp && isspace((int)(*bp)))43bp++; /* Allow trailing whitespace */44}45}46return ((num != 4 || *bp || d1 > 255 || d2 > 25547|| d3 > 255 || d4 > 255) ? FALSE : TRUE);48}4950/*---------------------------------------------------------------------------51| Facility : libnform52| Function : static bool Check_IPV4_Character(53| int c,54| const void *argp )55|56| Description : Check a character for unsigned type or period.57|58| Return Values : TRUE - character is valid59| FALSE - character is invalid60+--------------------------------------------------------------------------*/61static bool Check_IPV4_Character(int c, const void * argp)62{63argp=0; /* Silence unused parameter warning. */64return ((isdigit(c) || (c=='.')) ? TRUE : FALSE);65}6667static FIELDTYPE typeIPV4 = {68_RESIDENT,691, /* this is mutable, so we can't be const */70(FIELDTYPE *)0,71(FIELDTYPE *)0,72NULL,73NULL,74NULL,75Check_IPV4_Field,76Check_IPV4_Character,77NULL,78NULL79};8081FIELDTYPE* TYPE_IPV4 = &typeIPV4;8283/* fty_ipv4.c ends here */848586