/*
 * common functions (used by both backconn-cli and backconn-adm)
 *
 * This file is part of the backconn project. http://backconn.sourceforge.net
 * Copyright (C) 2017-2021 Mateusz Viste
 *
 * ===================== PUBLISHED UNDER THE MIT LICENSE =====================
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 * ===========================================================================
 */

#ifndef common_h_sentinel
#define common_h_sentinel

#define pVer "20210827"

/* sends l bytes from buffer buf to socket s. return 0 on success, -1 otherwise */
int sendall(int s, const void *buf, int l);

/* a wrapper around recv(), but with a controller timeout (in seconds) */
int recvtimeout(int sock, void *buff, int len, int timeout, int flags);

/* "encrypt" a string of bytes using a single-byte xor key */
void xorstr(void *buf, int xorkey, int len);

/* proxifies data from one connection to another (and vice versa), effectively
 * juggling bytes back and forth. returns when one of the connections breaks.
 * this function does not close any of the connections - do cleanup yourself! */
int proxy(int s1, int s2, unsigned char *buf, int buflen, int xorkey);

/* enable TCP keepalive on socket */
void enable_tcpkeepalive(int sock);

#endif