Saturday, June 30, 2012

Why are there #define instructions inside a structure


Consider the following structure. What is the need for having the macro definitions #define within the structure?
- The only reason for doing that is because they are directly related to the element in the structure. For example, in this case, IEEE80211_NODE_PWR_MGT is associated with the element ni_flag.

struct ieee80211_node {
  112         struct ieee80211vap     *ni_vap;   /* associated vap */
  113         struct ieee80211com     *ni_ic;    /* copy from vap to save deref*/
  114         struct ieee80211_node_table *ni_table;/* NB: may be NULL */
  115         TAILQ_ENTRY(ieee80211_node) ni_list; /* list of all nodes */
  116         LIST_ENTRY(ieee80211_node) ni_hash; /* hash collision list */
  117         u_int                   ni_refcnt;  /* count of held references */
  118         u_int                   ni_scangen; /* gen# for timeout scan */
  119         u_int                   ni_flags;
  120 #define IEEE80211_NODE_AUTH     0x000001    /* authorized for data */
  121 #define IEEE80211_NODE_QOS      0x000002    /* QoS enabled */
  122 #define IEEE80211_NODE_ERP      0x000004    /* ERP enabled */
  123 /* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
  124 #define IEEE80211_NODE_PWR_MGT  0x000010    /* power save mode enabled */
  125 #define IEEE80211_NODE_AREF     0x000020    /* authentication ref held */
  142      ...........................
}

0 comments:

Post a Comment