GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libform/fty_ipv4.c Lines: 0 12 0.0 %
Date: 2017-11-07 Branches: 0 10 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: fty_ipv4.c,v 1.7 2015/01/23 22:48:51 krw Exp $	*/
2
/****************************************************************************
3
 * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc.              *
4
 *                                                                          *
5
 * Permission is hereby granted, free of charge, to any person obtaining a  *
6
 * copy of this software and associated documentation files (the            *
7
 * "Software"), to deal in the Software without restriction, including      *
8
 * without limitation the rights to use, copy, modify, merge, publish,      *
9
 * distribute, distribute with modifications, sublicense, and/or sell       *
10
 * copies of the Software, and to permit persons to whom the Software is    *
11
 * furnished to do so, subject to the following conditions:                 *
12
 *                                                                          *
13
 * The above copyright notice and this permission notice shall be included  *
14
 * in all copies or substantial portions of the Software.                   *
15
 *                                                                          *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19
 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23
 *                                                                          *
24
 * Except as contained in this notice, the name(s) of the above copyright   *
25
 * holders shall not be used in advertising or otherwise to promote the     *
26
 * sale, use or other dealings in this Software without prior written       *
27
 * authorization.                                                           *
28
 ****************************************************************************/
29
30
/***************************************************************************
31
*                                                                          *
32
*  Author : Per Foreby, perf@efd.lth.se                                    *
33
*                                                                          *
34
***************************************************************************/
35
36
#include "form.priv.h"
37
38
MODULE_ID("$Id: fty_ipv4.c,v 1.7 2015/01/23 22:48:51 krw Exp $")
39
40
/*---------------------------------------------------------------------------
41
|   Facility      :  libnform
42
|   Function      :  static bool Check_IPV4_Field(
43
|                                      FIELD * field,
44
|                                      const void * argp)
45
|
46
|   Description   :  Validate buffer content to be a valid IP number (Ver. 4)
47
|
48
|   Return Values :  TRUE  - field is valid
49
|                    FALSE - field is invalid
50
+--------------------------------------------------------------------------*/
51
static bool
52
Check_IPV4_Field(FIELD *field, const void *argp GCC_UNUSED)
53
{
54
  char *bp = field_buffer(field, 0);
55
  int num = 0, len;
56
  unsigned int d1, d2, d3, d4;
57
58
  if (isdigit(UChar(*bp)))	/* Must start with digit */
59
    {
60
      num = sscanf(bp, "%u.%u.%u.%u%n", &d1, &d2, &d3, &d4, &len);
61
      if (num == 4)
62
	{
63
	  bp += len;		/* Make bp point to what sscanf() left */
64
	  while (isspace(UChar(*bp)))
65
	    bp++;		/* Allow trailing whitespace */
66
	}
67
    }
68
  return ((num != 4 || *bp || d1 > 255 || d2 > 255
69
	   || d3 > 255 || d4 > 255) ? FALSE : TRUE);
70
}
71
72
/*---------------------------------------------------------------------------
73
|   Facility      :  libnform
74
|   Function      :  static bool Check_IPV4_Character(
75
|                                      int c,
76
|                                      const void *argp )
77
|
78
|   Description   :  Check a character for unsigned type or period.
79
|
80
|   Return Values :  TRUE  - character is valid
81
|                    FALSE - character is invalid
82
+--------------------------------------------------------------------------*/
83
static bool
84
Check_IPV4_Character(int c, const void *argp GCC_UNUSED)
85
{
86
  return ((isdigit(UChar(c)) || (c == '.')) ? TRUE : FALSE);
87
}
88
89
static FIELDTYPE typeIPV4 =
90
{
91
  _RESIDENT,
92
  1,				/* this is mutable, so we can't be const */
93
  (FIELDTYPE *)0,
94
  (FIELDTYPE *)0,
95
  NULL,
96
  NULL,
97
  NULL,
98
  Check_IPV4_Field,
99
  Check_IPV4_Character,
100
  NULL,
101
  NULL
102
};
103
104
NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_IPV4 = &typeIPV4;
105
106
/* fty_ipv4.c ends here */