src/core/ip_addr.h
c391cc0d
 /**
53c7e0f1
  * ip address family related structures
7dd0b342
  *
53c7e0f1
  * Copyright (C) 2001-2003 FhG Fokus
7dd0b342
  *
6806e46a
  * This file is part of Kamailio, a free SIP server.
7dd0b342
  *
6806e46a
  * Kamailio is free software; you can redistribute it and/or modify
7dd0b342
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
6806e46a
  * Kamailio is distributed in the hope that it will be useful,
7dd0b342
  * 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.
  *
c391cc0d
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
4e2fdd79
  */
02ca141b
 /*!
c391cc0d
  * \file
  * \brief Kamailio core :: ip address family related structures
  * \ingroup core
  * Module: \ref core
  */
7dd0b342
 
4e2fdd79
 #ifndef ip_addr_h
 #define ip_addr_h
 
 #include <string.h>
381659ac
 #include <sys/types.h>
 #include <sys/socket.h>
4e2fdd79
 #include <netinet/in.h>
 #include <netdb.h>
36ef0329
 #include "str.h"
a288ee34
 #include "compiler_opt.h"
5ffc426e
 #include "ut.h"
4e2fdd79
 
 
 #include "dprint.h"
 
2d1b442f
 extern str ksr_ipv6_hex_style;
d48ce56d
 
44a21a8d
 typedef enum sip_protos { PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_SCTP,
 	PROTO_WS, PROTO_WSS, PROTO_OTHER } sip_protos_t;
cf4651db
 #define PROTO_LAST PROTO_OTHER
ed990c31
 
7a068ff3
 #ifdef USE_COMP
44a21a8d
 typedef enum comp_methods { COMP_NONE, COMP_SIGCOMP, COMP_SERGZ } comp_methods_t;
7a068ff3
 #endif
4e2fdd79
 
62d9eb79
 typedef struct ip_addr {
c391cc0d
 	unsigned int af;	/* address family: AF_INET6 or AF_INET */
 	unsigned int len;	/* address len, 16 or 4 */
 
53c7e0f1
 	/* 64 bits aligned address */
4e2fdd79
 	union {
8aeb47e2
 		unsigned long  addrl[16/sizeof(long)]; /* long format*/
4e2fdd79
 		unsigned int   addr32[4];
 		unsigned short addr16[8];
 		unsigned char  addr[16];
 	}u;
62d9eb79
 } ip_addr_t;
4e2fdd79
 
62d9eb79
 typedef struct net {
4e2fdd79
 	struct ip_addr ip;
 	struct ip_addr mask;
62d9eb79
 } sr_net_t;
4e2fdd79
 
44a21a8d
 typedef union sockaddr_union{
c391cc0d
 	struct sockaddr     s;
 	struct sockaddr_in  sin;
 	struct sockaddr_in6 sin6;
d13f863e
 	struct sockaddr_storage sas;
44a21a8d
 } sr_sockaddr_union_t;
4e2fdd79
 
9f4c52ce
 
44a21a8d
 typedef enum si_flags {
b2aa704d
 	SI_NONE         = 0,
 	SI_IS_IP        = (1<<0),
 	SI_IS_LO        = (1<<1),
 	SI_IS_MCAST     = (1<<2),
 	SI_IS_ANY       = (1<<3),
 	SI_IS_MHOMED    = (1<<4),
e93640e6
 	SI_IS_VIRTUAL	= (1<<5),
44a21a8d
 } si_flags_t;
eb321e3f
 
62d9eb79
 typedef struct addr_info {
eb321e3f
 	str name; /* name - eg.: foo.bar or 10.0.0.1 */
 	struct ip_addr address; /*ip address */
 	str address_str;        /*ip address converted to string -- optimization*/
 	enum si_flags flags; /* SI_IS_IP | SI_IS_LO | SI_IS_MCAST */
 	union sockaddr_union su;
 	struct addr_info* next;
 	struct addr_info* prev;
62d9eb79
 } addr_info_t;
