1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301 USA. *
19 *======================================================================*/
20 #ifndef __LWES_NET_FUNCTIONS_H
21 #define __LWES_NET_FUNCTIONS_H
27 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
34 #include "lwes_types.h"
40 /*! \file lwes_net_functions.h
41 * \brief Functions for dealing with multicast channels
44 /*! \struct lwes_net_connection lwes_net_functions.h
45 * \brief IP Multicast Channel object
47 struct lwes_net_connection
49 /*! low level socket descriptor */
52 /*! inet address for the multicast channel */
53 struct sockaddr_in mcast_addr
;
58 /*! inet address for the sender of this packet */
59 struct sockaddr_in sender_ip_addr
;
61 /*! used to stored the size of the above structure */
62 socklen_t sender_ip_socket_size
;
64 /*! boolean, will be TRUE if we have joined a multicast group.
65 we only join a multicast group if we are receiving packets */
69 /*! \brief Open a multicast channel
71 * \param[in] conn the multicast channel object to hole this connection
72 * \param[in] address the multicast IP address of the channel to connect to
73 * \param[in] iface the IP address of the network interface this channel shoul
75 * \param[in] port the multicast port of the channel to connect to
77 * \return 0 on success, a negative number on error
81 (struct lwes_net_connection
*conn
,
86 /*! \brief Close a multicast channel
88 * \param[in] conn the multicast channel object containing the
91 * \return 0 on success, a negative number on error
95 (struct lwes_net_connection
*conn
);
97 /*! \brief Get the current Time-To-Live on a multicast channel
99 * \param[in] conn the multicast channel to get the ttl for
101 * \returns the current ttl value on success, a negative number on error
105 (struct lwes_net_connection
*conn
);
107 /*! \brief Set a new Time-To-Live on a multicast channel
109 * \param[in] conn the multicast channel to get the ttl for
110 * \param[in] new_ttl the new ttl to set for outgoing packets
112 * \return 0 on success, a negative number on error
116 (struct lwes_net_connection
*conn
, int new_ttl
);
118 /*! \brief Get the socket file descriptor for the multicast channel
120 * \param[in] conn the multicast channel to get the socket file descriptor for
122 * \return the file descriptor on success, a negative number on error
126 (struct lwes_net_connection
*conn
);
128 /*! \brief Send bytes to the multicast channel
130 * \param[in] conn the multicast channel to send bytes to
131 * \param[in] bytes an array of bytes to send out on the channel
132 * \param[in] len the number of bytes from bytes to send out on the channel
134 * \return the number of bytes sent on success, a negative number on failure
138 (struct lwes_net_connection
*conn
,
142 /*! \brief Send bytes to a different multicast channel
144 * This can be used to send bytes out over an alternate channel, this will
145 * result in the creation and destruction of a struct lwes_net_connection
148 * \param[in] conn the multicast channel to ignore since it's not used in this
150 * \param[in] address the multicast IP address of the channel to connect to
151 * \param[in] iface the IP address of the network interface this channel shoul
153 * \param[in] port the multicast port of the channel to connect to
154 * \param[in] bytes the bytes to send to the alternate channel
155 * \param[in] len the number of bytes to send to the alternate channel
157 * \return the number of bytes sent on success, a negative number on failure
160 lwes_net_sendto_bytes
161 (struct lwes_net_connection
*conn
,
168 /*! \brief Bind to the multicast channel
170 * Used to actually bind to a channel, this should only be called if one
171 * plans to receive bytes from the channel
173 * \param[in] conn the multicast channel to bind to
175 * \return 0 on success, a negative number on failure
179 (struct lwes_net_connection
*conn
);
181 /*! \brief Receive bytes from the multicast channel in blocking mode
183 * This calls lwes_net_recv_bind internally.
185 * \param[in] conn the multicast channel to receive bytes from
186 * \param[out] bytes the byte array to fill out
187 * \param[in] len the size of the byte array to fill out
189 * \return the number of bytes received on success, a negative number on
194 (struct lwes_net_connection
*conn
,
198 /*! \brief Receive bytes from the multicast channel with a timeout
200 * This calls lwes_net_recv_bind internally.
202 * \param[in] conn the multicast channel to receive bytes from
203 * \param[out] bytes the byte array to fill out
204 * \param[in] len the size of the byte array to fill out
205 * \param[in] timeout_ms the maximum time to block on this call
207 * \return the number of bytes received on success, a negative number on
211 lwes_net_recv_bytes_by
212 (struct lwes_net_connection
*conn
,
215 unsigned int timeout_ms
);
221 #endif /* __NET_FUNCTIONS_H */