]> git.sur5r.net Git - ngadmin/blob - raw/src/misc.c
Move basic networking code to raw library
[ngadmin] / raw / src / misc.c
1
2 #include <stdlib.h>
3
4 #include <nsdp/misc.h>
5
6
7 static const char passwordKey[] = "NtgrSmartSwitchRock";
8
9
10 void passwordEndecode (char *buf, unsigned int len)
11 {
12         const char *k = passwordKey;
13         unsigned int i;
14         
15         if (buf == NULL || len <= 0)
16                 return;
17         
18         for (i = 0; i < len; i++) {
19                 if (*k == '\0')
20                         k = passwordKey;
21                 buf[i] ^= *k++;
22         }
23 }
24
25
26 int trim (char *txt, int start)
27 {
28         char *p;
29         
30         if (txt == NULL)
31                 return 0;
32         
33         p = txt + start;
34         while (p >= txt && (*p == ' ' || *p == '\n')) {
35                 *p = '\0';
36                 p--;
37         }
38         
39         return p - txt + 1;
40 }
41
42