socket_info.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* $Id$
  2. *
  3. * find & manage listen addresses
  4. *
  5. * Copyright (C) 2001-2003 FhG Fokus
  6. *
  7. * This file is part of ser, a free SIP server.
  8. *
  9. * ser is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * For a license to use the ser software under conditions
  15. * other than those described here, or to purchase support for this
  16. * software, please contact iptel.org by e-mail at the following addresses:
  17. * [email protected]
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to" the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. */
  28. /*
  29. * This file contains code that initializes and handles ser listen addresses
  30. * lists (struct socket_info). It is used mainly on startup.
  31. *
  32. * History:
  33. * --------
  34. * 2003-10-22 created by andrei
  35. * 2008-08-08 sctp support (andrei)
  36. */
  37. #ifndef socket_info_h
  38. #define socket_info_h
  39. #include "ip_addr.h"
  40. #include "dprint.h"
  41. #include "globals.h"
  42. /* struct socket_info is defined in ip_addr.h */
  43. extern struct socket_info* udp_listen;
  44. #ifdef USE_TCP
  45. extern struct socket_info* tcp_listen;
  46. #endif
  47. #ifdef USE_TLS
  48. extern struct socket_info* tls_listen;
  49. #endif
  50. #ifdef USE_SCTP
  51. extern struct socket_info* sctp_listen;
  52. #endif
  53. extern enum sip_protos nxt_proto[PROTO_LAST+1];
  54. /* flags for finding out the address types */
  55. #define SOCKET_T_IPV4 1
  56. #define SOCKET_T_IPV6 2
  57. #define SOCKET_T_UDP 4
  58. #define SOCKET_T_TCP 8
  59. #define SOCKET_T_TLS 16
  60. #define SOCKET_T_SCTP 32
  61. extern int socket_types;
  62. void init_proto_order();
  63. int add_listen_iface(char* name, struct name_lst* nlst,
  64. unsigned short port, unsigned short proto,
  65. enum si_flags flags);
  66. int fix_all_socket_lists();
  67. void print_all_socket_lists();
  68. void print_aliases();
  69. struct socket_info* grep_sock_info(str* host, unsigned short port,
  70. unsigned short proto);
  71. struct socket_info* grep_sock_info_by_port(unsigned short port,
  72. unsigned short proto);
  73. struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
  74. unsigned short proto);
  75. /* helper function:
  76. * returns next protocol, if the last one is reached return 0
  77. * useful for cycling on the supported protocols
  78. * order: udp, tcp, tls, sctp */
  79. static inline int next_proto(unsigned short proto)
  80. {
  81. if (proto>PROTO_LAST)
  82. LOG(L_ERR, "ERROR: next_proto: unknown proto %d\n", proto);
  83. else
  84. return nxt_proto[proto];
  85. return 0;
  86. }
  87. /* gets first non-null socket_info structure
  88. * (useful if for. e.g we are not listening on any udp sockets )
  89. */
  90. inline static struct socket_info* get_first_socket()
  91. {
  92. if (udp_listen) return udp_listen;
  93. #ifdef USE_TCP
  94. else if (tcp_listen) return tcp_listen;
  95. #endif
  96. #ifdef USE_SCTP
  97. else if (sctp_listen) return sctp_listen;
  98. #endif
  99. #ifdef USE_TCP
  100. #ifdef USE_TLS
  101. else if (tls_listen) return tls_listen;
  102. #endif
  103. #endif
  104. return 0;
  105. }
  106. #endif