1
0
mirror of https://code.semirocket.science/wrapsix synced 2024-11-10 08:10:59 +02:00
wrapsix/wrapper/storage.c

66 lines
1.4 KiB
C
Raw Normal View History

#include "storage.h"
2009-01-07 14:56:25 +02:00
/*** UDP ***/
int stg_conn_udp_cmp(const void *p1, const void *p2)
{
struct stg_conn_udp *pp1 = (struct stg_conn_udp *) p1;
struct stg_conn_udp *pp2 = (struct stg_conn_udp *) p2;
if (pp1->port < pp2->port) return -1;
if (pp1->port > pp2->port) return 1;
return 0;
}
void *stg_conn_udp_dup(void *p)
{
struct stg_conn_udp *pp = (struct stg_conn_udp *) p;
struct stg_conn_udp *p_new;
if ((p_new = (struct stg_conn_udp *) malloc(sizeof(struct stg_conn_udp))) == NULL) {
fprintf(stderr, "Fatal Error! Lack of free memory!\n");
exit(EXIT_FAILURE);
}
memcpy(p_new, pp, sizeof(struct stg_conn_udp));
return (void *) p_new;
}
void stg_conn_udp_rel(void *p)
{
free(p);
p = NULL;
}
/*** ICMP ***/
int stg_conn_icmp_cmp(const void *p1, const void *p2)
{
struct stg_conn_icmp *pp1 = (struct stg_conn_icmp *) p1;
struct stg_conn_icmp *pp2 = (struct stg_conn_icmp *) p2;
if (pp1->id < pp2->id) return -1;
if (pp1->id > pp2->id) return 1;
return 0;
}
void *stg_conn_icmp_dup(void *p)
{
struct stg_conn_icmp *pp = (struct stg_conn_icmp *) p;
struct stg_conn_icmp *p_new;
if ((p_new = (struct stg_conn_icmp *) malloc(sizeof(struct stg_conn_icmp))) == NULL) {
fprintf(stderr, "Fatal Error! Lack of free memory!\n");
exit(EXIT_FAILURE);
}
memcpy(p_new, pp, sizeof(struct stg_conn_icmp));
return (void *) p_new;
}
void stg_conn_icmp_rel(void *p)
{
free(p);
p = NULL;
}