9f4c52ce
 
609061e9
 
62d9eb79
 typedef struct advertise_info {
574daa6d
 	str name; /* name - eg.: foo.bar or 10.0.0.1 */
 	unsigned short port_no;  /* port number */
1296bb22
 	short port_pad; /* padding field */
574daa6d
 	str port_no_str; /* port number converted to string -- optimization*/
 	str address_str;        /*ip address converted to string -- optimization*/
 	struct ip_addr address; /* ip address */
 	str sock_str; /* Socket proto, ip, and port as string */
62d9eb79
 } advertise_info_t;
609061e9
 
62d9eb79
 typedef struct socket_info {
36ef0329
 	int socket;
61b32b46
 	int gindex; /* global index in the lists of all sockets */
36ef0329
 	str name; /* name - eg.: foo.bar or 10.0.0.1 */
 	struct ip_addr address; /* ip address */
eb321e3f
 	str address_str;        /*ip address converted to string -- optimization*/
36ef0329
 	str port_no_str; /* port number converted to string -- optimization*/
2ba73117
 	enum si_flags flags; /* SI_IS_IP | SI_IS_LO | SI_IS_MCAST */
c391cc0d
 	union sockaddr_union su;
9f4c52ce
 	struct socket_info* next;
 	struct socket_info* prev;
dd4ffbb7
 	unsigned short port_no;  /* port number */
 	char proto; /* tcp or udp*/
1296bb22
 	char proto_pad0; /* padding field */
 	short proto_pad1; /* padding field */
bc4ee022
 	str sock_str; /* Socket proto, ip, and port as string */
eb321e3f
 	struct addr_info* addr_info_lst; /* extra addresses (e.g. SCTP mh) */
edf5e385
 	int workers; /* number of worker processes for this socket */
 	int workers_tcpidx; /* index of workers in tcp children array */
76889dec
 	str sockname; /* socket name given in config listen value */
574daa6d
 	struct advertise_info useinfo; /* details to be used in SIP msg */
8b39cb6a
 #ifdef USE_MCAST
 	str mcast; /* name of interface that should join multicast group*/
 #endif /* USE_MCAST */
62d9eb79
 } socket_info_t;
 
 
 /* send flags */
44a21a8d
 typedef enum send_flags {
d09098cc
 	SND_F_FORCE_CON_REUSE   = (1 << 0), /* reuse an existing connection or fail */
 	SND_F_CON_CLOSE         = (1 << 1), /* close the connection after sending */
 	SND_F_FORCE_SOCKET      = (1 << 2), /* send socket in dst is forced */
44a21a8d
 } send_flags_t;
62d9eb79
 
 typedef struct snd_flags {
 	unsigned short f;          /* snd flags */
29758a66
 	unsigned short blst_imask; /* blocklist ignore mask */
62d9eb79
 } snd_flags_t;
36ef0329
 
0792f6e5
 /* recv flags */
 typedef enum recv_flags {
f86ced04
 	RECV_F_INTERNAL     = (1 << 0), /* message dispatched internally */
 	RECV_F_PREROUTING   = (1 << 1), /* message in pre-routing */
0792f6e5
 } recv_flags_t;
4e2fdd79
 
