common.h:

กก

uint16_t cksum(char *buff, int len)    

    Calculate the checksum for buff with length len 

int wrapudp(char *in, struct udp_t *out, int len, int sourceport, int destport)

    UDP encapsulation for in, the output will be out in udp_t structure. len is the length of in. sourceport and destport are source port and destination port need to be written in UDP header.

void wrapipv6(char *in, struct ipv6_t *out, uint16_t len, char* localaddr, char* targetaddr, uint16_t streamid, uint8_t nexthdr, char *filename)

    IPv6 encapsulation for in, the output will be out in ipv6_t structure. len is the length of in. localaddr and targetaddr are the IP addresses (in text format) for the source and destination. streamid is the stream id for the current flow and nexthdr denotes the what type the payload is in this package. There is a filename, which is not in standard IPv6 header. It denotes which file the current package belongs to.

void decapip6(char *in, struct ipv6_t *out, int pksize)

    IPv6 decapsulation for in, the output will be out in ipv6_t structure. pksize is the size of in in bytes. In fact, this function only copies in to out, so that out will be in ipv6_t structure, which is much easier to access for other functions.

void decapudp(char *in, struct udp_t *out, int pksize)

    UDP decapsulation for in, the output will be out in udp_t structure. pksize is the size of in in bytes.

int decapedip(char *in, struct shmbuffedit_t *shmbuffedit, char *edippayload, int in_len, int whichpk)

    EDIP decapsulation for in, the result will be in shmbuffedit, which is the editing buffer for API. The payload of EDIP will be in edippayload. in_len is the length of in in bytes. whichpk denotes the sequence of current packages in the stream it belongs to. The function will return the data type of edippayload, either another EDIP header or real payload UDP header.

int chop (char *in, int in_len, struct chop_t *choptemp, int chopsize)

    A long file has to be chopped into small pieces before it can be transferred. in is the original file, in_len is the length of in, chopsize is the length of each chopped data. The result is in choptemp. The function will return the number of chops. 

กก

The following four functions are from Unix Network Programming Volume 1 by W. Richard Stevens, Prentice Hall.

const char *inet_ntop(int family, const void *addrptr, char *strptr, size_t len)

static ssize_t my_read(int fd, char *ptr)

ssize_t readn(int fd, void *vptr, size_t n)

ssize_t readline(int fd, void *vptr, size_t maxlen)