in_var.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:8k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* in_var.h - internet interface variable header file */
  2. /* Copyright 1984 - 2001 Wind River Systems, Inc. */
  3. /*
  4.  * Copyright (c) 1985, 1986, 1993
  5.  * The Regents of the University of California.  All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  * 3. All advertising materials mentioning features or use of this software
  16.  *    must display the following acknowledgement:
  17.  * This product includes software developed by the University of
  18.  * California, Berkeley and its contributors.
  19.  * 4. Neither the name of the University nor the names of its contributors
  20.  *    may be used to endorse or promote products derived from this software
  21.  *    without specific prior written permission.
  22.  *
  23.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33.  * SUCH DAMAGE.
  34.  *
  35.  * @(#)in_var.h 8.2 (Berkeley) 1/9/95
  36.  */
  37. /*
  38. modification history
  39. --------------------
  40. 01d,04dec01,rae  cleanup
  41. 01c,10oct01,rae  merge from truestack (IGMPv2, VIRTUAL)
  42. 01b,05oct97,vin  changed in_ifaddr for fast multicasting.
  43. 01a,03mar96,vin  created from BSD4.4lite2.
  44. */
  45. #ifndef __INCin_varh
  46. #define __INCin_varh
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. #include "net/if.h"
  51. #include "netinet/in_pcb.h"
  52. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  53. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  54. #endif /* CPU_FAMILY==I960 */
  55. /*
  56.  * Interface address, Internet version.  One of these structures
  57.  * is allocated for each interface with an Internet address.
  58.  * The ifaddr structure contains the protocol-independent part
  59.  * of the structure and is assumed to be first.
  60.  */
  61. struct in_ifaddr {
  62. struct ifaddr ia_ifa; /* protocol-independent info */
  63. #define ia_ifp ia_ifa.ifa_ifp
  64. #define ia_flags ia_ifa.ifa_flags
  65. /* ia_{,sub}net{,mask} in host order */
  66. u_long ia_net; /* network number of interface */
  67. u_long ia_netmask; /* mask of net part */
  68. u_long ia_subnet; /* subnet number, including net */
  69. u_long ia_subnetmask; /* mask of subnet part */
  70. struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
  71. struct in_ifaddr *ia_next; /* next in list of internet addresses */
  72. struct sockaddr_in ia_addr; /* reserve space for interface name */
  73. struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
  74. #define ia_broadaddr ia_dstaddr
  75. struct sockaddr_in ia_sockmask; /* reserve space for general netmask */
  76. };
  77. struct in_aliasreq {
  78. char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  79. struct sockaddr_in ifra_addr;
  80. struct sockaddr_in ifra_broadaddr;
  81. #define ifra_dstaddr ifra_broadaddr
  82. struct sockaddr_in ifra_mask;
  83. };
  84. /*
  85.  * Given a pointer to an in_ifaddr (ifaddr),
  86.  * return a pointer to the addr as a sockaddr_in.
  87.  */
  88. #define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr))
  89. #define IN_LNAOF(in, ifa) 
  90. ((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
  91. #ifndef VIRTUAL_STACK
  92. extern struct in_ifaddr *in_ifaddr;
  93. #endif /* VIRTUAL_STACK */
  94. extern struct ifqueue ipintrq; /* ip packet input queue */
  95. extern u_char  inetctlerrmap[];
  96. extern void in_socktrim (struct sockaddr_in *);
  97. /*
  98.  * Macro for finding the interface (ifnet structure) corresponding to one
  99.  * of our IP addresses.
  100.  */
  101. #ifdef VIRTUAL_STACK
  102. #define INADDR_TO_IFP(addr, ifp) 
  103. /* struct in_addr addr; */ 
  104. /* struct ifnet *ifp; */ 
  105. register struct in_ifaddr *ia; 
  106. for (ia = _in_ifaddr; 
  107.     ia != NULL && IA_SIN(ia)->sin_addr.s_addr != (addr).s_addr; 
  108.     ia = ia->ia_next) 
  109.  continue; 
  110. (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; 
  111. }
  112. #else
  113. #define INADDR_TO_IFP(addr, ifp) 
  114. /* struct in_addr addr; */ 
  115. /* struct ifnet *ifp; */ 
  116. register struct in_ifaddr *ia; 
  117. for (ia = in_ifaddr; 
  118.     ia != NULL && IA_SIN(ia)->sin_addr.s_addr != (addr).s_addr; 
  119.     ia = ia->ia_next) 
  120.  continue; 
  121. (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; 
  122. }
  123. #endif /* VIRTUAL_STACK */
  124. /*
  125.  * Macro for finding the internet address structure (in_ifaddr) corresponding
  126.  * to a given interface (ifnet structure).
  127.  */
  128. #ifdef VIRTUAL_STACK
  129. #define IFP_TO_IA(ifp, ia) 
  130. /* struct ifnet *ifp; */ 
  131. /* struct in_ifaddr *ia; */ 
  132. for ((ia) = _in_ifaddr; 
  133.     (ia) != NULL && (ia)->ia_ifp != (ifp); 
  134.     (ia) = (ia)->ia_next) 
  135. continue; 
  136. }
  137. #else
  138. #define IFP_TO_IA(ifp, ia) 
  139. /* struct ifnet *ifp; */ 
  140. /* struct in_ifaddr *ia; */ 
  141. for ((ia) = in_ifaddr; 
  142.     (ia) != NULL && (ia)->ia_ifp != (ifp); 
  143.     (ia) = (ia)->ia_next) 
  144. continue; 
  145. }
  146. #endif /* VIRTUAL_STACK */
  147. LIST_HEAD(inMultiHead, in_multi); 
  148. /*
  149.  * This information should be part of the ifnet structure but we don't wish
  150.  * to change that - as it might break a number of things
  151.  */
  152. struct router_info {
  153. struct ifnet *rti_ifp;
  154. int    rti_type; /* type of router which is querier on this interface */
  155. int    rti_time; /* # of slow timeouts since last old query */
  156. struct router_info *rti_next;
  157. };
  158. /*
  159.  * Internet multicast address structure.  There is one of these for each IP
  160.  * multicast group to which this host belongs on a given network interface.
  161.  * They are kept in a linked list, rooted in the interface's in_ifaddr
  162.  * structure. (now it is a "hash list")
  163.  */
  164. struct in_multi {
  165. LIST_ENTRY(in_multi) inm_hash; /* hash list */
  166. struct in_addr inm_addr; /* IP multicast address */
  167. struct ifnet *inm_ifp; /* back pointer to ifnet */
  168. u_int inm_refcount; /* no. membership claims by sockets */
  169.         u_int inm_timer; /* IGMP membership report timer */
  170.         u_int inm_state; /*  state of the membership */
  171.         struct router_info *inm_rti; /* router info*/
  172.        struct  mBlk * pInPcbMblk;  /* chain of pcbs */ 
  173. };
  174. struct mcastHashInfo
  175.     {
  176.     struct inMultiHead * hashBase;
  177.     ULONG hashMask;
  178.     };
  179. typedef struct in_multi IN_MULTI;
  180. typedef struct mcastHashInfo M_CAST_HASH_INFO;
  181. typedef struct inMultiHead IN_MULTI_HEAD;
  182. extern struct mcastHashInfo mCastHashInfo;
  183. /* necessary macros */
  184. #define MCAST_HASH(mCastAddr, ifp, mask) 
  185. (((mCastAddr) ^ ((mCastAddr) >> 16) ^ (int)(ifp)) & (mask))
  186. /*
  187.  * Macro for looking up the in_multi record for a given IP multicast address
  188.  * on a given interface.  If no matching record is found, "inm" returns NULL.
  189.  */
  190. #define IN_LOOKUP_MULTI(addr, ifp, inm)  
  191.     {
  192.     (inm) = mcastHashTblLookup ((addr).s_addr, (ifp));
  193.     }
  194. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  195. #pragma align 0 /* turn off alignment requirement */
  196. #endif /* CPU_FAMILY==I960 */
  197. extern int in_ifinit (struct ifnet *,
  198.                            struct in_ifaddr *, struct sockaddr_in *, int);
  199. extern struct mBlk * in_addmulti (struct in_addr *, struct ifnet *,
  200.                                   struct inpcb *);
  201. extern int in_delmulti (struct mBlk *, struct inpcb *);
  202. extern void in_ifscrub (struct ifnet *, struct in_ifaddr *);
  203. extern int in_control (struct socket *, u_long, caddr_t, struct ifnet *);
  204. IMPORT STATUS  mcastHashTblInsert (struct in_multi *  pInMulti);
  205. IMPORT STATUS  mcastHashTblDelete (struct in_multi * pInMulti);
  206. IMPORT IN_MULTI * mcastHashTblLookup (int mcastAddr, struct ifnet * pIf);
  207. #ifdef __cplusplus
  208. }
  209. #endif
  210. #endif /* __INCin_varh */