mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added function to compare struct sockaddr's
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@59 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
08f14a1dc7
commit
6fc85c49ab
2 changed files with 37 additions and 0 deletions
|
@ -15,6 +15,7 @@
|
|||
|
||||
struct config;
|
||||
struct sockaddr_in;
|
||||
struct sockaddr;
|
||||
|
||||
/// The log level which is passed as first argument to print()
|
||||
enum log_level
|
||||
|
@ -55,6 +56,19 @@ int resolve_addr(const char *addr, struct sockaddr_in *sa, int flags);
|
|||
*/
|
||||
void init_realtime(struct config *g);
|
||||
|
||||
/** Compare two socket addresses based on their family and address.
|
||||
*
|
||||
* Only the family and the address is compared.
|
||||
* Port numbers etc are ignored.
|
||||
*
|
||||
* @param a First address
|
||||
* @param b Second address
|
||||
* @return
|
||||
* - 0 if the addresses are equal
|
||||
* - otherwise they are not equal
|
||||
*/
|
||||
int sockaddr_cmp(struct sockaddr *a, struct sockaddr *b);
|
||||
|
||||
/// Check assertion and exit if failed.
|
||||
#define assert(exp) do { \
|
||||
if (!(exp)) { \
|
||||
|
|
23
src/utils.c
23
src/utils.c
|
@ -90,6 +90,29 @@ int resolve_addr(const char *addr, struct sockaddr_in *sa, int flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sockaddr_cmp(struct sockaddr *a, struct sockaddr *b)
|
||||
{
|
||||
if (a->sa_family == b->sa_family) {
|
||||
switch (a->sa_family) {
|
||||
case AF_INET: {
|
||||
struct sockaddr_in *ai = (struct sockaddr_in *) a;
|
||||
struct sockaddr_in *bi = (struct sockaddr_in *) b;
|
||||
|
||||
return memcmp(&ai->sin_addr, &bi->sin_addr, sizeof(struct in_addr));
|
||||
}
|
||||
|
||||
case AF_INET6: {
|
||||
struct sockaddr_in6 *ai = (struct sockaddr_in6 *) a;
|
||||
struct sockaddr_in6 *bi = (struct sockaddr_in6 *) b;
|
||||
|
||||
return memcmp(&ai->sin6_addr, &bi->sin6_addr, sizeof(struct in6_addr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static cpu_set_t to_cpu_set_t(int set)
|
||||
{
|
||||
cpu_set_t cset;
|
||||
|
|
Loading…
Add table
Reference in a new issue