• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

socket_info.h

00001 /* $Id$
00002  *
00003  * find & manage listen addresses 
00004  *
00005  * Copyright (C) 2001-2003 FhG Fokus
00006  *
00007  * This file is part of ser, a free SIP server.
00008  *
00009  * ser is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * For a license to use the ser software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact iptel.org by e-mail at the following addresses:
00017  *    info@iptel.org
00018  *
00019  * ser is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License 
00025  * along with this program; if not, write to" the Free Software 
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  */
00028 /*
00029  * This file contains code that initializes and handles ser listen addresses
00030  * lists (struct socket_info). It is used mainly on startup.
00031  * 
00032  * History:
00033  * --------
00034  *  2003-10-22  created by andrei
00035  *  2008-08-08  sctp support (andrei)
00036  */
00037 
00038 
00039 #ifndef socket_info_h
00040 #define socket_info_h
00041 
00042 #include "ip_addr.h" 
00043 #include "dprint.h"
00044 #include "globals.h"
00045 
00046 /* This macro evaluates to the maximum length of string buffer needed to print
00047  * the text description of any socket, not counting the terminating zero added
00048  * by socket2str */
00049 #define MAX_SOCKET_STR (sizeof("unknown") - 1 + IP_ADDR_MAX_STR_SIZE + \
00050         INT2STR_MAX_LEN + 2 + 2)
00051 
00052 int socket2str(char* s, int* len, struct socket_info* si);
00053 int socketinfo2str(char* s, int* len, struct socket_info* si, int mode);
00054 
00055 
00056 /* struct socket_info is defined in ip_addr.h */
00057 
00058 extern struct socket_info* udp_listen;
00059 #ifdef USE_TCP
00060 extern struct socket_info* tcp_listen;
00061 #endif
00062 #ifdef USE_TLS
00063 extern struct socket_info* tls_listen;
00064 #endif
00065 #ifdef USE_SCTP
00066 extern struct socket_info* sctp_listen;
00067 #endif
00068 
00069 extern enum sip_protos nxt_proto[PROTO_LAST+1];
00070 
00071 
00072 
00073 /* flags for finding out the address types */
00074 #define SOCKET_T_IPV4  1
00075 #define SOCKET_T_IPV6  2
00076 #define SOCKET_T_UDP   4
00077 #define SOCKET_T_TCP   8
00078 #define SOCKET_T_TLS  16
00079 #define SOCKET_T_SCTP 32
00080 
00081 extern int socket_types;
00082 
00083 void init_proto_order(void);
00084 
00085 int add_listen_iface(char* name, struct name_lst* nlst,
00086                                                 unsigned short port, unsigned short proto,
00087                                                 enum si_flags flags);
00088 int add_listen_advertise_iface(char* name, struct name_lst* nlst,
00089                                                 unsigned short port, unsigned short proto,
00090                                                 char *useaddr, unsigned short useport,
00091                                                 enum si_flags flags);
00092 int fix_all_socket_lists(void);
00093 void print_all_socket_lists(void);
00094 void print_aliases(void);
00095 
00096 struct socket_info* grep_sock_info(str* host, unsigned short port,
00097                                                                                 unsigned short proto);
00098 struct socket_info* grep_sock_info_by_port(unsigned short port,
00099                                                                                         unsigned short proto);
00100 struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
00101                                                                                                 unsigned short proto);
00102 
00103 struct socket_info** get_sock_info_list(unsigned short proto);
00104 
00105 int parse_phostport(char* s, char** host, int* hlen,
00106                                                                  int* port, int* proto);
00107 
00108 /* helper function:
00109  * returns next protocol, if the last one is reached return 0
00110  * useful for cycling on the supported protocols
00111  * order: udp, tcp, tls, sctp */
00112 static inline int next_proto(unsigned short proto)
00113 {
00114         if (proto>PROTO_LAST)
00115                         LOG(L_ERR, "ERROR: next_proto: unknown proto %d\n", proto);
00116         else
00117                 return nxt_proto[proto];
00118         return 0;
00119 }
00120 
00121 
00122 
00123 /* gets first non-null socket_info structure
00124  * (useful if for. e.g we are not listening on any udp sockets )
00125  */
00126 inline static struct socket_info* get_first_socket(void)
00127 {
00128         if (udp_listen) return udp_listen;
00129 #ifdef USE_TCP
00130         else if (tcp_listen) return tcp_listen;
00131 #endif
00132 #ifdef USE_SCTP
00133         else if (sctp_listen) return sctp_listen;
00134 #endif
00135 #ifdef USE_TCP
00136 #ifdef USE_TLS
00137         else if (tls_listen) return tls_listen;
00138 #endif
00139 #endif
00140         return 0;
00141 }
00142 
00143 
00144 #endif

Generated on Tue May 22 2012 13:10:15 for SIP Router by  doxygen 1.7.1