62d9eb79
 typedef struct receive_info {
f2f969dd
 	struct ip_addr src_ip;
 	struct ip_addr dst_ip;
4c4e112f
 	unsigned short src_port; /* host byte order */
 	unsigned short dst_port; /* host byte order */
c030910c
 	int proto_reserved1; /* tcp stores the connection id here */
f2f969dd
 	int proto_reserved2;
53c7e0f1
 	union sockaddr_union src_su; /* useful for replies*/
c391cc0d
 	struct socket_info* bind_address; /* sock_info structure on which
 										* the msg was received */
0792f6e5
 	recv_flags_t rflags; /* flags */
dd4ffbb7
 	char proto;
7a068ff3
 #ifdef USE_COMP
1296bb22
 	char proto_pad0;  /* padding field */
7a068ff3
 	short comp; /* compression */
1296bb22
 #else
 	char proto_pad0;  /* padding field */
 	short proto_pad1; /* padding field */
7a068ff3
 #endif
f2f969dd
 	/* no need for dst_su yet */
62d9eb79
 } receive_info_t;
 
 
 typedef struct dest_info {
 	struct socket_info* send_sock;
 	union sockaddr_union to;
 	int id; /* tcp stores the connection id here */
 	snd_flags_t send_flags;
1296bb22
 	char proto;
62d9eb79
 #ifdef USE_COMP
1296bb22
 	char proto_pad0;  /* padding field */
62d9eb79
 	short comp;
1296bb22
 #else
 	char proto_pad0;  /* padding field */
 	short proto_pad1; /* padding field */
62d9eb79
 #endif
 } dest_info_t;
f2f969dd
 
609061e9
 
2bb8598e
 typedef struct ksr_coninfo {
 	ip_addr_t src_ip;
 	ip_addr_t dst_ip;
 	unsigned short src_port; /* host byte order */
 	unsigned short dst_port; /* host byte order */
 	int proto;
 	socket_info_t *csocket;
 } ksr_coninfo_t;
 
b57a2d78
 typedef struct sr_net_info {
 	str data;
d5e29886
 	unsigned int bufsize;
62d9eb79
 	receive_info_t* rcv;
 	dest_info_t* dst;
b57a2d78
 } sr_net_info_t;
f2f969dd
 
bbcbd691
 sr_net_info_t *ksr_evrt_rcvnetinfo_get(void);
c391cc0d
 
8cf5dde5
 #define SND_FLAGS_INIT(sflags) \
 	do{ \
 		(sflags)->f=0; \
 		(sflags)->blst_imask=0; \
 	}while(0)
 
c391cc0d
 
8cf5dde5
 #define SND_FLAGS_OR(dst, src1, src2) \
 	do{ \
 		(dst)->f = (src1)->f | (src2)->f; \
 		(dst)->blst_imask = (src1)->blst_imask | (src2)->blst_imask; \
 	}while(0)
 
c391cc0d
 
8cf5dde5
 #define SND_FLAGS_AND(dst, src1, src2) \
 	do{ \
 		(dst)->f = (src1)->f & (src2)->f; \
 		(dst)->blst_imask = (src1)->blst_imask & (src2)->blst_imask; \
 	}while(0)
67c9277a
 
c391cc0d
 
eb321e3f
 /* list of names for multi-homed sockets that need to bind on
  * multiple addresses in the same time (sctp ) */
62d9eb79
 typedef struct name_lst {
6cd48835
 	char* name;
eb321e3f
 	struct name_lst* next;
 	int flags;
62d9eb79
 } name_lst_t;
eb321e3f
 
 
62d9eb79
 typedef struct socket_id {
eb321e3f
 	struct name_lst* addr_lst; /* address list, the first one must
c391cc0d
 								* be present and is the main one
 								* (in case of multihoming sctp) */
eb321e3f
 	int flags;
6cd48835
 	int proto;
 	int port;
 	struct socket_id* next;
62d9eb79
 } socket_id_t;
6cd48835
 
 
741db913
 /* len of the sockaddr */
087d0976
 #ifdef HAVE_SOCKADDR_SA_LEN
741db913
 #define sockaddru_len(su)	((su).s.sa_len)
 #else
 #define sockaddru_len(su)	\
c391cc0d
 	(((su).s.sa_family==AF_INET6)?sizeof(struct sockaddr_in6):\
 		sizeof(struct sockaddr_in))
087d0976
 #endif /* HAVE_SOCKADDR_SA_LEN*/
c391cc0d
 
