src/vfer_packet.c File Reference

Implements packetizing and depacketizing functions. More...

#include "vfer_packet.h"

Go to the source code of this file.

Functions

static void Packet_Compute_Delay (char *pack_buf, struct timeval *tv, packet *p)
packetPacket_Form_CCAck (uint32_t opts, uint32_t seq_num, uint32_t last_seq_received, uint16_t packets_lost, uint16_t oldest_frame, uint16_t newest_frame, int32_t delay_delta, int32_t delay, uint32_t bytes_total, uint16_t intervals_frame_num, intervals_t *intervals)
packetPacket_Form_Close (uint32_t opts, uint32_t seq_num)
packetPacket_Form_Data (uint32_t opts, uint32_t seq_num, uint16_t frame_num, uint32_t data_offset, uint32_t frame_len, void *data, int data_len)
packetPacket_Form_Request (uint32_t opts, uint32_t init_seq_num, uint32_t max_frame_size, uint32_t recv_buf_size, uint32_t send_buf_size, uint16_t init_frame_num)
packetPacket_Form_Response (uint32_t opts, uint32_t init_seq_num, uint16_t init_frame_num, uint16_t connection_port, uint32_t max_frame_size, uint32_t recv_buf_size, uint32_t send_buf_size, int32_t request_delay)
uint16_t Packet_Gen_FrameNum ()
uint32_t Packet_Gen_SeqNum ()
static void Packet_Get_Header (packet *p)
static int Packet_Get_Opt (uint32_t opts, int opt)
static void Packet_Get_Type (char *buf, unsigned char *type)
static void Packet_Get_Version (char *buf, unsigned char *version)
static packetPacket_PrepIov (int num_bufs, int first_buf_len)
void Packet_Print (packet *p)
int Packet_Read (int fd, packet **p, struct sockaddr *addr, socklen_t *addr_len)
int Packet_Read_ICMP (int icmp_fd, void *pmtu)
static int Packet_Set_Header (packet *p, unsigned char type, uint32_t opts, uint32_t seq)
static void Packet_Set_Opt (uint32_t *opts, int opt)
void Packet_Set_Seq (packet *p, uint32_t seq)
char * Packet_Str (packet *p)
char * Packet_Str_Type (packet *p)
int Packet_Translate_CCAck (packet *p)
int Packet_Translate_Close (packet *p)
int Packet_Translate_Data (packet *p)
int Packet_Translate_Request (packet *p)
int Packet_Translate_Response (packet *p)
static void Packet_Unset_Opt (uint32_t *opts, int opt)
int Packet_Write (packet *p, int fd, struct sockaddr *addr, socklen_t addr_len)


Detailed Description

Implements packetizing and depacketizing functions.

Author:
Ivan Beschastnikh
This file contains usefull functions to compose and decompose packets. It also includes some handy utilities for printing packets out to stdout.

Definition in file vfer_packet.c.


Function Documentation

static void Packet_Compute_Delay ( char *  pack_buf,
struct timeval *  tv,
packet p 
) [inline, static]

Computes the delay for a packet based on the raw packet buffer, sets the value computed in the packet structure and also extracts the time stamp from the raw packet buffer into the structure

Parameters:
pack_buf raw packet buffer
tv time structure marking receipt time for the packet
p packet structure for the packet buffer

Definition at line 717 of file vfer_packet.c.

packet* Packet_Form_CCAck ( uint32_t  opts,
uint32_t  seq_num,
uint32_t  last_seq_received,
uint16_t  packets_lost,
uint16_t  oldest_frame,
uint16_t  newest_frame,
int32_t  delay_delta,
int32_t  delay,
uint32_t  bytes_total,
uint16_t  intervals_frame_num,
intervals_t intervals 
)

Forms a CC Ack packet

Parameters:
opts options for the generic header of the packet
seq_num sequence number for the generic header of the packet
last_seq_received last sequence number received by this connection
packets_lost estimated lost number of frags
oldest_frame oldest frame the received of this packet should resend
newest_frame oldest frame the received of this packet should resend
delay_delta current delay on the reverse path (not the path of this ack)
delay current delay for the reverse path
bytes_total total data bytes received by the endpoint
intervals_frame_num the frame number corresponding to the missing data intervals
intervals intervals structure (defined in datagram.h) If intervals->head == 0 then no intervals will be sent in the ack packet
Returns:
NULL on error pointer to an allocated packet on success

Definition at line 304 of file vfer_packet.c.

packet* Packet_Form_Close ( uint32_t  opts,
uint32_t  seq_num 
)

