2015-04-05 02:07:59 +02:00
|
|
|
/*
|
|
|
|
This file is part of libcapwap.
|
|
|
|
|
|
|
|
libcapwap is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
libcapwap is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-03-06 11:03:55 +01:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Implements some aciplist functions
|
|
|
|
*/
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
#include "aciplist.h"
|
2018-03-06 18:28:31 +01:00
|
|
|
#include "mavl.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
#include "sock.h"
|
|
|
|
|
|
|
|
|
2018-03-06 18:28:31 +01:00
|
|
|
static int acip_cmp(const mavldata_t *x1, const mavldata_t *x2)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2018-03-06 18:28:31 +01:00
|
|
|
struct cw_acip *ip1 = (struct cw_acip *) x1->ptr;
|
|
|
|
struct cw_acip *ip2 = (struct cw_acip *) x2->ptr;
|
2015-04-10 17:14:55 +02:00
|
|
|
|
2016-11-07 19:37:02 +01:00
|
|
|
int r = ip1->index - ip2->index;
|
2015-04-10 17:14:55 +02:00
|
|
|
if (r!=0)
|
|
|
|
return r;
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
if (ip1->ip.ss_family != ip2->ip.ss_family) {
|
2014-07-11 22:12:11 +02:00
|
|
|
if (ip1->ip.ss_family == AF_INET)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
if (ip1->ip.ss_family == AF_INET) {
|
|
|
|
struct sockaddr_in *s2 = (struct sockaddr_in *) &ip2->ip;
|
|
|
|
struct sockaddr_in *s1 = (struct sockaddr_in *) &ip1->ip;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
return memcmp(&s1->sin_addr, &s2->sin_addr,
|
|
|
|
sock_addrlen((struct sockaddr *) s1));
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
if (ip1->ip.ss_family == AF_INET6) {
|
|
|
|
struct sockaddr_in6 *s2 = (struct sockaddr_in6 *) &ip2->ip;
|
|
|
|
struct sockaddr_in6 *s1 = (struct sockaddr_in6 *) &ip1->ip;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
return memcmp(&s1->sin6_addr.s6_addr, &s2->sin6_addr.s6_addr,
|
|
|
|
sock_addrlen((struct sockaddr *) s1));
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-03-06 18:28:31 +01:00
|
|
|
static void acip_del(mavldata_t *d)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2018-03-06 18:28:31 +01:00
|
|
|
free(d->ptr);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
2016-03-06 11:03:55 +01:00
|
|
|
/**
|
|
|
|
* Create a cw_aciplist_t object
|
|
|
|
* @return The created aciplist or NULL if an error has occured.
|
|
|
|
*/
|
2015-04-05 02:07:59 +02:00
|
|
|
cw_aciplist_t cw_aciplist_create()
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2018-03-06 18:28:31 +01:00
|
|
|
return mavl_create(acip_cmp, acip_del);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|