Parent Directory
|
Revision Log
Update copyright info
| 1 | /* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 | /* |
| 3 | * ip_mask |
| 4 | * - IP address mask |
| 5 | * |
| 6 | * Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 | */ |
| 8 | |
| 9 | #ifdef HAVE_CONFIG_H |
| 10 | #include "config.h" |
| 11 | #endif |
| 12 | |
| 13 | #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 |