1 /*
2  * $Id: udp_trsp.h 1048 2008-07-15 18:48:07Z sayer $
3  *
4  * Copyright (C) 2007 Raphael Coeffic
5  *
6  * This file is part of SEMS, a free SIP media server.
7  *
8  * SEMS is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version. This program is released under
12  * the GPL with the additional exemption that compiling, linking,
13  * and/or using OpenSSL is allowed.
14  *
15  * For a license to use the SEMS software under conditions
16  * other than those described here, or to purchase support for this
17  * software, please contact iptel.org by e-mail at the following addresses:
18  *    info@iptel.org
19  *
20  * SEMS is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28  */
29 #ifndef _udp_trsp_h_
30 #define _udp_trsp_h_
31 
32 #include "transport.h"
33 
34 /**
35  * Maximum message length for UDP
36  * not including terminating '\0'
37  */
38 #define MAX_UDP_MSGLEN 65535
39 
40 #include <sys/socket.h>
41 
42 #include <string>
43 using std::string;
44 
45 class udp_trsp_socket: public trsp_socket
46 {
47     int sendto(const sockaddr_storage* sa, const char* msg, const int msg_len);
48     int sendmsg(const sockaddr_storage* sa, const char* msg, const int msg_len);
49 
50 public:
51     udp_trsp_socket(unsigned short if_num, unsigned int opts,
52 		    unsigned int sys_if_idx = 0)
trsp_socket(if_num,opts,sys_if_idx)53 	: trsp_socket(if_num,opts,sys_if_idx) {}
54 
~udp_trsp_socket()55     ~udp_trsp_socket() {}
56 
57     /**
58      * Binds the transport socket to an address
59      * @return -1 if error(s) occured.
60      */
61     virtual int bind(const string& address, unsigned short port);
62 
get_transport()63     const char* get_transport() const
64     { return "udp"; }
65 
66     int set_recvbuf_size(int rcvbuf_size);
67 
68     /**
69      * Sends a message.
70      * @return -1 if error(s) occured.
71      */
72     int send(const sockaddr_storage* sa, const char* msg,
73 	     const int msg_len, unsigned int flags);
74 };
75 
76 class udp_trsp: public transport
77 {
78 protected:
79     /** @see AmThread */
80     void run();
81     /** @see AmThread */
82     void on_stop();
83 
84 public:
85     /** @see transport */
86     udp_trsp(udp_trsp_socket* sock);
87     ~udp_trsp();
88 };
89 
90 #endif
91 
92 /** EMACS **
93  * Local variables:
94  * mode: c++
95  * c-basic-offset: 4
96  * End:
97  */
98