base.h
上传用户:allwinjm
上传日期:2021-08-29
资源大小:99k
文件大小:6k
源码类别:

Internet/IE编程

开发平台:

Unix_Linux

  1. /************************************************************************ 
  2.  * RSTP library - Rapid Spanning Tree (802.1t, 802.1w) 
  3.  * Copyright (C) 2001-2003 Optical Access 
  4.  * Author: Alex Rozin 
  5.  * 
  6.  * This file is part of RSTP library. 
  7.  * 
  8.  * RSTP library is free software; you can redistribute it and/or modify it 
  9.  * under the terms of the GNU Lesser General Public License as published by the 
  10.  * Free Software Foundation; version 2.1 
  11.  * 
  12.  * RSTP library is distributed in the hope that it will be useful, but 
  13.  * WITHOUT ANY WARRANTY; without even the implied warranty of 
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser 
  15.  * General Public License for more details. 
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public License 
  18.  * along with RSTP library; see the file COPYING.  If not, write to the Free 
  19.  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
  20.  * 02111-1307, USA. 
  21.  **********************************************************************/
  22. /* Mutual RSTP definitions */
  23.  
  24. #ifndef _STP_BASE_H__
  25. #define _STP_BASE_H__
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #ifdef DEBUG
  29. #  define STP_DBG 1
  30. #endif
  31. #ifdef __LINUX__
  32. #  include <stddef.h>
  33. #  include <stdio.h>
  34. #  include <netinet/in.h>
  35. #  include "bitmap.h"
  36. #  include "uid_stp.h"
  37. #  define Print printf
  38. #else
  39. #  include <psos.h>
  40. #  include "comdef.h"
  41. #  include "comdef.x"                        
  42. #  include "Bitmap/bitmap.h"
  43. #  include "Bitmap/bitmap.x"
  44. #  include "Ui/uid_stp.h"
  45. #endif
  46. #ifndef INOUT
  47. #  define IN      /* consider as comments near 'input' parameters */
  48. #  define OUT     /* consider as comments near 'output' parameters */
  49. #  define INOUT   /* consider as comments near 'input/output' parameters */
  50. #endif
  51. #ifndef Zero
  52. #  define Zero        0
  53. #  define One         1
  54. #endif
  55. #ifndef Bool
  56. #  define Bool        int
  57. #  define False       0
  58. #  define True        1
  59. #endif
  60. #include "stp_bpdu.h"
  61. #include "vector.h"
  62. #include "times.h"
  63. #define RSTP_ERRORS { 
  64.   CHOOSE(STP_OK),                                       
  65.   CHOOSE(STP_Cannot_Find_Vlan),         
  66.   CHOOSE(STP_Imlicite_Instance_Create_Failed),          
  67.   CHOOSE(STP_Small_Bridge_Priority),                    
  68.   CHOOSE(STP_Large_Bridge_Priority),                    
  69.   CHOOSE(STP_Small_Hello_Time),                         
  70.   CHOOSE(STP_Large_Hello_Time),                         
  71.   CHOOSE(STP_Small_Max_Age),                            
  72.   CHOOSE(STP_Large_Max_Age),                            
  73.   CHOOSE(STP_Small_Forward_Delay),                      
  74.   CHOOSE(STP_Large_Forward_Delay),                      
  75.   CHOOSE(STP_Forward_Delay_And_Max_Age_Are_Inconsistent),
  76.   CHOOSE(STP_Hello_Time_And_Max_Age_Are_Inconsistent),  
  77.   CHOOSE(STP_Vlan_Had_Not_Yet_Been_Created),            
  78.   CHOOSE(STP_Port_Is_Absent_In_The_Vlan),               
  79.   CHOOSE(STP_Big_len8023_Format),                       
  80.   CHOOSE(STP_Small_len8023_Format),                     
  81.   CHOOSE(STP_len8023_Format_Gt_Len),                    
  82.   CHOOSE(STP_Not_Proper_802_3_Packet),                  
  83.   CHOOSE(STP_Invalid_Protocol),                         
  84.   CHOOSE(STP_Invalid_Version),                          
  85.   CHOOSE(STP_Had_Not_Yet_Been_Enabled_On_The_Vlan),     
  86.   CHOOSE(STP_Cannot_Create_Instance_For_Vlan),          
  87.   CHOOSE(STP_Cannot_Create_Instance_For_Port),          
  88.   CHOOSE(STP_Invalid_Bridge_Priority),                  
  89.   CHOOSE(STP_There_Are_No_Ports),                       
  90.   CHOOSE(STP_Cannot_Compute_Bridge_Prio),               
  91.   CHOOSE(STP_Another_Error),                            
  92.   CHOOSE(STP_Nothing_To_Do),                            
  93.   CHOOSE(STP_LAST_DUMMY),                               
  94. }
  95. #define CHOOSE(a) a
  96. typedef enum RSTP_ERRORS RSTP_ERRORS_T;
  97. #undef CHOOSE
  98. #ifndef __LINUX__
  99. extern char* strdup (const char *s);
  100. extern USHORT Ntohs (USHORT n); 
  101. extern ULONG Htonl (ULONG h);   
  102. extern USHORT Htons (USHORT h);
  103. extern ULONG Ntohl (ULONG n);
  104. #define htonl Htonl
  105. #define htons Htons
  106. #define ntohl Ntohl
  107. #define ntohs Ntohs
  108. #endif
  109. #ifdef __LINUX__
  110. #define STP_FATAL(TXT, MSG, EXCOD)                      
  111.       {stp_trace ("FATAL:%s failed: %s:%d", TXT, MSG, EXCOD);  
  112.       exit (EXCOD);}
  113. #else
  114. #define STP_FATAL(TXT, MSG, EXCOD)                      
  115.       Print ("FATAL: %s code %s:%dn", TXT, MSG, EXCOD)
  116. #endif
  117. #define STP_MALLOC(PTR, TYPE, MSG)              
  118.   {                                             
  119.     PTR = (TYPE*) calloc (1, sizeof (TYPE));    
  120.     if (! PTR) {                                
  121.       STP_FATAL("malloc", MSG, -6);             
  122.     }                                           
  123.   }
  124. #define STP_FREE(PTR, MSG)              
  125.   {                                     
  126.     if (! PTR) {                        
  127.       STP_FATAL("free", MSG, -66);      
  128.     }                                   
  129.     free (PTR);                         
  130.     PTR = NULL;                         
  131.   }
  132. #define STP_STRDUP(PTR, SRC, MSG)       
  133.   {                                     
  134.     PTR = strdup (SRC);                 
  135.     if (! PTR) {                        
  136.       STP_FATAL("strdup", MSG, -7);     
  137.     }                                   
  138.   }
  139. #define STP_NEW_IN_LIST(WHAT, TYPE, LIST, MSG)  
  140.   {                                             
  141.     STP_MALLOC(WHAT, TYPE, MSG);                
  142.     WHAT->next = LIST;                          
  143.     LIST = WHAT;                                
  144.   }
  145. typedef enum {
  146.   RSTP_PORT_EN_T,
  147.   RSTP_PORT_DIS_T,
  148.   RSTP_PORT_SPEED_T,
  149.   RSTP_PORT_DPLEX_T,
  150.   RSTP_PORT_RX_T,
  151.   RSTP_PORT_TIME_T,
  152.   RSTP_PORT_MNGR_T,
  153.   RSTP_EVENT_LAST_DUMMY
  154. } RSTP_EVENT_T;
  155. /* for debug trace messages */
  156. #ifdef __LINUX__
  157. extern char* sprint_time_stump (void);
  158. #define stp_trace(F, B...) printf("%s:" F "n", sprint_time_stump(), ##B)
  159. #else
  160. extern ULONG stp_trace (const char* fmt, ...);
  161. #endif
  162. #endif /*  _STP_BASE_H__ */