Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

packet.c File Reference


Detailed Description

G2 packet parser / constructor.

Author:
Jeroen Asselman
Date:
2004

#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "packet.h"

Functions

char * g2_packet_pack (g2packet_t *packet, int *length)
 G2 Packet pack.

int g2_packet_calc_new_length (g2packet_t *packet)
 G2 Packet calculate length/.

void g2_packet2buf (g2packet_t *packet, char *destination)
 G2 Packet2buf.

g2packet_tg2_new_packet ()
 G2 New Packet.

void g2_free_packet (g2packet_t *packet)
 G2 free packet.

void g2_parse_header (char **buffer, g2packet_t *packet)
 g2 parse header.

void g2_parse_packet (char **buffer, g2packet_t *packet)
 G2 Parse packet.

char * g2_packet_get_name (g2packet_t *packet)
 Get the packet name.

g2packet_tg2_packet_get_next_child (g2packet_t *basepacket)
 Get the next child from the current packet.

char * g2_packet_get_payload (g2packet_t *packet, int *length)
 Get payload.

void g2_packet_add_child (g2packet_t *packet, g2packet_t *child)
 Add child to packet.

void g2_packet_add_payload (g2packet_t *packet, char *payload, int length)
 G2 Packet add payload.

int g2_packet_calc_lenlength (int length)
 Calculate the lenlength field from a given length.


Function Documentation

void g2_free_packet g2packet_t packet  ) 
 

G2 free packet.

Frees a g2 packet and any associated memory. This will also free a payload assigned.

g2packet_t* g2_new_packet  ) 
 

G2 New Packet.

Creates a new G2 packet.

void g2_packet2buf g2packet_t packet,
char *  destination
 

G2 Packet2buf.

In the destination pointer a g2 packet is constructed from the given G2Packet. The destination should be at least the size retreived with g2_packet_calc_new_length(packet).

void g2_packet_add_child g2packet_t packet,
g2packet_t child
 

Add child to packet.

Adds a child packet to the packet. Do _not_ add child packets after adding a payload.

Parameters:
packet is a pointer to the packet to which the child should be added.
child is a pointer to the packet to add.

void g2_packet_add_payload g2packet_t packet,
char *  payload,
int  length
 

G2 Packet add payload.

Adds a payload to the current packet. After this do _NOT_ add children anymore.

Parameters:
packet is a pointer to the packet to which the payload should be added.
payload is a pointer to the payload which will be added to the packet.
length is the length of the payload to add.

int g2_packet_calc_lenlength int  length  )  [static]
 

Calculate the lenlength field from a given length.

int g2_packet_calc_new_length g2packet_t packet  ) 
 

G2 Packet calculate length/.

Calculates the size that will be used by this G2Packet when transformed to a buffer / char pointer.

Returns:
the length of the G2Packet when transformed to a buffer.

char* g2_packet_get_name g2packet_t packet  ) 
 

Get the packet name.

Retreives the name of the packet.

Returns:
a name string.

g2packet_t* g2_packet_get_next_child g2packet_t basepacket  ) 
 

Get the next child from the current packet.

Retreives the next child packet from the current packet and moves to the next child packet. Next time this function is called the next child packet is returned.

Returns:
the child packet or NULL if no (more) child packets are available.

char* g2_packet_get_payload g2packet_t packet,
int *  length
 

Get payload.

After this it isn't possible anymore to retreive any children. As it will fast skip them

char * g2_packet_pack g2packet_t packet,
int *  length
 

G2 Packet pack.

Construct a buffer from a G2Packet and return the newly allocated buffer.

Returns:
a pointer to the buffer containing the packed G2Packet.

void g2_parse_header char **  buffer,
g2packet_t packet
 

g2 parse header.

Parse the packet header to extract length information.

void g2_parse_packet char **  buffer,
g2packet_t packet
 

G2 Parse packet.

Parse the g2 packet to retreive the start of the payload/children


Generated on Sun Feb 12 10:50:05 2006 for Gtk-Gnutella by doxygen 1.3.6