File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / mpd / src / ip.h
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 08:44:29 2013 UTC (11 years, 5 months ago) by misho
Branches: mpd, MAIN
CVS tags: v5_8p7, v5_8p1_cross, v5_8p1, v5_8, v5_7p0, v5_7, HEAD
5.7


/*
 * ip.h
 *
 * Written by Alexander Motin <mav@FreeBSD.org>
 */

#ifndef _IP_H_
#define _IP_H_

#include <sys/types.h>
#include <sys/param.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>

/*
 * DEFINITIONS
 */

  struct u_addr {
    sa_family_t family;
    union {
	struct in_addr ip4;
	struct in6_addr ip6;
    } u;
  };

  struct u_range {
    struct u_addr	addr;
    u_char    		width;
  };

  enum {
    ALLOW_IPV4=1,
    ALLOW_IPV6,
    ALLOW_MASK
  };

/*
 * FUNCTIONS
 */

  extern int	IpShowRoutes(Context ctx, int ac, char *av[], void *arg);
  extern int	IpAddrInRange(struct u_range *range, struct u_addr *addr);

  extern int	ParseAddr(const char *s, struct u_addr *addr, u_char allow);
  extern int	ParseRange(const char *s, struct u_range *range, u_char allow);
  extern struct sockaddr_storage * ParseAddrPort(int ac, char *av[], u_char allow);

  extern sa_family_t	u_addrfamily(struct u_addr *addr);
  extern sa_family_t	u_rangefamily(struct u_range *range);

  extern char	*u_addrtoa(struct u_addr *addr, char *dst, size_t size);
  extern char	*u_rangetoa(struct u_range *range, char *dst, size_t size);

  extern void	u_addrcopy(const struct u_addr *src, struct u_addr *dst);
  extern void	u_rangecopy(const struct u_range *src, struct u_range *dst);

  extern void	in_addrtou_addr(const struct in_addr *src, struct u_addr *dst);
  extern void	in6_addrtou_addr(const struct in6_addr *src, struct u_addr *dst);

  extern void	u_addrtoin_addr(const struct u_addr *src, struct in_addr *dst);
  extern void	u_addrtoin6_addr(const struct u_addr *src, struct in6_addr *dst);

  extern void	in_addrtou_range(const struct in_addr *src, u_char width, struct u_range *dst);
  extern void	in6_addrtou_range(const struct in6_addr *src, u_char width, struct u_range *dst);

  extern void	u_rangetosockaddrs(struct u_range *range, struct sockaddr_storage *dst, struct sockaddr_storage *msk);
  extern void	u_addrtosockaddr(struct u_addr *addr, in_port_t port, struct sockaddr_storage *dst);
  extern void	sockaddrtou_addr(struct sockaddr_storage *src, struct u_addr *addr, in_port_t *port);

  extern void	u_addrclear(struct u_addr *addr);
  extern void	u_rangeclear(struct u_range *range);

  extern int 	u_addrempty(struct u_addr *addr);
  extern int 	u_rangeempty(struct u_range *range);
  extern int 	u_rangehost(struct u_range *range);

  extern int 	u_addrcompare(const struct u_addr *addr1, const struct u_addr *addr2);
  extern int 	u_rangecompare(const struct u_range *range1, const struct u_range *range2);

  extern uint32_t	u_addrtoid(const struct u_addr *addr);
  
  extern u_char		in_addrtowidth(struct in_addr *mask);
  extern struct in_addr *widthtoin_addr(u_char width, struct in_addr *mask);

#endif


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>