ip.h
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
  2. /*
  3.  * Copyright (c) 1997 Regents of the University of California.
  4.  * All rights reserved.
  5.  * 
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in the
  13.  *    documentation and/or other materials provided with the distribution.
  14.  * 3. All advertising materials mentioning features or use of this software
  15.  *    must display the following acknowledgement:
  16.  *  This product includes software developed by the MASH Research
  17.  *  Group at the University of California Berkeley.
  18.  * 4. Neither the name of the University nor of the Research Group may be
  19.  *    used to endorse or promote products derived from this software without
  20.  *    specific prior written permission.
  21.  * 
  22.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32.  * SUCH DAMAGE.
  33.  *
  34.  * @(#) $Header: /cvsroot/nsnam/ns-2/common/ip.h,v 1.16 2006/02/22 13:32:23 mahrenho Exp $
  35.  */
  36. /* a network layer; basically like IPv6 */
  37. #ifndef ns_ip_h
  38. #define ns_ip_h
  39. #include "config.h"
  40. #include "packet.h"
  41. #define IP_HDR_LEN      20
  42. #define IP_DEF_TTL      32
  43. // The following undef is to suppress warnings on systems were
  44. // IP_BROADCAST is defined.
  45. #ifdef IP_BROADCAST
  46. #undef IP_BROADCAST
  47. #endif
  48. // #define IP_BROADCAST ((u_int32_t) 0xffffffff)
  49. static const u_int32_t IP_BROADCAST = ((u_int32_t) 0xffffffff);
  50. struct hdr_ip {
  51. /* common to IPv{4,6} */
  52. ns_addr_t src_;
  53. ns_addr_t dst_;
  54. int ttl_;
  55. /* Monarch extn */
  56. //  u_int16_t sport_;
  57. //  u_int16_t dport_;
  58. /* IPv6 */
  59. int fid_; /* flow id */
  60. int prio_;
  61. static int offset_;
  62. inline static int& offset() { return offset_; }
  63. inline static hdr_ip* access(const Packet* p) {
  64. return (hdr_ip*) p->access(offset_);
  65. }
  66. /* per-field member acces functions */
  67. ns_addr_t& src() { return (src_); }
  68. nsaddr_t& saddr() { return (src_.addr_); }
  69.         int32_t& sport() { return src_.port_;}
  70. ns_addr_t& dst() { return (dst_); }
  71. nsaddr_t& daddr() { return (dst_.addr_); }
  72.         int32_t& dport() { return dst_.port_;}
  73. int& ttl() { return (ttl_); }
  74. /* ipv6 fields */
  75. int& flowid() { return (fid_); }
  76. int& prio() { return (prio_); }
  77. };
  78. #endif