4e2fdd79
 /* inits an ip_addr with the addr. info from a hostent structure
  * ip = struct ip_addr*
  * he= struct hostent*
  */
 #define hostent2ip_addr(ip, he, addr_no) \
 	do{ \
 		(ip)->af=(he)->h_addrtype; \
 		(ip)->len=(he)->h_length;  \
 		memcpy((ip)->u.addr, (he)->h_addr_list[(addr_no)], (ip)->len); \
 	}while(0)
 
 
 /* gets the protocol family corresponding to a specific address family
  * ( PF_INET - AF_INET, PF_INET6 - AF_INET6, af for others)
  */
 #define AF2PF(af)   (((af)==AF_INET)?PF_INET:((af)==AF_INET6)?PF_INET6:(af))
 
 
dc4cdb29
 struct net* mk_new_net(struct ip_addr* ip, struct ip_addr* mask);
 struct net* mk_new_net_bitlen(struct ip_addr* ip, unsigned int bitlen);
 int mk_net(struct net* n, struct ip_addr* ip, struct ip_addr* mask);
 int mk_net_bitlen(struct net* n, struct ip_addr* ip, unsigned int bitlen);
 int mk_net_str(struct net* dst, str* s);
4e2fdd79
 
9c01c860
 void print_ip(char* prefix, struct ip_addr* ip, char* suffix);
4e2fdd79
 void stdout_print_ip(struct ip_addr* ip);
 void print_net(struct net* net);
 
a077f5e1
 char* get_proto_name(unsigned int proto);
 #define proto2a get_proto_name
10117562
 
b81dff6a
 int get_valid_proto_string(unsigned int iproto, int utype, int vtype,
 		str *sproto);
10117562
 
2ba73117
 #ifdef USE_MCAST
 /* Returns 1 if the given address is a multicast address */
 int is_mcast(struct ip_addr* ip);
 #endif /* USE_MCAST */
4e2fdd79
 
205fcb02
 /* returns 1 if the given ip address is INADDR_ANY or IN6ADDR_ANY,
  * 0 otherwise */
f0273b46
 inline static int ip_addr_any(const struct ip_addr* ip)
205fcb02
 {
 	int r;
 	int l;
c391cc0d
 
205fcb02
 	l=ip->len/4;
 	for (r=0; r<l; r++)
 		if (ip->u.addr32[r]!=0)
 			return 0;
 	return 1;
 }
 
 
1571613c
 /* returns 1 if the given ip address is a loopback address
  * 0 otherwise */
f0273b46
 inline static int ip_addr_loopback(const struct ip_addr* ip)
1571613c
 {
f52aa05b
 	if (ip->af==AF_INET)
1571613c
 		return ip->u.addr32[0]==htonl(INADDR_LOOPBACK);
f52aa05b
 	else if (ip->af==AF_INET6)
8a2ca526
 		return IN6_IS_ADDR_LOOPBACK((struct in6_addr*)ip->u.addr32);
1571613c
 	return 0;
 }
 
 
a288ee34
 /* creates an ANY ip_addr (filled with 0, af and len properly set) */
 inline static void ip_addr_mk_any(int af, struct ip_addr* ip)
 {
 	ip->af=af;
 	if (likely(af==AF_INET)){
 		ip->len=4;
 		ip->u.addr32[0]=0;
 	}
 	else{
 		ip->len=16;
 #if (defined (ULONG_MAX) && ULONG_MAX > 4294967295) || defined LP64
 		/* long is 64 bits */
 		ip->u.addrl[0]=0;
 		ip->u.addrl[1]=0;
 #else
 		ip->u.addr32[0]=0;
 		ip->u.addr32[1]=0;
 		ip->u.addr32[2]=0;
 		ip->u.addr32[3]=0;
 #endif /* ULONG_MAX */
 	}
 }
 
c391cc0d
 
 /* returns 1 if ip & net.mask == net.ip ; 0 otherwise & -1 on error
  * [ diff. address families ]) */
f0273b46
 inline static int matchnet(const struct ip_addr* ip, const struct net* net)
