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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/* +------------------------------------+
* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
* Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
* E-mail:
* <brain@chatspike.net>
* <Craig@chatspike.net>
*
* Written by Craig Edwards, Craig McLure, and others.
* This program is free but copyrighted software; see
* the file COPYING for details.
*
* ---------------------------------------------------
*/
using namespace std;
#include "inspircd.h"
#include "inspircd_io.h"
#include "inspircd_util.h"
#include "inspstring.h"
#include "helperfuncs.h"
extern time_t TIME;
char *SafeStrncpy (char *dest, const char *src, size_t size)
{
if (!dest)
{
dest = NULL;
return (NULL);
}
else if (size < 1)
{
dest = NULL;
return (NULL);
}
memset (dest, '\0', size);
strlcpy (dest, src, size - 1);
return (dest);
}
char *CleanIpAddr (char *cleanAddr, const char *dirtyAddr)
{
int count = 0, maxdot = 0, maxoctet = 0;
memset (cleanAddr, '\0', MAXBUF);
if(dirtyAddr == NULL)
return(cleanAddr);
for (count = 0; count < MAXBUF - 1; count++)
{
if (isdigit (dirtyAddr[count]))
{
if (++maxoctet > 3)
{
cleanAddr[count] = '\0';
break;
}
cleanAddr[count] = dirtyAddr[count];
}
else if (dirtyAddr[count] == '.')
{
if (++maxdot > 3)
{
cleanAddr[count] = '\0';
break;
}
maxoctet = 0;
cleanAddr[count] = dirtyAddr[count];
}
else
{
cleanAddr[count] = '\0';
break;
}
}
return (cleanAddr);
}
char* CleanFilename(char* name)
{
char* p = name + strlen(name);
while ((p != name) && (*p != '/'))
p--;
if ( p != name)
{
return ++p;
}
else
{
return p;
}
}
|