Forms a Close packet

Parameters:
opts options for the generic header of the packet
seq_num sequence number for the generic header of the packet
Returns:
NULL on error pointer to an allocated packet on success

Definition at line 417 of file vfer_packet.c.

packet* Packet_Form_Data ( uint32_t  opts,
uint32_t  seq_num,
uint16_t  frame_num,
uint32_t  data_offset,
uint32_t  frame_len,
void *  data,
int  data_len 
)

Forms a Data packet

Parameters:
opts options for the generic header of the packet
seq_num sequence number for the generic header of the packet
frame_num frame number this data packet carries a frag for
data_offset offset of the data in the frame
frame_len either -1 (do not include in the data header) (opts will be set and send accordingly) or is not -1, in which case it is included in the data header
data data buffer to send in the body of the data packet
data_len tells us how the span of the data buffer pointed to by the data arg
Returns:
NULL on error pointer to an allocated packet on success

Definition at line 240 of file vfer_packet.c.

packet* Packet_Form_Request ( uint32_t  opts,
uint32_t  init_seq_num,
uint32_t  max_frame_size,
uint32_t  recv_buf_size,
uint32_t  send_buf_size,
uint16_t  init_frame_num 
)

Forms a Request packet

Parameters:
opts options for the generic header of the packet
init_seq_num initial sequence number for the sender's half of connection
max_frame_size maximum frame size the sender is willing to receive
recv_buf_size receive buffer size at the sender
send_buf_size sending buffer size at the sender
init_frame_num initial frame number for the sender's half of connection
Returns:
NULL on error pointer to an allocated packet on success

Definition at line 134 of file vfer_packet.c.

packet* Packet_Form_Response ( uint32_t  opts,
uint32_t  init_seq_num,
uint16_t  init_frame_num,
uint16_t  connection_port,
uint32_t  max_frame_size,
uint32_t  recv_buf_size,
uint32_t  send_buf_size,
int32_t  request_delay 
)

Forms a Response packet

Parameters:
opts options for the generic header of the packet
init_seq_num initial sequence number for the sender's half of connection
init_frame_num initial frame number for the sender's half of connection
connection_port the connection port to which the sender should connect and use for the remained of this connection
max_frame_size maximum frame size the sender is willing to receive
recv_buf_size receive buffer size at the sender
send_buf_size sending buffer size at the sender
request_delay the delay computed for the request packet
Returns:
NULL on error pointer to an allocated packet on success

Definition at line 183 of file vfer_packet.c.

uint16_t Packet_Gen_FrameNum (  )  [inline]

Generates a random (2 bytes) frame number

Returns:
generated frame number

Definition at line 1037 of file vfer_packet.c.

uint32_t Packet_Gen_SeqNum (  )  [inline]

Generates a random (4 byte) sequence number.

Returns:
generated sequence number

Definition at line 1048 of file vfer_packet.c.

static void Packet_Get_Header ( packet p  )  [inline, static]

Gets the packet header from a packet buffer and writes into the packet structure

Parameters:
p pointer to the packet in which get and get the header

Definition at line 659 of file vfer_packet.c.

static int Packet_Get_Opt ( uint32_t  opts,
int  opt 
) [inline, static]

Boolean function that checks if an option is set

Parameters:
opts options pointer
opt option to check for
Returns:
0 if option is not set 1 if the option is set

Definition at line 1091 of file vfer_packet.c.

static void Packet_Get_Type ( char *  buf,
unsigned char *  type 
) [inline, static]

Extracts the type in a bufer interpreted as packet header

Parameters:
buf packet buffer
type reference arg type of packet

Definition at line 686 of file vfer_packet.c.

static void Packet_Get_Version ( char *  buf,
unsigned char *  version 
) [inline, static]

Extracts the version in a buffer interpreted as packet header

Parameters:
buf packet buffer
version reference argument into which the version will be stored

Definition at line 700 of file vfer_packet.c.

static packet * Packet_PrepIov ( int  num_bufs,
int  first_buf_len 
) [inline, static]

Prepares the iov strucutre for a packet

Parameters:
num_bufs number of iov buffers to allocate
first_buf_len length of the first buffer to allocate
Returns:
NULL on error newly allocated packet pointer with allocated buffers

Definition at line 748 of file vfer_packet.c.

void Packet_Print ( packet p  ) 

Prints a description of the packet onto stdout

Parameters:
p packet pointer

Definition at line 107 of file vfer_packet.c.

int Packet_Read ( int  fd,
packet **  p,
struct sockaddr *  addr,
socklen_t *  addr_len 
)

