2014-07-11 22:12:11 +02:00
|
|
|
/*
|
2016-03-06 11:08:16 +01:00
|
|
|
This file is part of actube.
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-03-06 11:08:16 +01:00
|
|
|
actube is free software: you can redistribute it and/or modify
|
2014-07-11 22:12:11 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
libcapwap 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-03-06 11:08:16 +01:00
|
|
|
|
2015-05-04 07:34:25 +02:00
|
|
|
/**
|
|
|
|
*@file
|
|
|
|
*@breif
|
2016-03-07 08:43:34 +01:00
|
|
|
*@defgroup SOCK SOCK
|
2015-05-04 07:34:25 +02:00
|
|
|
*@{
|
|
|
|
*/
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#ifndef __SOCK_H
|
|
|
|
#define __SOCK_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#define HAVE_SIN_LEN
|
|
|
|
#define HAVE_SIN6_LEN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-15 14:29:24 +01:00
|
|
|
extern int sock_create(const struct sockaddr *sa);
|
|
|
|
extern int sock_mwait(int *socklist, int socklistlen, fd_set * fset);
|
|
|
|
extern void sock_copyaddr(struct sockaddr_storage *dst, const struct sockaddr *src);
|
|
|
|
extern int sock_cmpaddr(const struct sockaddr *addr1, const struct sockaddr *addr2,
|
|
|
|
int cmpport);
|
|
|
|
extern int sock_addrlen(const struct sockaddr *sa);
|
|
|
|
extern int sock_receive(int sock, void *buf, size_t len, int flags,
|
|
|
|
struct sockaddr *srcaddr, socklen_t * addrlen);
|
|
|
|
extern int sock_mreceive(int *socklist, int socklistlen,
|
|
|
|
void (*callback) (int *socklist, int index, struct sockaddr *,
|
|
|
|
uint8_t * buf, int len));
|
|
|
|
extern int sock_getifaddr(const char *ifname, int family, int type, struct sockaddr *sa);
|
2014-07-11 22:12:11 +02:00
|
|
|
extern int sock_getifhwaddr(const char *ifname, uint8_t * hwaddr, uint8_t * addrlen);
|
2016-02-15 14:29:24 +01:00
|
|
|
extern char *sock_hwaddrtostr(const uint8_t * haddr, int len, char *dst,
|
|
|
|
const char *separator);
|
2018-03-03 08:15:19 +01:00
|
|
|
|
|
|
|
/*
|
2016-03-06 11:08:16 +01:00
|
|
|
//extern char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen);
|
2018-03-03 08:15:19 +01:00
|
|
|
*/
|
|
|
|
|
2016-02-15 14:29:24 +01:00
|
|
|
extern int sock_strtoaddr(const char *s, struct sockaddr *saout);
|
2014-07-11 22:12:11 +02:00
|
|
|
extern int sock_set_recvtimeout(int sock, int seconds);
|
|
|
|
|
|
|
|
extern int sock_getport(struct sockaddr *addr);
|
|
|
|
extern int sock_setport(struct sockaddr *addr, int port);
|
2016-02-15 14:29:24 +01:00
|
|
|
extern int sock_getbroadcastaddr(const struct sockaddr *addr,
|
|
|
|
struct sockaddr *broadcastaddr);
|
|
|
|
extern void sock_addrinit(struct sockaddr *addr, int type);
|
|
|
|
extern int sock_set_dontfrag(int sock, int val);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-07-14 22:42:12 +02:00
|
|
|
|
2016-02-15 14:29:24 +01:00
|
|
|
extern char *sock_get_primary_if(int family);
|
2018-03-03 08:15:19 +01:00
|
|
|
|
|
|
|
/*
|
2016-02-15 14:29:24 +01:00
|
|
|
//extern char * sock_getifinfo(const struct sockaddr *sa,struct ifaddrs *result);
|
2018-03-03 08:15:19 +01:00
|
|
|
*/
|
2016-02-15 14:29:24 +01:00
|
|
|
extern int sock_getifinfo(const struct sockaddr *addr, char *ifname,
|
|
|
|
struct sockaddr *broadcast, struct sockaddr *netmask);
|
2014-07-14 22:42:12 +02:00
|
|
|
|
2015-04-24 07:13:54 +02:00
|
|
|
|
2016-02-15 14:29:24 +01:00
|
|
|
|
2016-03-06 11:08:16 +01:00
|
|
|
char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen, int addport);
|
|
|
|
|
2018-03-05 12:23:16 +01:00
|
|
|
#define SOCK_ADDR_BUFSIZE 64
|
|
|
|
|
|
|
|
#define SOCK_ADDR_BUF_DEFINE char __sock_buf__[SOCK_ADDR_BUFSIZE]
|
2016-03-06 11:08:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a sockaddr structure to a human readable string
|
|
|
|
* @param s sockaddr
|
|
|
|
* @return A char* pointer to converted address
|
|
|
|
*
|
|
|
|
* The returned string is pushed on the stack (unnamed variable), so this macro should
|
|
|
|
* only be used as function argument.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* \code
|
|
|
|
struct sockaddr sa;
|
|
|
|
// Initialize sa ...
|
|
|
|
sprintf("Adress: %s",sock_addr2str(&sa));
|
|
|
|
\endcode
|
|
|
|
*/
|
2018-03-05 12:23:16 +01:00
|
|
|
#define sock_addr2str(s,buf) ( sock_addrtostr( (struct sockaddr*)s, buf , SOCK_ADDR_BUFSIZE, 0 ) )
|
2016-03-06 11:08:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as #sock_addr2str, but also the port number is appended to the result
|
|
|
|
* @see #sock_addr2str
|
|
|
|
*/
|
2018-03-05 12:23:16 +01:00
|
|
|
#define sock_addr2str_p(s,buf) ( sock_addrtostr( (struct sockaddr*)s, buf, SOCK_ADDR_BUFSIZE, 1 ) )
|
2016-02-22 09:18:35 +01:00
|
|
|
|
2015-04-24 07:13:54 +02:00
|
|
|
|
|
|
|
|
2014-07-27 00:46:58 +02:00
|
|
|
#define sock_hwaddr2str(s,l) ( sock_hwaddrtostr( s,l, (char[64]){0}, ":" ) )
|
|
|
|
#define sock_hwaddr2idstr(s,l) ( sock_hwaddrtostr( s,l, (char[64]){0}, "" ) )
|
2018-03-03 08:15:19 +01:00
|
|
|
|
|
|
|
/*
|
2016-03-06 11:08:16 +01:00
|
|
|
//#define sock_addrtostr(s,str,n) sock_addrtostr(s,str,n,1)
|
2018-03-03 08:15:19 +01:00
|
|
|
*/
|
2014-07-22 07:09:20 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
#define sock_addrfamily(addr) ( ((struct sockaddr_storage*)(addr))->ss_family )
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-02-15 14:29:24 +01:00
|
|
|
#endif /* __SOCK_H */
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-05-04 07:34:25 +02:00
|
|
|
/**@}*/
|