summaryrefslogtreecommitdiff
path: root/src/server_check.c
blob: 94069cc9553cf8cf567e6461985148c514e534b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * active port forwarder - software for secure forwarding
 * Copyright (C) 2003,2004,2005 jeremian <jeremian [at] poczta.fm>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#include "stats.h"

void
check_value(int* where, char* what, char* info)
{
  char* znak;
  long tmp;
  if ((tmp = strtol(what, &znak, 10)) >= INT_MAX) {
    aflog(0, "%s: %s\n", info, what);
    exit(1);
  }
  if (((*what) == '\0') || (*znak != '\0')) {
    aflog(0, "%s: %s\n", info, what);
    exit(1);
  }
  if (tmp <= 0) {
    aflog(0, "%s: %d\n", info, *where);
    exit(1);
  }
  (*where) = tmp;
}

int
check_long(char* text, long* number)
{
  char* tmp;
  if (((*number = strtol(text, &tmp, 10)) == LONG_MAX) || (*number == LONG_MIN)) {
    return 1;
  }
  if ((*text != '\0') && (*tmp == '\0')) {
    return 0;
  }
  else {
    return 2;
  }
}