4e2fdd79
 {
5b532c7f
 	unsigned int r;
f701ac7d
 
4e2fdd79
 	if (ip->af == net->ip.af){
 		for(r=0; r<ip->len/4; r++){ /* ipv4 & ipv6 addresses are
c391cc0d
 									 * all multiple of 4*/
 			if ((ip->u.addr32[r]&net->mask.u.addr32[r])
 					!=net->ip.u.addr32[r]) {
4e2fdd79
 				return 0;
 			}
 		}
 		return 1;
 	};
 	return -1;
 }
 
 
57e2cd15
 /* inits an ip_addr pointer from a sockaddr structure*/
f0273b46
 static inline void sockaddr2ip_addr(struct ip_addr* ip, const struct sockaddr* sa)
57e2cd15
 {
 	switch(sa->sa_family){
c391cc0d
 		case AF_INET:
57e2cd15
 			ip->af=AF_INET;
 			ip->len=4;
 			memcpy(ip->u.addr, &((struct sockaddr_in*)sa)->sin_addr, 4);
 			break;
c391cc0d
 		case AF_INET6:
57e2cd15
 			ip->af=AF_INET6;
 			ip->len=16;
 			memcpy(ip->u.addr, &((struct sockaddr_in6*)sa)->sin6_addr, 16);
 			break;
c391cc0d
 		default:
44f49c06
 			LM_CRIT("unknown address family %d\n", sa->sa_family);
57e2cd15
 	}
 }
 
 
0c5da34b
 /* compare 2 ip_addrs (both args are pointers)*/
 #define ip_addr_cmp(ip1, ip2) \
 	(((ip1)->af==(ip2)->af)&& \
c391cc0d
 		(memcmp((ip1)->u.addr, (ip2)->u.addr, (ip1)->len)==0))
0c5da34b
 
 
 /* compare 2 sockaddr_unions */
e18010e9
 static inline int su_cmp(const union sockaddr_union* s1,
c391cc0d
 		const union sockaddr_union* s2)
0c5da34b
 {
 	if (s1->s.sa_family!=s2->s.sa_family) return 0;
 	switch(s1->s.sa_family){
 		case AF_INET:
 			return (s1->sin.sin_port==s2->sin.sin_port)&&
c391cc0d
 				(memcmp(&s1->sin.sin_addr, &s2->sin.sin_addr, 4)==0);
0c5da34b
 		case AF_INET6:
 			return (s1->sin6.sin6_port==s2->sin6.sin6_port)&&
c391cc0d
 				(memcmp(&s1->sin6.sin6_addr, &s2->sin6.sin6_addr, 16)==0);
0c5da34b
 		default:
44f49c06
 			LM_CRIT("unknown address family %d\n", s1->s.sa_family);
0c5da34b
 			return 0;
 	}
 }
 
 
4c4e112f
 /* gets the port number (host byte order) */
e18010e9
 static inline unsigned short su_getport(const union sockaddr_union* su)
0c5da34b
 {
 	switch(su->s.sa_family){
 		case AF_INET:
4c4e112f
 			return ntohs(su->sin.sin_port);
0c5da34b
 		case AF_INET6:
4c4e112f
 			return ntohs(su->sin6.sin6_port);
0c5da34b
 		default:
44f49c06
 			LM_CRIT("unknown address family %d\n", su->s.sa_family);
0c5da34b
 			return 0;
 	}
 }
 
 
4c4e112f
 /* sets the port number (host byte order) */
20581c5a
 static inline void su_setport(union sockaddr_union* su, unsigned short port)
 {
 	switch(su->s.sa_family){
 		case AF_INET:
4c4e112f
 			su->sin.sin_port=htons(port);
20581c5a
 			break;
 		case AF_INET6:
c391cc0d
 			su->sin6.sin6_port=htons(port);
 			break;
20581c5a
 		default:
44f49c06
 			LM_CRIT("unknown address family %d\n", su->s.sa_family);
20581c5a
 	}
 }
 
 
4e2fdd79
 /* inits an ip_addr pointer from a sockaddr_union ip address */
f0273b46
 static inline void su2ip_addr(struct ip_addr* ip, const union sockaddr_union* su)
