1 /* $Id: packet.c,v 1.1 2005/12/12 18:14:22 nobunaga Exp $ 
 
   3 Copyright (C) 2002 Marc Kirchner <kirchner@stud.fh-heilbronn.de>
 
   5 This library is free software; you can redistribute it and/or
 
   6 modify it under the terms of the GNU Lesser General Public
 
   7 License as published by the Free Software Foundation; either
 
   8 version 2.1 of the License, or (at your option) any later version.
 
  10 This library is distributed in the hope that it will be useful,
 
  11 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
  13 Lesser General Public License for more details.
 
  15 You should have received a copy of the GNU Lesser General Public
 
  16 License along with this library; if not, write to the Free Software
 
  17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
  24 @name int pkt_init(struct packet *pkt, unsigned long type, unsigned int size)
 
  25 @desc Allocates memory for a new packet and initializes its internal variables
 
  26 @param pkt pointer to the new packet
 
  27 @param type type of the packet. Its setting is currently ignored, but this is likely to change. Possible values are e.g. PKT_NET_IP|PKT_TRANS_TCP. See packet.h for other values
 
  28 @param size overall size if the packet not including ethernet headers or trailers.
 
  32 pkt_init(struct packet *pkt, unsigned long type, unsigned int size)
 
  34         if ((pkt->pkt = (unsigned char *) malloc(size)) == NULL) {
 
  35                 /* no mem, we assume errno will be set */
 
  39                 memset(pkt->pkt, 0, size);
 
  43                 /* set active ptr to beginning of mem */
 
  44                 pkt->pkt_ptr = pkt->pkt;
 
  52 @name int pkt_free(struct packet *pkt)
 
  53 @desc Used to destroy a packet and to free used memory
 
  54 @param pkt the packet to destroy
 
  58 pkt_free(struct packet *pkt)
 
  70 @name int pkt_move_actptr(struct packet *pkt, int relmov) 
 
  71 @desc This function moves the active pointer inside the packet.
 
  72 @param pkt the packet whose active ptr is to be moved
 
  73 @param relmov number of bytes the active ptr shall be moved. To move it backward, negative values may be used.
 
  77 pkt_move_actptr(struct packet *pkt, int relmov)
 
  81         if ((pkt->pkt_pos + relmov > pkt->pkt_size) ||
 
  82                 (pkt->pkt_pos + relmov < 0)) {
 
  85                 pkt->pkt_ptr += relmov;