⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 root.c

📁 TM1300/PNX1300系列DSP(主要用于视频处理)操作系统pSOS系统的几个demo
💻 C
字号:
/*
 *+-------------------------------------------------------------------+
 *| Copyright (c) 1999,2000 TriMedia Technologies Inc.                |
 *|                                                                   |
 *| This software  is furnished under a license  and may only be used |
 *| and copied in accordance with the terms  and conditions of such a |
 *| license  and with  the inclusion of this  copyright notice.  This |
 *| software or any other copies of this software may not be provided |
 *| or otherwise  made available  to any other person.  The ownership |
 *| and title of this software is not transferred.                    |
 *|                                                                   |
 *| The information  in this software  is subject  to change  without |
 *| any  prior notice  and should not be construed as a commitment by |
 *| TriMedia Technologies.                                            |
 *|                                                                   |
 *| This  code  and  information  is  provided  "as is"  without  any |
 *| warranty of any kind,  either expressed or implied, including but |
 *| not limited  to the implied warranties  of merchantability and/or |
 *| fitness for any particular purpose.                               |
 *+-------------------------------------------------------------------+
 *
 *  Module name              : root.c    1.8
 *
 *  Last update              : 10:48:03 - 99/04/26
 *
 *  Title                    : Psos-based IO test program
 *
 *  Description              : This is a test programme for
 *                             demonstrating
 *                             D N S name lookup (also using serial
 *                             I/O over T C P/I P).
 */

#include <tmlib/tmtypes.h>
#include <stdio.h>
#include <psos.h>
#include <pna.h>
#include <dns.h>
#include "sys_conf.h"
#include "assert.h"
#include <tmlib/dprintf.h>

#define COUNT(a) (sizeof (a)/sizeof *(a))

static union {unsigned char a [4]; long l;} servers [] =
{
   {{130, 140, 26, 166}}, /*trins1.trimedia.sv.sc.philips.com*/
   {{130, 140, 45, 252}}, /*svlns3.sv.sc.philips.com*/
   {{130, 140, 26, 125}}, /*purple2.trimedia.sv.sc.philips.com*/
};

char *search_list [] =
{
   "trimedia.sv.sc.philips.com",
   "sv.sc.philips.com",
   NULL
};

static rescfg_t res_conf =
{
   RES_STATIC << 8 | RES_DNS, /*priorities for resolution (encoded)*/
   100,                       /*priority for resolver timer task*/
   DNS_MODE_CACHE_NET,        /*query mode*/
   60,                        /*maximim TTL for DNS RRs*/
   2*100,                     /*wait period for resolver timeouts*/
   2,                         /*number of times resolver retransmits*/
   5,                         /*maximim cache entries*/
   COUNT (servers),           /*no of DNS servers*/
   (long *) servers,          /*list of DNS servers to probe*/
   search_list,               /*DNS search path*/
   5,                         /*maximum entries in static host table*/
   0,                         /*maximum entries in static net table*/
   10,                        /*mark time for DNS cache*/
   30                         /*sweep time for DNS cache*/
};

enum cpt {cpt_C = 1, cpt_PSOS, cpt_DNS, cpt_LOCAL};
#define cpt_SHIFT 24
#define cpt_MASK  0xFF000000u
#define C     (cpt_C     << cpt_SHIFT)
#define PSOS  (cpt_PSOS  << cpt_SHIFT)
#define DNS   (cpt_DNS   << cpt_SHIFT)
#define LOCAL (cpt_LOCAL << cpt_SHIFT)

void root (void)
{
   char             name [80];
   UInt             err = 0u;
   struct hostent   host;
   char           **p;
   int              i;

   DP_START (10*1024, Null);
   DP_ON ();

   DP (("+root\n"));

   SerialRPC_start ();

   printf ("Standalone Set Top Box Started\n");

   if ((err = res_start (&res_conf)) != 0)
      {err |= PSOS; goto finish;}

   if ((err = res_set_hostentry (htonl (SD_LAN1_IP), NC_HOSTNAME)) !=
         0)
      {err |= DNS; goto finish;}

   while (True)
   {
      if (printf ("? ") == -1)
         {err = C | errno; goto finish;}

      if (fflush (stdout) == -1)
         {err = C | errno; goto finish;}

      if (fgets (name, sizeof name, stdin) == NULL)
         {err = C | errno; goto finish;}

      /*Remove the trailing \n.*/
      name [strcspn (name, "\n")] = '\0';

      if (name [0] == '\0')
         break;

      if (printf ("gethostbyname (\"%s\"):\n", name) == -1)
         {err = C | errno; goto finish;}

      if (gethostbyname (name, &host) == -1)
      {
         if (printf ("   _|_\n") == -1)
            {err = C | errno; goto finish;}
      }
      else
      {
         if (host.h_addrtype != AF_INET)
            {err = LOCAL | __LINE__; goto finish;}

         if (host.h_length != 4)
            {err = LOCAL | __LINE__; goto finish;}

         if (host.h_aliases != NULL)
            {err = LOCAL | __LINE__; goto finish;}

         if (printf ("   h_name          \"%s\"\n"
               "   h_aliases       NULL\n"
               "   h_addrtype      AF_INET\n"
               "   h_length        4\n",
               host.h_name) == -1)
            {err = C | errno; goto finish;}

         i = 0;
         for (p = host.h_addr_list; *p != NULL; ++p)
            if (printf ("   h_addr_list [%d] %d.%d.%d.%d\n", i++,
                  ((unsigned char *) *p) [0],
                  ((unsigned char *) *p) [1],
                  ((unsigned char *) *p) [2],
                  ((unsigned char *) *p) [3]) == -1)
               {err = C | errno; goto finish;}
      }
   }

finish:
   if (err == 0u)
      printf ("Standalone Set Top Box Stopped\n");
   else
      switch (err >> cpt_SHIFT)
      {
         case cpt_C:
            printf ("C library error %d\n", err & ~cpt_MASK);
         break;

         case cpt_PSOS:
            printf ("pSOS error %d\n", err & ~cpt_MASK);
         break;

         case cpt_DNS:
            printf ("D N S error\n");
         break;

         case cpt_LOCAL:
            printf ("Local error at line %d\n", err & ~cpt_MASK);
         break;
      }

   DP (("-root\n"));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -