Binary Packet

Binary Packet — A binary data packet.

Synopsis

                    GskPacket;
void                (*GskPacketDestroyFunc)             (gpointer destroy_data,
                                                         GskPacket *packet);
GskPacket *         gsk_packet_new                      (gpointer data,
                                                         guint length,
                                                         GskPacketDestroyFunc destroy,
                                                         gpointer destroy_data);
GskPacket *         gsk_packet_new_copy                 (gconstpointer data,
                                                         guint length);
void                gsk_packet_set_src_address          (GskPacket *packet,
                                                         GskSocketAddress *address);
void                gsk_packet_set_dst_address          (GskPacket *packet,
                                                         GskSocketAddress *address);
void                gsk_packet_unref                    (GskPacket *packet);
GskPacket *         gsk_packet_ref                      (GskPacket *packet);

Description

A reference-counted binary piece of data with a destroy-notify to allow arbitrary memory management.

It may optionally have two GskSocketAddress to denote the source and destination of the packet.

Details

GskPacket

typedef struct {
  /*< public: readonly >*/
  gpointer data;
  guint len;
  GskSocketAddress *src_address;
  GskSocketAddress *dst_address;
  GskPacketDestroyFunc destroy;
  gpointer destroy_data;
} GskPacket;

A packet of binary data, optionally associated with a particular host.

gpointer data;

the raw binary data.

guint len;

length of the raw data.

GskSocketAddress *src_address;

GskSocketAddress *dst_address;

GskPacketDestroyFunc destroy;

destroy notification.

gpointer destroy_data;

data to invoke destroy on.

GskPacketDestroyFunc ()

void                (*GskPacketDestroyFunc)             (gpointer destroy_data,
                                                         GskPacket *packet);

The actual function prototype of destroy. This is only useful if you want to examine the whole GskPacket from your destroy function.

destroy_data :

as passed to gsk_packet_new()

packet :

the whole packet.

gsk_packet_new ()

GskPacket *         gsk_packet_new                      (gpointer data,
                                                         guint length,
                                                         GskPacketDestroyFunc destroy,
                                                         gpointer destroy_data);

Creates a new packet with the given data. The packet's ref-count is 1; it will be destroyed when it gets to 0.

data :

binary data in the packet

length :

length of binary data

destroy :

method to destroy the data.

destroy_data :

the argument to the destroy method.

Returns :

a new GskPacket

gsk_packet_new_copy ()

GskPacket *         gsk_packet_new_copy                 (gconstpointer data,
                                                         guint length);

Creates a new packet with a copy of the given data. The packet's ref-count is 1; it will be destroyed when it gets to 0.

data :

binary data to be copied into the packet

length :

length of binary data

Returns :

a new GskPacket

gsk_packet_set_src_address ()

void                gsk_packet_set_src_address          (GskPacket *packet,
                                                         GskSocketAddress *address);

Change the source address associated with a packet. This should be the address of the interface the packet was sent from.

packet :

a packet whose source address should be changed.

address :

the new address.

gsk_packet_set_dst_address ()

void                gsk_packet_set_dst_address          (GskPacket *packet,
                                                         GskSocketAddress *address);

Change the destination address associated with a packet. This should be the address of the interface the packet was sent to.

packet :

a packet whose destination address should be changed.

address :

the new address.

gsk_packet_unref ()

void                gsk_packet_unref                    (GskPacket *packet);

Remove a reference-count from the packet, deleting the packet if it gets to 0.

packet :

a packet to remove a reference from.

gsk_packet_ref ()

GskPacket *         gsk_packet_ref                      (GskPacket *packet);

Add a reference-count to the packet.

packet :

a packet to add a reference to.

Returns :

the packet, for convenience.