4e2fdd79
 {
 	switch(su->s.sa_family){
c391cc0d
 		case AF_INET:
 			ip->af=AF_INET;
 			ip->len=4;
 			memcpy(ip->u.addr, &su->sin.sin_addr, 4);
 			break;
 		case AF_INET6:
 			ip->af=AF_INET6;
 			ip->len=16;
 			memcpy(ip->u.addr, &su->sin6.sin6_addr, 16);
 			break;
 		default:
 			LM_CRIT("unknown address family %d\n", su->s.sa_family);
dfe8db75
 			memset(ip, 0, sizeof(ip_addr_t));
4e2fdd79
 	}
 }
 
 
156b277b
 /* ip_addr2su -> the same as init_su*/
 #define ip_addr2su init_su
4e2fdd79
 
c391cc0d
 /* inits a struct sockaddr_union from a struct ip_addr and a port no
4c4e112f
  * returns 0 if ok, -1 on error (unknown address family)
  * the port number is in host byte order */
4e2fdd79
 static inline int init_su( union sockaddr_union* su,
c391cc0d
 		struct ip_addr* ip,
 		unsigned short port )
4e2fdd79
 {
0fcf9d39
 	memset(su, 0, sizeof(union sockaddr_union));/*needed on freebsd*/
4e2fdd79
 	su->s.sa_family=ip->af;
 	switch(ip->af){
c391cc0d
 		case	AF_INET6:
 			memcpy(&su->sin6.sin6_addr, ip->u.addr, ip->len);
 #ifdef HAVE_SOCKADDR_SA_LEN
4e2fdd79
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
c391cc0d
 #endif
 			su->sin6.sin6_port=htons(port);
 			break;
 		case AF_INET:
 			memcpy(&su->sin.sin_addr, ip->u.addr, ip->len);
 #ifdef HAVE_SOCKADDR_SA_LEN
4e2fdd79
 			su->sin.sin_len=sizeof(struct sockaddr_in);
c391cc0d
 #endif
 			su->sin.sin_port=htons(port);
 			break;
 		default:
 			LM_CRIT("unknown address family %d\n", ip->af);
 			return -1;
4e2fdd79
 	}
 	return 0;
 }
 
 
6bc40dea
 /* inits a struct sockaddr_union from a struct hostent, an address index in
4c4e112f
  * the hostent structure and a port no. (host byte order)
4e2fdd79
  * WARNING: no index overflow  checks!
  * returns 0 if ok, -1 on error (unknown address family) */
2d1b442f
 int hostent2su(union sockaddr_union* su,
c391cc0d
 		struct hostent* he,
 		unsigned int idx,
2d1b442f
 		unsigned short port);
4e2fdd79
 
 
5ffc426e
 /* maximum size of a str returned by ip_addr2str */
22a72f3a
 /* POSIX INET6_ADDRSTRLEN (RFC 4291 section 2.2) - IPv6 with IPv4 tunneling
  * (39): 1234:5678:9012:3456:7890:1234:5678:9012
  * (45): ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255 */
 #ifdef INET6_ADDRSTRLEN
 #define IP6_MAX_STR_SIZE (INET6_ADDRSTRLEN-1)
 #else
 #define IP6_MAX_STR_SIZE 45
 #endif
 /*123.456.789.123*/
 #ifdef INET_ADDRSTRLEN
 #define IP4_MAX_STR_SIZE (INET_ADDRSTRLEN-1)
 #else
 #define IP4_MAX_STR_SIZE 15
 #endif
5ffc426e
 
 /* converts a raw ipv6 addr (16 bytes) to ascii */
2d1b442f
 int ip6tosbuf(unsigned char* ip6, char* buff, int len);
5ffc426e
 
 
 /* converts a raw ipv4 addr (4 bytes) to ascii */
2d1b442f
 int ip4tosbuf(unsigned char* ip4, char* buff, int len);
