/[LeafOK_CVS]/lbbs/src/ip_mask.c
ViewVC logotype

Annotation of /lbbs/src/ip_mask.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Tue Nov 11 00:28:05 2025 UTC (4 months ago) by sysadm
Branch: MAIN
Changes since 1.3: +4 -0 lines
Content type: text/x-csrc
Use config.h

1 sysadm 1.2 /* SPDX-License-Identifier: GPL-3.0-or-later */
2     /*
3     * ip_mask
4     * - IP address mask
5     *
6 sysadm 1.3 * Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com>
7 sysadm 1.2 */
8 sysadm 1.1
9 sysadm 1.4 #ifdef HAVE_CONFIG_H
10     #include "config.h"
11     #endif
12    
13 sysadm 1.1 #include "ip_mask.h"
14     #include <string.h>
15    
16     const char *ip_mask(char *s, int level, char mask)
17     {
18     char *p = s;
19    
20     if (level <= 0)
21     {
22     return s;
23     }
24     if (level > 4)
25     {
26     level = 4;
27     }
28    
29     for (int i = 0; i < 4 - level; i++)
30     {
31     p = strchr(p, '.');
32     if (p == NULL)
33     {
34     return s;
35     }
36     p++;
37     }
38    
39     for (int i = 0; i < level; i++)
40     {
41     *p = mask;
42     p++;
43     if (i < level - 1)
44     {
45     *p = '.';
46     p++;
47     }
48     }
49     *p = '\0';
50    
51     return s;
52     }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1