Porting code that used the libparticle before version v0.4.0 to the current version mainly means changing the names of some types, most functions and fields. The number of arguments changed in some methods. Accessing several fields of packets can now be done by appropriate method calls.
Be aware that not all changes / methods are mentioned!
packet = p_pkt_alloc();). Especially after the use of free_acl_packet(packet);.
cl_packet* parse_cl_packet(int version, unsigned char* data, int len); method that converts packet contents into a struct with the new method int p_pkt_parse(struct p_packet * packet, uint8_t * buffer, size_t len); that parses the data of a buffer (for example, after p_revc_raw) into the structure of a packet.
In the table, example calls are shown.
| old version (< v0.4.0) | new version (>= v0.4.0) |
|---|---|
| cl_packet *packet = NULL; | struct p_packet *packet = NULL; |
| packet = create_cl_packet(2); | packet = p_pkt_alloc(); |
| send_sock = p_socket(5556, 0); | send_sock = p_socket_open(0, 0, 5556); |
| p_close(send_sock); | p_socket_close(send_sock); |
| sent = p_send_acked(send_sock, recv_sock, packet, sendToId, num_of_retries, timeout); | p_socket_set_retry(send_sock, number_of_retries, timeout); sent = p_socket_send_acked(send_sock, recv_sock, pkt, sendToId); (or use int p_socket_send_acked_str(int send_sock, int recv_sock, struct p_packet * send_data, char * addstr);) |
| sent = p_send(send_sock, packet); | sent = p_socket_send(send_sock, pkt); |
| add_acl_tupel(cl, create_acl_tupel("RDA", (const unsigned char *)sendtext, sendlen)); | int p_acl_add(packet, (uint8_t*) type, sendtext, sendlen, 0); or use p_acl_add_str(packet, "RDA", sendtext, sendlen, 0); |
| free_acl_packet(packet); or free_cl_packet(packet); | p_pkt_free(packet); |
| recpkt = p_recv(recv_sock, send_sock); | recpkt = p_socket_recv(recv_sock, send_sock); |
| recpkt->acl_packet | p_acl_first(recpkt) |
| recpkt->id | p_pkt_get_srcid(recpkt) |
| acltup->len | acltup->acl_len |
| val = acltup->data[0] | p_acl_get_data(acltup, (char**)data); val = (*data)[0] |
For the next methods, the function signatures are shown.
| int p_send_addressed(int send_sock, cl_packet *cl, const unsigned char* ID); | int p_socket_send_addressed(int send_sock, struct p_packet * send_data, uint8_t * add); (or use int p_socket_send_addressed_str(int send_sock, struct p_packet * send_data, char * add_str);) |
| int p_set_blockingmode(int sock, unsigned char mode); | int p_socket_set_blocking(int sock, int mode); |
| int p_init_recv(int sock); | int p_socket_set_recv_option(int fd, int option); |
| int p_recv_raw(int sock, unsigned char *data, int maxlen); | int p_socket_recv_raw(int sock, char * data, size_t maxlen); |
| int p_send_addressed(int send_sock, cl_packet *cl, const unsigned char* ID); | int p_socket_send_addressed(int send_sock, struct p_packet * send_data, uint8_t * add); |
| int p_send_raw(int sock, unsigned char *data, int len); | int p_socket_send_raw(int sock, char * data, size_t len); |
| void p_add_filter(int sock, const char* type); void p_rm_filter(int sock, const char* type); void p_add_id_filter(int sock, const char* id); void p_rm_id_filter(int sock, const char* id); void p_add_loc_filter(int sock, const char* loc); void p_rm_loc_filter(int sock, const char* loc); | use some of these instead: struct p_packet *p_socket_recv_filtered(int recv_sock, int send_sock, int recv_filter); together with methods from filter.h: int p_filter_create(const char * filter_name); int p_filter_destroy(int filter); int p_filter_add(int filter, int type, void * arg); int p_filter_apply(int filter, struct p_packet * packet); void p_describe_filter(int filter); void *p_filter_arg(int filter); |
| void print_cl_packet(cl_packet *cl); | void p_describe_pkt(struct p_packet * packet); |
| acl_tupel* get_next_acl_tupel(cl_packet *cl); acl_tupel* get_next_acl_tupel_by_type(cl_packet *cl, const char* type); |
use some of these instead: struct p_acl_tuple *p_acl_first(const struct p_packet * packet); struct p_acl_tuple *p_acl_next(const struct p_packet * packet, const struct p_acl_tuple * acl_touple); int p_acl_findfirst(const struct p_packet * packet, const uint8_t * acl_type, struct p_acl_tuple ** found_touple); int p_acl_findfirst_str(const struct p_packet * packet, const char * acl_type, struct p_acl_tuple ** found_touple); int p_acl_findnext(const struct p_packet * packet, const struct p_acl_tuple * current_touple, struct p_acl_tuple ** found_touple); |
| old version | new version (>= v0.4.0) |
|---|---|
| ->location | uint8_t *p_pkt_get_location(struct p_packet * packet); or char *p_pkt_get_location_str(struct p_packet * packet, char * buffer, size_t maxlen); |
| ->id | uint8_t *p_pkt_get_srcid(struct p_packet * packet); or char *p_pkt_get_srcid_str(struct p_packet * packet, char * buffer, size_t maxlen); |
| ->seq | int p_pkt_get_seq(struct p_packet * packet); |
The according setter methods are:
int p_pkt_set_location(struct p_packet * packet, const uint8_t * location); or
int p_pkt_set_location_str(struct p_packet * packet, const char * location);
int p_pkt_set_srcid(struct p_packet * packet, const uint8_t * source);
int p_pkt_set_srcid_str(struct p_packet * packet, const char * source);
int p_pkt_set_seq(struct p_packet * packet, const uint8_t seq);
New methods are:
int p_pkt_get_ack(struct p_packet * packet);
uint8_t * p_acl_get_type(struct p_acl_tuple * acl);
char * p_pkt_get_type_str(struct p_acl_tuple *acl, char *buf);
struct p_acl_tuple *p_acl_new(uint8_t *type, uint8_t * data, uint16_t len, int may_frag );
struct p_acl_tuple *p_acl_new_str(char *type_str, uint8_t *data, uint16_t len, int may_frag );
int p_socket_set_ipdest(int sock, struct in_addr * address);
int p_socket_set_ipdest_str(int sock, char * address);
int p_socket_set_ipsrc_all(int sock);
int p_socket_set_ipsrc(int sock, struct in_addr * address);
int p_socket_set_ipsrc_str(int sock , char * address);
int p_socket_set_broadcast(int sock);
int p_socket_set_id(int sock, uint8_t * add);
int p_socket_set_id_str(int sock, char * addstr);
int p_socket_set_loc(int sock, uint8_t * loc);
int p_socket_set_loc_str(int sock, char * locstr);
int p_socket_set_autoack(int sock, int mode);
int p_socket_set_retry(int sock, uint8_t retries, uint32_t timeout);
void p_describe_socket(int sock);
frag.h
int p_socket_set_frag_option(int fd, int option);
int p_socket_send_file(int fd_out, int fd_in, uint8_t * buf, uint32_t len, uint8_t * sendto, uint8_t * acl_type);
int p_socket_send_file_str(int fd_out, int fd_in, uint8_t * buf, uint32_t len, char * sendto, char * acl_type);
#include <sys/types.h>
#ifdef WIN32
#include <windows.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include <errno.h>
#include <fcntl.h>
#ifndef WIN32
#include <netdb.h>
#include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "conf.h"
#include "error.h"
#include "packet.h"
#include "socket.h"
#include "util.h"
#include <libparticle.h>
#include <_packet.h>