/[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.1 - (hide annotations)
Wed Jul 23 01:16:28 2025 UTC (7 months, 3 weeks ago) by sysadm
Branch: MAIN
Content type: text/x-csrc
Move ip_mask() to dedicated ip_mask.c(.h) files

1 sysadm 1.1 /***************************************************************************
2     ip_mask.c - description
3     -------------------
4     Copyright : (C) 2004-2025 by Leaflet
5     Email : leaflet@leafok.com
6     ***************************************************************************/
7    
8     /***************************************************************************
9     * *
10     * This program is free software; you can redistribute it and/or modify *
11     * it under the terms of the GNU General Public License as published by *
12     * the Free Software Foundation; either version 3 of the License, or *
13     * (at your option) any later version. *
14     * *
15     ***************************************************************************/
16    
17     #include "ip_mask.h"
18     #include <string.h>
19    
20     const char *ip_mask(char *s, int level, char mask)
21     {
22     char *p = s;
23    
24     if (level <= 0)
25     {
26     return s;
27     }
28     if (level > 4)
29     {
30     level = 4;
31     }
32    
33     for (int i = 0; i < 4 - level; i++)
34     {
35     p = strchr(p, '.');
36     if (p == NULL)
37     {
38     return s;
39     }
40     p++;
41     }
42    
43     for (int i = 0; i < level; i++)
44     {
45     *p = mask;
46     p++;
47     if (i < level - 1)
48     {
49     *p = '.';
50     p++;
51     }
52     }
53     *p = '\0';
54    
55     return s;
56     }

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