File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / libnet / doc / html / libnet-asn1_8h-source.html
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 22:14:23 2012 UTC (12 years, 5 months ago) by misho
Branches: libnet, MAIN
CVS tags: v1_1_2_1, HEAD
libnet

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>libnet: libnet-asn1.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.4 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div>
<h1>libnet-asn1.h</h1><div class="fragment"><pre>00001 <span class="comment">/*</span>
00002 <span class="comment"> *  $Id: libnet-asn1_8h-source.html,v 1.1.1.1 2012/02/21 22:14:23 misho Exp $</span>
00003 <span class="comment"> *</span>
00004 <span class="comment"> *  libnet-asn1.h - Network routine library ASN.1 header file</span>
00005 <span class="comment"> *</span>
00006 <span class="comment"> *  Copyright (c) 1998 - 2004 Mike D. Schiffman &lt;mike@infonexus.com&gt;</span>
00007 <span class="comment"> *  All rights reserved.</span>
00008 <span class="comment"> *</span>
00009 <span class="comment"> *  Definitions for Abstract Syntax Notation One, ASN.1</span>
00010 <span class="comment"> *  As defined in ISO/IS 8824 and ISO/IS 8825</span>
00011 <span class="comment"> *</span>
00012 <span class="comment"> *  Copyright 1988, 1989 by Carnegie Mellon University</span>
00013 <span class="comment"> *  All rights reserved.</span>
00014 <span class="comment"> *</span>
00015 <span class="comment"> *  Permission to use, copy, modify, and distribute this software and its</span>
00016 <span class="comment"> *  documentation for any purpose and without fee is hereby granted,</span>
00017 <span class="comment"> *  provided that the above copyright notice appear in all copies and that</span>
00018 <span class="comment"> *  both that copyright notice and this permission notice appear in</span>
00019 <span class="comment"> *  supporting documentation, and that the name of CMU not be</span>
00020 <span class="comment"> *  used in advertising or publicity pertaining to distribution of the</span>
00021 <span class="comment"> *  software without specific, written prior permission.</span>
00022 <span class="comment"> *</span>
00023 <span class="comment"> *  CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING</span>
00024 <span class="comment"> *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL</span>
00025 <span class="comment"> *  CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR</span>
00026 <span class="comment"> *  ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,</span>
00027 <span class="comment"> *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,</span>
00028 <span class="comment"> *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS</span>
00029 <span class="comment"> *  SOFTWARE.</span>
00030 <span class="comment"> *</span>
00031 <span class="comment"> *  Copyright (c) 1998 - 2001 Mike D. Schiffman &lt;mike@infonexus.com&gt;</span>
00032 <span class="comment"> *  All rights reserved.</span>
00033 <span class="comment"> *</span>
00034 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
00035 <span class="comment"> * modification, are permitted provided that the following conditions</span>
00036 <span class="comment"> * are met:</span>
00037 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
00038 <span class="comment"> *    notice, this list of conditions and the following disclaimer.</span>
00039 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
00040 <span class="comment"> *    notice, this list of conditions and the following disclaimer in the</span>
00041 <span class="comment"> *    documentation and/or other materials provided with the distribution.</span>
00042 <span class="comment"> *</span>
00043 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND</span>
00044 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
00045 <span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
00046 <span class="comment"> * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE</span>
00047 <span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
00048 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</span>
00049 <span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span>
00050 <span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span>
00051 <span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</span>
00052 <span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span>
00053 <span class="comment"> * SUCH DAMAGE.</span>
00054 <span class="comment"> */</span>
00055 
00056 <span class="preprocessor">#ifndef __LIBNET_ASN1_H</span>
00057 <span class="preprocessor"></span><span class="preprocessor">#define __LIBNET_ASN1_H</span>
00058 <span class="preprocessor"></span>
00059 <span class="preprocessor">#ifndef EIGHTBIT_SUBIDS</span>
00060 <span class="preprocessor"></span><span class="keyword">typedef</span> u_int32_t  oid;
00061 <span class="preprocessor">#define MAX_SUBID   0xFFFFFFFF</span>
00062 <span class="preprocessor"></span><span class="preprocessor">#else</span>
00063 <span class="preprocessor"></span><span class="keyword">typedef</span> u_int8_t  oid;
00064 <span class="preprocessor">#define MAX_SUBID   0xFF</span>
00065 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00066 <span class="preprocessor"></span>
00067 <span class="preprocessor">#define MAX_OID_LEN         64  </span><span class="comment">/* max subid's in an oid */</span>
00068 
00069 <span class="preprocessor">#define ASN_BOOLEAN         (0x01)</span>
00070 <span class="preprocessor"></span><span class="preprocessor">#define ASN_INTEGER         (0x02)</span>
00071 <span class="preprocessor"></span><span class="preprocessor">#define ASN_BIT_STR         (0x03)</span>
00072 <span class="preprocessor"></span><span class="preprocessor">#define ASN_OCTET_STR       (0x04)</span>
00073 <span class="preprocessor"></span><span class="preprocessor">#define ASN_NULL            (0x05)</span>
00074 <span class="preprocessor"></span><span class="preprocessor">#define ASN_OBJECT_ID       (0x06)</span>
00075 <span class="preprocessor"></span><span class="preprocessor">#define ASN_SEQUENCE        (0x10)</span>
00076 <span class="preprocessor"></span><span class="preprocessor">#define ASN_SET             (0x11)</span>
00077 <span class="preprocessor"></span>
00078 <span class="preprocessor">#define ASN_UNIVERSAL       (0x00)</span>
00079 <span class="preprocessor"></span><span class="preprocessor">#define ASN_APPLICATION     (0x40)</span>
00080 <span class="preprocessor"></span><span class="preprocessor">#define ASN_CONTEXT         (0x80)</span>
00081 <span class="preprocessor"></span><span class="preprocessor">#define ASN_PRIVATE         (0xC0)</span>
00082 <span class="preprocessor"></span>
00083 <span class="preprocessor">#define ASN_PRIMITIVE       (0x00)</span>
00084 <span class="preprocessor"></span><span class="preprocessor">#define ASN_CONSTRUCTOR     (0x20)</span>
00085 <span class="preprocessor"></span>
00086 <span class="preprocessor">#define ASN_LONG_LEN        (0x80)</span>
00087 <span class="preprocessor"></span><span class="preprocessor">#define ASN_EXTENSION_ID    (0x1F)</span>
00088 <span class="preprocessor"></span><span class="preprocessor">#define ASN_BIT8            (0x80)</span>
00089 <span class="preprocessor"></span>
00090 <span class="preprocessor">#define IS_CONSTRUCTOR(byte)  ((byte) &amp; ASN_CONSTRUCTOR)</span>
00091 <span class="preprocessor"></span><span class="preprocessor">#define IS_EXTENSION_ID(byte) (((byte) &amp; ASN_EXTENSION_ID) = ASN_EXTENSION_ID)</span>
00092 <span class="preprocessor"></span>
00093 <span class="comment">/*</span>
00094 <span class="comment"> *  All of the build_asn1_* (build_asn1_length being an exception) functions</span>
00095 <span class="comment"> *  take the same first 3 arguments:</span>
00096 <span class="comment"> *</span>
00097 <span class="comment"> *  u_int8_t *data:   This is a pointer to the start of the data object to be</span>
00098 <span class="comment"> *                  manipulated.</span>
00099 <span class="comment"> *  int *datalen:   This is a pointer to the number of valid bytes following</span>
00100 <span class="comment"> *                  "data".  This should be not be exceeded in any function.</span>
00101 <span class="comment"> *                  Upon exiting a function, this value will reflect the</span>
00102 <span class="comment"> *                  changed "data" and then refer to the new number of valid</span>
00103 <span class="comment"> *                  bytes until the end of "data".</span>
00104 <span class="comment"> *  u_int8_t type:    The ASN.1 object type.</span>
00105 <span class="comment"> */</span>
00106 
00107 
00108 <span class="comment">/*</span>
00109 <span class="comment"> *  Builds an ASN object containing an integer.</span>
00110 <span class="comment"> *</span>
00111 <span class="comment"> *  Returns NULL upon error or a pointer to the first byte past the end of</span>
00112 <span class="comment"> *  this object (the start of the next object).</span>
00113 <span class="comment"> */</span>
00114 
00115 u_int8_t *
00116 libnet_build_asn1_int(
00117     u_int8_t *,           <span class="comment">/* Pointer to the output buffer */</span>
00118     <span class="keywordtype">int</span> *,              <span class="comment">/* Number of valid bytes left in the buffer */</span>
00119     u_int8_t,             <span class="comment">/* ASN object type */</span>
00120     int32_t *,             <span class="comment">/* Pointer to a int32_t integer */</span>
00121     <span class="keywordtype">int</span>                 <span class="comment">/* Size of a int32_t integer */</span>
00122     );
00123 
00124 
00125 <span class="comment">/*</span>
00126 <span class="comment"> *  Builds an ASN object containing an unsigned integer.</span>
00127 <span class="comment"> *</span>
00128 <span class="comment"> *  Returns NULL upon error or a pointer to the first byte past the end of</span>
00129 <span class="comment"> *  this object (the start of the next object).</span>
00130 <span class="comment"> */</span>
00131 
00132 u_int8_t *
00133 libnet_build_asn1_uint(
00134     u_int8_t *,           <span class="comment">/* Pointer to the output buffer */</span>
00135     <span class="keywordtype">int</span> *,              <span class="comment">/* Number of valid bytes left in the buffer */</span>
00136     u_int8_t,             <span class="comment">/* ASN object type */</span>
00137     u_int32_t *,           <span class="comment">/* Pointer to an unsigned int32_t integer */</span>
00138     <span class="keywordtype">int</span>                 <span class="comment">/* Size of a int32_t integer */</span>
00139     );
00140 
00141 
00142 <span class="comment">/*</span>
00143 <span class="comment"> *  Builds an ASN object containing an octect string.</span>
00144 <span class="comment"> *</span>
00145 <span class="comment"> *  Returns NULL upon error or a pointer to the first byte past the end of</span>
00146 <span class="comment"> *  this object (the start of the next object).</span>
00147 <span class="comment"> */</span>
00148 
00149 u_int8_t *
00150 libnet_build_asn1_string(
00151     u_int8_t *,           <span class="comment">/* Pointer to the output buffer */</span>
00152     <span class="keywordtype">int</span> *,              <span class="comment">/* Number of valid bytes left in the buffer */</span>
00153     u_int8_t,             <span class="comment">/* ASN object type */</span>
00154     u_int8_t *,           <span class="comment">/* Pointer to a string to be built into an object */</span>
00155     <span class="keywordtype">int</span>                 <span class="comment">/* Size of the string */</span>
00156     );
00157 
00158 
00159 <span class="comment">/*</span>
00160 <span class="comment"> *  Builds an ASN header for an object with the ID and length specified.  This</span>
00161 <span class="comment"> *  only works on data types &lt; 30, i.e. no extension octets.  The maximum</span>
00162 <span class="comment"> *  length is 0xFFFF;</span>
00163 <span class="comment"> *</span>
00164 <span class="comment"> *  Returns a pointer to the first byte of the contents of this object or</span>
00165 <span class="comment"> *  NULL upon error</span>
00166 <span class="comment"> */</span>
00167 
00168 u_int8_t *
00169 libnet_build_asn1_header(
00170     u_int8_t *,       <span class="comment">/* Pointer to the start of the object */</span>
00171     <span class="keywordtype">int</span> *,          <span class="comment">/* Number of valid bytes left in buffer */</span>
00172     u_int8_t,         <span class="comment">/* ASN object type */</span>
00173     <span class="keywordtype">int</span>             <span class="comment">/* ASN object length */</span>
00174     );
00175 
00176 
00177 u_int8_t *
00178 libnet_build_asn1_length(
00179     u_int8_t *,       <span class="comment">/* Pointer to start of object */</span>
00180     <span class="keywordtype">int</span> *,          <span class="comment">/* Number of valid bytes in buffer */</span>
00181     <span class="keywordtype">int</span>             <span class="comment">/* Length of object */</span>
00182     );
00183 
00184 
00185 <span class="comment">/*</span>
00186 <span class="comment"> *  Builds an ASN header for a sequence with the ID and length specified.</span>
00187 <span class="comment"> *</span>
00188 <span class="comment"> *  This only works on data types &lt; 30, i.e. no extension octets.</span>
00189 <span class="comment"> *  The maximum length is 0xFFFF;</span>
00190 <span class="comment"> *</span>
00191 <span class="comment"> *  Returns a pointer to the first byte of the contents of this object.</span>
00192 <span class="comment"> *  Returns NULL on any error.</span>
00193 <span class="comment"> */</span>
00194 
00195 u_int8_t *
00196 libnet_build_asn1_sequence(
00197     u_int8_t *,
00198     <span class="keywordtype">int</span> *,
00199     u_int8_t,
00200     <span class="keywordtype">int</span>
00201     );
00202 
00203 
00204 <span class="comment">/*</span>
00205 <span class="comment"> *  Builds an ASN object identifier object containing the input string.</span>
00206 <span class="comment"> *</span>
00207 <span class="comment"> *  Returns NULL upon error or a pointer to the first byte past the end of</span>
00208 <span class="comment"> *  this object (the start of the next object).</span>
00209 <span class="comment"> */</span>
00210 
00211 u_int8_t *
00212 libnet_build_asn1_objid(
00213     u_int8_t *,
00214     <span class="keywordtype">int</span> *,
00215     u_int8_t,
00216     oid *,
00217     <span class="keywordtype">int</span>
00218     );
00219 
00220 
00221 <span class="comment">/*</span>
00222 <span class="comment"> *  Builds an ASN null object.</span>
00223 <span class="comment"> *</span>
00224 <span class="comment"> *  Returns NULL upon error or a pointer to the first byte past the end of</span>
00225 <span class="comment"> *  this object (the start of the next object).</span>
00226 <span class="comment"> */</span>
00227 
00228 u_int8_t *
00229 libnet_build_asn1_null(
00230     u_int8_t *,
00231     <span class="keywordtype">int</span> *,
00232     u_int8_t
00233     );
00234 
00235 
00236 <span class="comment">/*</span>
00237 <span class="comment"> *  Builds an ASN bitstring.</span>
00238 <span class="comment"> *</span>
00239 <span class="comment"> *  Returns NULL upon error or a pointer to the first byte past the end of</span>
00240 <span class="comment"> *  this object (the start of the next object).</span>
00241 <span class="comment"> */</span>
00242 
00243 u_int8_t *
00244 libnet_build_asn1_bitstring(
00245     u_int8_t *,
00246     <span class="keywordtype">int</span> *,
00247     u_int8_t,
00248     u_int8_t *,       <span class="comment">/* Pointer to the input buffer */</span>
00249     <span class="keywordtype">int</span>             <span class="comment">/* Length of the input buffer */</span>
00250     );
00251 
00252 
00253 <span class="preprocessor">#endif  </span><span class="comment">/* __LIBNET_ASN1_H */</span>
00254 
00255 <span class="comment">/* EOF */</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Wed Mar 10 13:23:37 2004 for libnet by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 > 
</a>1.3.4 </small></address>
</body>
</html>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>