5ffc426e
 
 
 /* fast ip_addr -> string converter;
  * returns number of bytes written in buf on success, <=0 on error
  * The buffer must have enough space to hold the maximum size ip address
  *  of the corresponding address (see IP[46] above) or else the function
  *  will return error (no detailed might fit checks are made, for example
  *   if len==7 the function will fail even for 1.2.3.4).
  */
2d1b442f
 int ip_addr2sbuf(struct ip_addr* ip, char* buff, int len);
 
5ffc426e
 
cdafc5a6
 /* same as ip_addr2sbuf, but with [  ] around IPv6 addresses */
2d1b442f
 int ip_addr2sbufz(struct ip_addr* ip, char* buff, int len);
cdafc5a6
 
5ffc426e
 
 /* maximum size of a str returned by ip_addr2a (including \0) */
 #define IP_ADDR_MAX_STR_SIZE (IP6_MAX_STR_SIZE+1) /* ip62ascii +  \0*/
cdafc5a6
 #define IP_ADDR_MAX_STRZ_SIZE (IP6_MAX_STR_SIZE+3) /* ip62ascii + [ + ] + \0*/
2d1b442f
 
5ffc426e
 /* fast ip_addr -> string converter;
  * it uses an internal buffer
  */
2d1b442f
 char* ip_addr2a(struct ip_addr* ip);
4e2fdd79
 
c391cc0d
 
b7bc7a54
 /* full address in text representation, including [] for ipv6 */
2d1b442f
 char* ip_addr2strz(struct ip_addr* ip);
b7bc7a54
 
4e2fdd79
 
5ffc426e
 #define SU2A_MAX_STR_SIZE  (IP6_MAX_STR_SIZE + 2 /* [] */+\
c391cc0d
 		1 /* : */ + USHORT2SBUF_MAX_LEN + 1 /* \0 */)
 
2d1b442f
 
5ffc426e
 /* returns an asciiz string containing the ip and the port
  *  (<ip_addr>:port or [<ipv6_addr>]:port)
  */
2d1b442f
 char* su2a(union sockaddr_union* su, int su_len);
5ffc426e
 
fabaa667
 #define SUIP2A_MAX_STR_SIZE  (IP6_MAX_STR_SIZE + 2 /* [] */ + 1 /* \0 */)
2d1b442f
 
fabaa667
 /* returns an asciiz string containing the ip
  *  (<ipv4_addr> or [<ipv6_addr>])
  */
2d1b442f
 char* suip2a(union sockaddr_union* su, int su_len);
fabaa667
 
5ffc426e
 
4c9f3fde
 /* converts an ip_addr structure to a hostent, returns pointer to internal
  * statical structure */
2d1b442f
 struct hostent* ip_addr2he(str* name, struct ip_addr* ip);
2f0f1a30
 
 
 /* init a dest_info structure */
 #define init_dest_info(dst) \
 	do{ \
7a068ff3
 		memset((dst), 0, sizeof(struct dest_info)); \
c391cc0d
 	} while(0)
7a068ff3
 
 
 /* init a dest_info structure from a recv_info structure */
 inline static void init_dst_from_rcv(struct dest_info* dst,
f0273b46
 		const struct receive_info* rcv)
7a068ff3
 {
c391cc0d
 	dst->send_sock=rcv->bind_address;
 	dst->to=rcv->src_su;
 	dst->id=rcv->proto_reserved1;
 	dst->proto=rcv->proto;
 	dst->send_flags.f=0;
 	dst->send_flags.blst_imask=0;
7a068ff3
 #ifdef USE_COMP
c391cc0d
 	dst->comp=rcv->comp;
7a068ff3
 #endif
 }
 
c391cc0d
 
c1a4788c
 /**
  * match ip address with net address and bitmask
  * - return 0 on match, -1 otherwise
  */
 int ip_addr_match_net(ip_addr_t *iaddr, ip_addr_t *naddr, int mask);
7a068ff3
 
c725f1de
 int si_get_signaling_data(struct socket_info *si, str **addr, str **port);
 
4e2fdd79
 #endif