mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
0e0f6021ce
This patch changes the network filtering code to use libvirt's existing IPv4 and IPv6 address parsers/printers rather than my self-written ones. I am introducing a new function in network.c that counts the number of bits in a netmask and ensures that the given address is indeed a netmask, return -1 on error or values of 0-32 for IPv4 addresses and 0-128 for IPv6 addresses. I then based the function checking for valid netmask on invoking this function.
55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
/*
|
|
* network.h: network helper APIs for libvirt
|
|
*
|
|
* Copyright (C) 2009-2009 Red Hat, Inc.
|
|
*
|
|
* See COPYING.LIB for the License of this software
|
|
*
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
*/
|
|
|
|
#ifndef __VIR_NETWORK_H__
|
|
# define __VIR_NETWORK_H__
|
|
|
|
# include "internal.h"
|
|
|
|
# include <sys/types.h>
|
|
# include <sys/socket.h>
|
|
# include <netdb.h>
|
|
|
|
typedef union {
|
|
struct sockaddr_storage stor;
|
|
struct sockaddr_in inet4;
|
|
struct sockaddr_in6 inet6;
|
|
} virSocketAddr;
|
|
typedef virSocketAddr *virSocketAddrPtr;
|
|
|
|
int virSocketParseAddr (const char *val,
|
|
virSocketAddrPtr addr,
|
|
int hint);
|
|
|
|
int virSocketParseIpv4Addr(const char *val,
|
|
virSocketAddrPtr addr);
|
|
|
|
int virSocketParseIpv6Addr(const char *val,
|
|
virSocketAddrPtr addr);
|
|
|
|
char * virSocketFormatAddr(virSocketAddrPtr addr);
|
|
|
|
int virSocketSetPort(virSocketAddrPtr addr, int port);
|
|
|
|
int virSocketGetPort(virSocketAddrPtr addr);
|
|
|
|
int virSocketGetRange (virSocketAddrPtr start,
|
|
virSocketAddrPtr end);
|
|
|
|
int virSocketAddrIsNetmask(virSocketAddrPtr netmask);
|
|
|
|
int virSocketCheckNetmask (virSocketAddrPtr addr1,
|
|
virSocketAddrPtr addr2,
|
|
virSocketAddrPtr netmask);
|
|
|
|
int virSocketGetNumNetmaskBits(const virSocketAddrPtr netmask);
|
|
|
|
#endif /* __VIR_NETWORK_H__ */
|