/[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.3 - (hide annotations)
Tue Nov 4 14:58:56 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.2: +1 -1 lines
Content type: text/x-csrc
Refine file header information comments

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     #include "ip_mask.h"
10     #include <string.h>
11    
12     const char *ip_mask(char *s, int level, char mask)
13     {
14     char *p = s;
15    
16     if (level <= 0)
17     {
18     return s;
19     }
20     if (level > 4)
21     {
22     level = 4;
23     }
24    
25     for (int i = 0; i < 4 - level; i++)
26     {
27     p = strchr(p, '.');
28     if (p == NULL)
29     {
30     return s;
31     }
32     p++;
33     }
34    
35     for (int i = 0; i < level; i++)
36     {
37     *p = mask;
38     p++;
39     if (i < level - 1)
40     {
41     *p = '.';
42     p++;
43     }
44     }
45     *p = '\0';
46    
47     return s;
48     }

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