| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- /**
- * @file DatagramSocketSink.h
- * @author Ambroz Bizjak <ambrop7@gmail.com>
- *
- * @section LICENSE
- *
- * This file is part of BadVPN.
- *
- * BadVPN is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * BadVPN is distributed in the hope that it will be useful,
- * 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 Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * @section DESCRIPTION
- *
- * A {@link PacketPassInterface} sink which sends packets to a datagram socket.
- */
- #ifndef BADVPN_DATAGRAMSOCKETSINK_H
- #define BADVPN_DATAGRAMSOCKETSINK_H
- #include <stdint.h>
- #include <base/DebugObject.h>
- #include <system/BSocket.h>
- #include <flow/PacketPassInterface.h>
- #include <flow/FlowError.h>
- #define DATAGRAMSOCKETSINK_ERROR_BSOCKET 1
- #define DATAGRAMSOCKETSINK_ERROR_WRONGSIZE 2
- /**
- * A {@link PacketPassInterface} sink which sends packets to a datagram socket.
- */
- typedef struct {
- FlowErrorReporter rep;
- BSocket *bsock;
- BAddr addr;
- BIPAddr local_addr;
- PacketPassInterface input;
- int in_len;
- uint8_t *in;
- DebugObject d_obj;
- } DatagramSocketSink;
- /**
- * Initializes the sink.
- *
- * @param s the object
- * @param rep error reporting data. Error code is an int. Possible error codes:
- * - DATAGRAMSOCKETSINK_ERROR_BSOCKET: {@link BSocket_SendToFrom} failed
- * with an unhandled error code
- * - DATAGRAMSOCKETSINK_ERROR_WRONGSIZE: {@link BSocket_SendToFrom} succeeded,
- * but did not send all of the packet
- * On error, the object will continue to operate unless it is destroyed from
- * the error handler.
- * @param bsock datagram socket to write packets to. Registers a BSOCKET_WRITE handler which
- * must not be registered.
- * @param mtu maximum packet size. Must be >=0.
- * @param addr remote address. Must be recognized and valid. Passed to {@link BSocket_SendToFrom}.
- * @param local_addr source address. Must be recognized.
- * Passed to {@link BSocket_SendToFrom}.
- * @param pg pending group
- */
- void DatagramSocketSink_Init (DatagramSocketSink *s, FlowErrorReporter rep, BSocket *bsock, int mtu, BAddr addr, BIPAddr local_addr, BPendingGroup *pg);
- /**
- * Frees the sink.
- *
- * @param s the object
- */
- void DatagramSocketSink_Free (DatagramSocketSink *s);
- /**
- * Returns the input interface.
- *
- * @param s the object
- * @return input interface
- */
- PacketPassInterface * DatagramSocketSink_GetInput (DatagramSocketSink *s);
- /**
- * Sets sending addresses.
- *
- * @param s the object
- * @param addr remote address. Must be recognized and valid. Passed to {@link BSocket_SendToFrom}.
- * @param local_addr source address. Must be recognized.
- * Passed to {@link BSocket_SendToFrom}.
- */
- void DatagramSocketSink_SetAddresses (DatagramSocketSink *s, BAddr addr, BIPAddr local_addr);
- #endif
|