socket_info.h
6806e46a
 /*
ab63a9a6
  * find & manage listen addresses 
  *
53c7e0f1
  * Copyright (C) 2001-2003 FhG Fokus
ab63a9a6
  *
6806e46a
  * This file is part of Kamailio, a free SIP server.
ab63a9a6
  *
6806e46a
  * Kamailio is free software; you can redistribute it and/or modify
ab63a9a6
  * 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,
ab63a9a6
  * 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 this program; if not, write to" the Free Software 
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
ab63a9a6
  */
6806e46a
 
 /*! \file
  * \brief Kamailio core :: listen address
  * This file contains code that initializes and handles Kamailio listen addresses
ab63a9a6
  * lists (struct socket_info). It is used mainly on startup.
  * 
  */
 
 
 #ifndef socket_info_h
 #define socket_info_h
 
 #include "ip_addr.h" 
 #include "dprint.h"
d5707fe1
 #include "globals.h"
eb321e3f
 
14839e8f
 /* This macro evaluates to the maximum length of string buffer needed to print
  * the text description of any socket, not counting the terminating zero added
  * by socket2str */
 #define MAX_SOCKET_STR (sizeof("unknown") - 1 + IP_ADDR_MAX_STR_SIZE + \
426c6b7e
 	INT2STR_MAX_LEN + 2 + 2)
14839e8f
 
 int socket2str(char* s, int* len, struct socket_info* si);
574daa6d
 int socketinfo2str(char* s, int* len, struct socket_info* si, int mode);
eb321e3f
 
aaec127f
 /* Helper macro that results in the default port based on the protocol */
 #define proto_default_port(proto) ((proto==PROTO_TLS)?SIPS_PORT:SIP_PORT)
eb321e3f
 
ab63a9a6
 /* struct socket_info is defined in ip_addr.h */
 
ee7f9cb4
 extern struct socket_info* udp_listen;
ab63a9a6
 #ifdef USE_TCP
ee7f9cb4
 extern struct socket_info* tcp_listen;
ab63a9a6
 #endif
 #ifdef USE_TLS
ee7f9cb4
 extern struct socket_info* tls_listen;
ab63a9a6
 #endif
c3611173
 #ifdef USE_SCTP
 extern struct socket_info* sctp_listen;
 #endif
 
 extern enum sip_protos nxt_proto[PROTO_LAST+1];
 
ab63a9a6
 
 
dcb59e67
 /* flags for finding out the address types */
c3611173
 #define SOCKET_T_IPV4  1
 #define SOCKET_T_IPV6  2
 #define SOCKET_T_UDP   4
 #define SOCKET_T_TCP   8
 #define SOCKET_T_TLS  16
 #define SOCKET_T_SCTP 32
dcb59e67
 
2cfcc6bb
 extern int socket_types;
dcb59e67
 
abb01fb4
 void init_proto_order(void);
c3611173
 
eb321e3f
 int add_listen_iface(char* name, struct name_lst* nlst,
 						unsigned short port, unsigned short proto,
 						enum si_flags flags);
574daa6d
 int add_listen_advertise_iface(char* name, struct name_lst* nlst,
 						unsigned short port, unsigned short proto,
 						char *useaddr, unsigned short useport,
 						enum si_flags flags);
abb01fb4
 int fix_all_socket_lists(void);
 void print_all_socket_lists(void);
 void print_aliases(void);
ab63a9a6
 
463fdeec
 struct socket_info* grep_sock_info(str* host, unsigned short port,
 										unsigned short proto);
2bf9371d
 struct socket_info* grep_sock_info_by_port(unsigned short port,
 											unsigned short proto);
a35ad52c
 struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
 												unsigned short proto);
ab63a9a6
 
00c747a1
 struct socket_info** get_sock_info_list(unsigned short proto);
c3611173
 
df088fb8
 int parse_phostport(char* s, char** host, int* hlen,
537ce843
 								 int* port, int* proto);
 
6335d07c
 int parse_proto(unsigned char* s, long len, int* proto);
 
132df8d6
 char* get_valid_proto_name(unsigned short proto);
 
ab63a9a6
 /* helper function:
  * returns next protocol, if the last one is reached return 0
c3611173
  * useful for cycling on the supported protocols
  * order: udp, tcp, tls, sctp */
ab63a9a6
 static inline int next_proto(unsigned short proto)
 {
c3611173
 	if (proto>PROTO_LAST)
5e8e40a4
 		LM_ERR("unknown proto %d\n", proto);
c3611173
 	else
 		return nxt_proto[proto];
ab63a9a6
 	return 0;
 }
 
 
 
 /* gets first non-null socket_info structure
53c7e0f1
  * (useful if for. e.g we are not listening on any udp sockets )
ab63a9a6
  */
abb01fb4
 inline static struct socket_info* get_first_socket(void)
ab63a9a6
 {
 	if (udp_listen) return udp_listen;
 #ifdef USE_TCP
 	else if (tcp_listen) return tcp_listen;
c3611173
 #endif
 #ifdef USE_SCTP
 	else if (sctp_listen) return sctp_listen;
 #endif
 #ifdef USE_TCP
ab63a9a6
 #ifdef USE_TLS
 	else if (tls_listen) return tls_listen;
 #endif
 #endif
 	return 0;
 }
 
6335d07c
 /* structure to break down 'proto:host:port' */
 typedef struct _sr_phostp {
 	int proto;
 	str host;
 	int port;
 } sr_phostp_t;
 
 struct socket_info* lookup_local_socket(str *phostp);
ab63a9a6
 
 #endif