Reads from a file descriptor into an iov buffer.

Does minor validation of the generic header. Returns either an error or the packet_type of the received packet. Set iov as return by reference.

Parameters:
fd file descriptor to which to write the buffer
p packet strucutre to read the packet into
addr pointer that is either NULL or address to which we send the iov
addr_len pointer to be set by reference to length of addr param
Returns:
0 on success (p contains a valid packet) errno on syscall error -1 received packet has incorrect length (validation err) -2 received packet has incorrect type (validation err) -3 received packet has incorrect version (validation err) -4 on unknown packet type -5 on error (shutdown socket) -6 on error (ALLOC macro) -7 on error (other) - such as mismatched recv sizes (see below)

Definition at line 789 of file vfer_packet.c.

int Packet_Read_ICMP ( int  icmp_fd,
void *  pmtu 
)

Reads ICMP packets and makes any necessary adjustments to the path MTU.

Parameters:
icmp_fd file descriptor of icmp socket
pmtu pmtu structure to modify if we read an ICMP packet
Returns:
0 on success (p contains a valid packet) -1 no ICMP packets to be read

Definition at line 913 of file vfer_packet.c.

static int Packet_Set_Header ( packet p,
unsigned char  type,
uint32_t  opts,
uint32_t  seq 
) [inline, static]

Sets the packet header into a packet buffer

Parameters:
p pointer to the packet in which to set the header
type type of packet
opts opts to store in packet
seq sequence number to set in packet
Returns:
number of bytes of buf that are used by the header

Definition at line 637 of file vfer_packet.c.

static void Packet_Set_Opt ( uint32_t *  opts,
int  opt 
) [inline, static]

Sets an option in an options pointer

Parameters:
opts options pointer
opt option to set

Definition at line 1063 of file vfer_packet.c.

void Packet_Set_Seq ( packet p,
uint32_t  seq 
) [inline]

Sets the sequence number in the packet header

Parameters:
p pointer to the packet in which to set the header
seq sequence number to set in the header

Definition at line 618 of file vfer_packet.c.

char* Packet_Str ( packet p  ) 

Create a string description of the packet

Parameters:
p packet pointer
Returns:
string describing the packet parameter

Definition at line 75 of file vfer_packet.c.

char* Packet_Str_Type ( packet p  ) 

String type of packet

Parameters:
p packet pointer
Returns:
string describing the type of the packet parameter

Definition at line 53 of file vfer_packet.c.

int Packet_Translate_CCAck ( packet p  ) 

Fills in the cc_ack union memeber with values from a raw packet

Parameters:
p packet pointer to traslate
Returns:
0 on success -1 packet with incorrect length

Definition at line 543 of file vfer_packet.c.

int Packet_Translate_Close ( packet p  ) 

Fills in the close union memeber with values from a raw packet

Parameters:
p packet pointer to traslate
Returns:
0 on success -1 packet with incorrect length

Definition at line 601 of file vfer_packet.c.

int Packet_Translate_Data ( packet p  ) 

Fills in the data union memeber with values from a raw packet

Parameters:
p packet pointer to traslate
Returns:
0 on success -1 packet with incorrect length

Definition at line 502 of file vfer_packet.c.

int Packet_Translate_Request ( packet p  ) 

Fills in the request union memeber with values from a raw packet

Parameters:
p packet pointer to traslate
Returns:
0 on success -1 packet with incorrect length

Definition at line 437 of file vfer_packet.c.

int Packet_Translate_Response ( packet p  ) 

Fills in the response union memeber with values from a raw packet

Parameters:
p packet pointer to traslate
Returns:
0 on success -1 packet with incorrect length

Definition at line 466 of file vfer_packet.c.

static void Packet_Unset_Opt ( uint32_t *  opts,
int  opt 
) [inline, static]

Unsets an option in an options pointer

Parameters:
opts options pointer
opt option to unset

Definition at line 1075 of file vfer_packet.c.

int Packet_Write ( packet p,
int  fd,
struct sockaddr *  addr,
socklen_t  addr_len 
)

Writes a packet of a certain length to a file descriptor.

Parameters:
p packet structure containing the packet to write out
fd file descriptor to which to write the buffer
addr is the address to send the packet to (eg. for unconnected sockets - used in server.c Server_Accept() )
addr_len is the length of the addr param
Returns:
0 on success errno generated by sendmsg or writev on error

Definition at line 956 of file vfer_packet.c.


Generated on Tue Aug 8 16:07:21 2006 for VFER by  doxygen 1.4.7