123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- /***************************************************************************
- * *
- * _____ ____ *
- * | __ \ / __ \ _ _ _____ *
- * | | \ \ / / \_\ | | | | _ \ *
- * | | \ \| | | | | | |_| | *
- * | | | || | | | | | ___/ *
- * | | / /| | __ | | | | _ \ *
- * | |__/ / \ \__/ / | |___| | |_| | *
- * |_____/ \____/ |_____|_|_____/ *
- * *
- * Wiimms source code library *
- * *
- ***************************************************************************
- * *
- * Copyright (c) 2012-2022 by Dirk Clemens <wiimm@wiimm.de> *
- * *
- ***************************************************************************
- * *
- * This library is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This library 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. *
- * *
- * See file gpl-2.0.txt or http://www.gnu.org/licenses/gpl-2.0.txt *
- * *
- ***************************************************************************/
- #ifndef DCLIB_NETWORK_LINUX_H
- #define DCLIB_NETWORK_LINUX_H 1
- #ifndef DCLIB_NETWORK_H
- #include "dclib-network.h"
- #endif
- //
- ///////////////////////////////////////////////////////////////////////////////
- /////////////// IP/UDP ///////////////
- ///////////////////////////////////////////////////////////////////////////////
- ssize_t ReceiveUDPv4
- (
- int sock, // valid socket
- void *buf, // buffer tostore incoming data
- size_t buf_size, // size of buffer
- int flags, // flags for recffrom() or recvmsg()
- struct sockaddr_in *src_addr, // not NULL: stire source address
- in_addr_t *dest_addr // not NULL: store destination IPv4 (NBO)
- );
- ///////////////////////////////////////////////////////////////////////////////
- ssize_t SendUDPv4
- (
- int sock, // valid socket
- const void *data, // data to send
- size_t data_size, // size of data
- int flags, // flags for sendto() or sendmsg()
- struct sockaddr_in *dest_addr, // destination address (NULL possible)
- in_addr_t src_addr // not 0: source IPv4 (NBO)
- );
- ///////////////////////////////////////////////////////////////////////////////
- ssize_t recvfrom2
- (
- int sock,
- void *buf,
- size_t buf_size,
- int flags,
- struct sockaddr *src_addr,
- socklen_t *src_addrlen,
- struct sockaddr *dest_addr,
- socklen_t *dest_addrlen
- );
- //-----------------------------------------------------------------------------
- ssize_t sendto2
- (
- int sock,
- const void *buf,
- size_t buf_size,
- int flags,
- struct sockaddr *dest_addr,
- socklen_t dest_addrlen,
- struct sockaddr_in *src_addr,
- socklen_t src_addrlen
- );
- //
- ///////////////////////////////////////////////////////////////////////////////
- /////////////// SendRawUDP() ///////////////
- ///////////////////////////////////////////////////////////////////////////////
- enumError SendRawUDP
- (
- // Capability CAP_NET_RAW needed (or effective user ID of 0).
- int sock, // RAW socket to use,
- // if -1: open and close private socket
- ccp send_addr, // NULL or sender address:port
- u32 send_ip4, // fall back IP4, if 'send_addr' empty
- u16 send_port, // default sender port
- ccp recv_addr, // NULL or receiver address:port
- u32 recv_ip4, // fall back IP4, if 'recv_addr' empty
- u16 recv_port, // default receiver port
- const void *data, // data to send
- uint size, // size of 'data'
- uint log_mode // 0:silent, >0:print errors,
- // >=0x10: hexdump data, 'lmode' bytes max
- );
- //-----------------------------------------------------------------------------
- enumError SendRawUDPsa
- (
- // Capability CAP_NET_RAW needed (or effective user ID of 0).
- int sock, // RAW socket to use,
- // if -1: open and close private socket
- struct sockaddr_in *sa_send, // sockaddr of sender
- struct sockaddr_in *sa_recv, // sockaddr of receiver
- const void *data, // data to send
- uint size, // size of 'data'
- uint log_mode // 0:silent, >0:print errors,
- // >=0x10: hexdump data, 'lmode' bytes max
- );
- //-----------------------------------------------------------------------------
- uint SetupRawUDPsa
- (
- // returns total packet len (mabe with limited 'size')
- udp_packet_t *pkt, // paket header to setup (cleared and written)
- struct sockaddr_in *sa_send, // sockaddr of sender
- struct sockaddr_in *sa_recv, // sockaddr of receiver
- const void *data, // data to send
- uint size // size of 'data'
- );
- //
- ///////////////////////////////////////////////////////////////////////////////
- /////////////// Routing Support ///////////////
- ///////////////////////////////////////////////////////////////////////////////
- // all IP4 in network byte order
- typedef struct RouteIP4_t
- {
- //--- returned data
- int index; // entry index, starts with 0, incremented for each found
- // -1: invalid data
- char *iface; // pointer into 'buf': interface name
- u32 dest; // destination address, network byte order
- u32 mask; // destination network mask, network byte order
- u32 gate; // gateway address, network byte order
- u32 flags; // routing flags
- //--- internal data
- FILE *f; // open file
- uint col_iface; // column index for 'iface'
- uint col_dest; // column index for 'dest'
- uint col_mask; // column index for 'mask'
- uint col_gate; // column index for 'gate'
- uint col_flags; // column index for 'flags'
- char buf[200]; // line buffer for /proc/net/route
- }
- RouteIP4_t;
- ///////////////////////////////////////////////////////////////////////////////
- bool OpenRouteScanIP4
- (
- // returns TRUE on success and FALSE if no element is found
- RouteIP4_t *rt // valid data, will be initialized
- );
- bool NextRouteScanIP4
- (
- // returns TRUE on success and FALSE if no more element is found
- RouteIP4_t *rt // valid data
- );
- void CloseRouteScanIP4
- (
- RouteIP4_t *rt // valid data
- );
- ///////////////////////////////////////////////////////////////////////////////
- bool FindGatewayIP4
- (
- // returns TRUE if gateway found
- RouteIP4_t *rt, // valid data, will be initialized
- u32 ip4 // search gateway for this address (network byte order)
- );
- u32 GetIP4ByInterface
- ( // return 0 or IP4 in network byte order
- ccp iface // interface name. If NULL: Use default gateway
- );
- //
- ///////////////////////////////////////////////////////////////////////////////
- /////////////// E N D ///////////////
- ///////////////////////////////////////////////////////////////////////////////
- #endif // DCLIB_NETWORK_LINUX_H
|