?login_element?

Subversion Repositories NedoOS

Rev

Rev 1577 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <oscalls.h>
  4. #include <socket.h>
  5. #include <intrz80.h>
  6. #include <stdlib.h>
  7.  
  8. unsigned char ipadress[] = "\0\0\0\0\0";
  9. unsigned char *p;
  10. const unsigned char help[] = "View and set system DNS server\r\nUsage: dns.com [ip-adress]\r\n\0";
  11.  
  12. void errorip(void)
  13. {
  14.         printf("Error parsing IP adress\r\n");
  15.         exit(0);
  16. }
  17. int pos(unsigned char *s, unsigned char *c, unsigned int n, unsigned int startPos)
  18. {
  19.         unsigned int i, j;
  20.         unsigned int lenC, lenS;
  21.  
  22.         for (lenC = 0; c[lenC]; lenC++)
  23.                 ;
  24.         for (lenS = 0; s[lenS]; lenS++)
  25.                 ;
  26.         for (i = startPos; i <= lenS - lenC; i++)
  27.         {
  28.                 for (j = 0; s[i + j] == c[j]; j++)
  29.                         ;
  30.                 if (j - lenC == 1 && i == lenS - lenC && !(n - 1))
  31.                         return i;
  32.                 if (j == lenC)
  33.                         if (n - 1)
  34.                                 n--;
  35.                         else
  36.                                 return i;
  37.         }
  38.         return -1;
  39. }
  40.  
  41. void get_dns(void)
  42. {
  43.         os_getdns(ipadress);
  44.         printf("%d", ipadress[0]);
  45.         printf(".");
  46.         printf("%d", ipadress[1]);
  47.         printf(".");
  48.         printf("%d", ipadress[2]);
  49.         printf(".");
  50.         printf("%d", ipadress[3]);
  51.         printf("\r\n");
  52. }
  53.  
  54. void setdns(void)
  55. {
  56.         int n = -1, nold, test;
  57.         unsigned char counter, counter2;
  58.         unsigned char coma[] = ".";
  59.         unsigned char buf[16];
  60.         unsigned char p2[255];
  61.         p2[0] = '\0';
  62.         strcat(p2, p);
  63.         strcat(p2, coma);
  64.         for (counter = 0; counter < 4; counter++)
  65.         {
  66.                 nold = n;
  67.                 n = pos(p2, coma, counter + 1, 0);
  68.                 if (n == -1)
  69.                 {
  70.                         errorip();
  71.                 }
  72.                 for (counter2 = 0; counter2 < (n - nold - 1); counter2++)
  73.                 {
  74.                         buf[counter2] = p[counter2 + nold + 1];
  75.                 }
  76.                 buf[counter2] = '\0';
  77.                 test = atoi(buf);
  78.                 if (test > 255)
  79.                 {
  80.                         errorip();
  81.                 }
  82.                 ipadress[counter] = atoi(buf);
  83.         }
  84.         os_setdns(ipadress);
  85. }
  86.  
  87. C_task main(int argc, char *argv[])
  88. {
  89.         os_initstdio();
  90.  
  91.         if (argc == 1)
  92.         {
  93.                 puts(help);
  94.                 printf("Current DNS-server: ");
  95.                 get_dns();
  96.                 exit(0);
  97.         }
  98.  
  99.         if (argc == 2)
  100.         {
  101.                 p = argv[1];
  102.                 setdns();
  103.                 printf("Current DNS-server: ");
  104.                 get_dns();
  105.                 exit(0);
  106.         }
  107.         errorip();
  108.         //      return 0;
  109. }
  110.