mirror of
https://repo.or.cz/socat.git
synced 2024-12-22 23:42:34 +00:00
adapted conditionals to genericsocket, interface
This commit is contained in:
parent
674b0e608d
commit
084726e981
6 changed files with 39 additions and 6 deletions
|
@ -450,7 +450,7 @@ int parseport(const char *portname, int ipproto) {
|
||||||
#endif /* WITH_TCP || WITH_UDP */
|
#endif /* WITH_TCP || WITH_UDP */
|
||||||
|
|
||||||
|
|
||||||
#if WITH_IP4 || WITH_IP6
|
#if WITH_IP4 || WITH_IP6 || WITH_INTERFACE
|
||||||
/* check the systems interfaces for ifname and return its index
|
/* check the systems interfaces for ifname and return its index
|
||||||
or -1 if no interface with this name was found
|
or -1 if no interface with this name was found
|
||||||
The system calls require an arbitrary socket; the calling program may
|
The system calls require an arbitrary socket; the calling program may
|
||||||
|
@ -501,8 +501,10 @@ int ifindexbyname(const char *ifname, int anysock) {
|
||||||
return -1;
|
return -1;
|
||||||
#endif /* !defined(HAVE_ STRUCT_IFREQ) && defined(SIOCGIFCONF) && defined(SIOCGIFINDEX) */
|
#endif /* !defined(HAVE_ STRUCT_IFREQ) && defined(SIOCGIFCONF) && defined(SIOCGIFINDEX) */
|
||||||
}
|
}
|
||||||
|
#endif /* WITH_IP4 || WITH_IP6 || WITH_INTERFACE */
|
||||||
|
|
||||||
|
|
||||||
|
#if WITH_IP4 || WITH_IP6 || WITH_INTERFACE
|
||||||
/* like ifindexbyname(), but also allows the index number as input - in this
|
/* like ifindexbyname(), but also allows the index number as input - in this
|
||||||
case it does not lookup the index.
|
case it does not lookup the index.
|
||||||
writes the resulting index to *ifindex and returns 0,
|
writes the resulting index to *ifindex and returns 0,
|
||||||
|
@ -526,7 +528,7 @@ int ifindex(const char *ifname, unsigned int *ifindex, int anysock) {
|
||||||
*ifindex = val;
|
*ifindex = val;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* WITH_IP4 || WITH_IP6 */
|
#endif /* WITH_IP4 || WITH_IP6 || WITH_INTERFACE */
|
||||||
|
|
||||||
|
|
||||||
/* constructs an environment variable whose name is built from socats uppercase
|
/* constructs an environment variable whose name is built from socats uppercase
|
||||||
|
|
|
@ -21,9 +21,9 @@ union sockaddr_union {
|
||||||
#if WITH_UNIX
|
#if WITH_UNIX
|
||||||
struct sockaddr_un un;
|
struct sockaddr_un un;
|
||||||
#endif /* WITH_UNIX */
|
#endif /* WITH_UNIX */
|
||||||
#if WITH_IP4
|
#if _WITH_IP4
|
||||||
struct sockaddr_in ip4;
|
struct sockaddr_in ip4;
|
||||||
#endif /* WITH_IP4 */
|
#endif /* _WITH_IP4 */
|
||||||
#if WITH_IP6
|
#if WITH_IP6
|
||||||
struct sockaddr_in6 ip6;
|
struct sockaddr_in6 ip6;
|
||||||
#endif /* WITH_IP6 */
|
#endif /* WITH_IP6 */
|
||||||
|
|
4
xio-ip.c
4
xio-ip.c
|
@ -466,6 +466,7 @@ int xiolog_ancillary_ip(struct cmsghdr *cmsg, int *num,
|
||||||
snprintf(nambuff, namlen, "type_%u", cmsg->cmsg_type);
|
snprintf(nambuff, namlen, "type_%u", cmsg->cmsg_type);
|
||||||
xiodump(CMSG_DATA(cmsg), msglen, valbuff, vallen, 0);
|
xiodump(CMSG_DATA(cmsg), msglen, valbuff, vallen, 0);
|
||||||
return STAT_OK;
|
return STAT_OK;
|
||||||
|
#if WITH_IP4
|
||||||
#ifdef IP_PKTINFO
|
#ifdef IP_PKTINFO
|
||||||
case IP_PKTINFO: {
|
case IP_PKTINFO: {
|
||||||
struct in_pktinfo *pktinfo = (struct in_pktinfo *)CMSG_DATA(cmsg);
|
struct in_pktinfo *pktinfo = (struct in_pktinfo *)CMSG_DATA(cmsg);
|
||||||
|
@ -481,6 +482,7 @@ int xiolog_ancillary_ip(struct cmsghdr *cmsg, int *num,
|
||||||
}
|
}
|
||||||
return STAT_OK;
|
return STAT_OK;
|
||||||
#endif /* IP_PKTINFO */
|
#endif /* IP_PKTINFO */
|
||||||
|
#endif /* WITH_IP4 */
|
||||||
#ifdef IP_RECVERR
|
#ifdef IP_RECVERR
|
||||||
case IP_RECVERR: {
|
case IP_RECVERR: {
|
||||||
struct sock_extended_err *err =
|
struct sock_extended_err *err =
|
||||||
|
@ -513,6 +515,7 @@ int xiolog_ancillary_ip(struct cmsghdr *cmsg, int *num,
|
||||||
return STAT_OK;
|
return STAT_OK;
|
||||||
}
|
}
|
||||||
#endif /* defined(IP_RECVIF) */
|
#endif /* defined(IP_RECVIF) */
|
||||||
|
#if WITH_IP4
|
||||||
#ifdef IP_RECVDSTADDR
|
#ifdef IP_RECVDSTADDR
|
||||||
case IP_RECVDSTADDR:
|
case IP_RECVDSTADDR:
|
||||||
*num = 1;
|
*num = 1;
|
||||||
|
@ -522,6 +525,7 @@ int xiolog_ancillary_ip(struct cmsghdr *cmsg, int *num,
|
||||||
inet4addr_info(ntohl(*(uint32_t *)CMSG_DATA(cmsg)), valbuff, vallen);
|
inet4addr_info(ntohl(*(uint32_t *)CMSG_DATA(cmsg)), valbuff, vallen);
|
||||||
return STAT_OK;
|
return STAT_OK;
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* WITH_IP4 */
|
||||||
case IP_OPTIONS:
|
case IP_OPTIONS:
|
||||||
case IP_RECVOPTS:
|
case IP_RECVOPTS:
|
||||||
cmsgtype = "IP_OPTIONS"; cmsgname = "options"; cmsgfmt = NULL; break;
|
cmsgtype = "IP_OPTIONS"; cmsgname = "options"; cmsgfmt = NULL; break;
|
||||||
|
|
21
xio-socket.c
21
xio-socket.c
|
@ -65,13 +65,17 @@ xiolog_ancillary_socket(struct cmsghdr *cmsg, int *num,
|
||||||
char *valbuff, int vallen);
|
char *valbuff, int vallen);
|
||||||
|
|
||||||
|
|
||||||
|
#if WITH_GENERICSOCKET
|
||||||
/* generic socket addresses */
|
/* generic socket addresses */
|
||||||
const struct addrdesc xioaddr_socket_connect = { "socket-connect", 1, xioopen_socket_connect, GROUP_FD|GROUP_SOCKET|GROUP_CHILD|GROUP_RETRY, 0, 0, 0 HELP(":<domain>:<protocol>:<remote-address>") };
|
const struct addrdesc xioaddr_socket_connect = { "socket-connect", 1, xioopen_socket_connect, GROUP_FD|GROUP_SOCKET|GROUP_CHILD|GROUP_RETRY, 0, 0, 0 HELP(":<domain>:<protocol>:<remote-address>") };
|
||||||
|
#if WITH_LISTEN
|
||||||
const struct addrdesc xioaddr_socket_listen = { "socket-listen", 1, xioopen_socket_listen, GROUP_FD|GROUP_SOCKET|GROUP_LISTEN|GROUP_RANGE|GROUP_CHILD|GROUP_RETRY, 0, 0, 0 HELP(":<domain>:<protocol>:<local-address>") };
|
const struct addrdesc xioaddr_socket_listen = { "socket-listen", 1, xioopen_socket_listen, GROUP_FD|GROUP_SOCKET|GROUP_LISTEN|GROUP_RANGE|GROUP_CHILD|GROUP_RETRY, 0, 0, 0 HELP(":<domain>:<protocol>:<local-address>") };
|
||||||
|
#endif /* WITH_LISTEN */
|
||||||
const struct addrdesc xioaddr_socket_sendto = { "socket-sendto", 3, xioopen_socket_sendto, GROUP_FD|GROUP_SOCKET, 0, 0, 0 HELP(":<domain>:<type>:<protocol>:<remote-address>") };
|
const struct addrdesc xioaddr_socket_sendto = { "socket-sendto", 3, xioopen_socket_sendto, GROUP_FD|GROUP_SOCKET, 0, 0, 0 HELP(":<domain>:<type>:<protocol>:<remote-address>") };
|
||||||
const struct addrdesc xioaddr_socket_datagram= { "socket-datagram", 3, xioopen_socket_datagram, GROUP_FD|GROUP_SOCKET|GROUP_RANGE, 0, 0, 0 HELP(":<domain>:<type>:<protocol>:<remote-address>") };
|
const struct addrdesc xioaddr_socket_datagram= { "socket-datagram", 3, xioopen_socket_datagram, GROUP_FD|GROUP_SOCKET|GROUP_RANGE, 0, 0, 0 HELP(":<domain>:<type>:<protocol>:<remote-address>") };
|
||||||
const struct addrdesc xioaddr_socket_recvfrom= { "socket-recvfrom", 3, xioopen_socket_recvfrom, GROUP_FD|GROUP_SOCKET|GROUP_RANGE|GROUP_CHILD, 0, 0, 0 HELP(":<domain>:<type>:<protocol>:<local-address>") };
|
const struct addrdesc xioaddr_socket_recvfrom= { "socket-recvfrom", 3, xioopen_socket_recvfrom, GROUP_FD|GROUP_SOCKET|GROUP_RANGE|GROUP_CHILD, 0, 0, 0 HELP(":<domain>:<type>:<protocol>:<local-address>") };
|
||||||
const struct addrdesc xioaddr_socket_recv = { "socket-recv", 1, xioopen_socket_recv, GROUP_FD|GROUP_SOCKET|GROUP_RANGE, 0, 0, 0 HELP(":<domain>:<type>:<protocol>:<local-address>") };
|
const struct addrdesc xioaddr_socket_recv = { "socket-recv", 1, xioopen_socket_recv, GROUP_FD|GROUP_SOCKET|GROUP_RANGE, 0, 0, 0 HELP(":<domain>:<type>:<protocol>:<local-address>") };
|
||||||
|
#endif /* WITH_GENERICSOCKET */
|
||||||
|
|
||||||
|
|
||||||
/* the following options apply not only to generic socket addresses but to all
|
/* the following options apply not only to generic socket addresses but to all
|
||||||
|
@ -192,6 +196,9 @@ const struct optdesc opt_setsockopt_int = { "setsockopt-int", "sockopt-int
|
||||||
const struct optdesc opt_setsockopt_bin = { "setsockopt-bin", "sockopt-bin", OPT_SETSOCKOPT_BIN, GROUP_SOCKET,PH_PASTSOCKET,TYPE_INT_INT_BIN, OFUNC_SOCKOPT_GENERIC, 0, 0 };
|
const struct optdesc opt_setsockopt_bin = { "setsockopt-bin", "sockopt-bin", OPT_SETSOCKOPT_BIN, GROUP_SOCKET,PH_PASTSOCKET,TYPE_INT_INT_BIN, OFUNC_SOCKOPT_GENERIC, 0, 0 };
|
||||||
const struct optdesc opt_setsockopt_string = { "setsockopt-string", "sockopt-string", OPT_SETSOCKOPT_STRING, GROUP_SOCKET,PH_PASTSOCKET,TYPE_INT_INT_STRING, OFUNC_SOCKOPT_GENERIC, 0, 0 };
|
const struct optdesc opt_setsockopt_string = { "setsockopt-string", "sockopt-string", OPT_SETSOCKOPT_STRING, GROUP_SOCKET,PH_PASTSOCKET,TYPE_INT_INT_STRING, OFUNC_SOCKOPT_GENERIC, 0, 0 };
|
||||||
|
|
||||||
|
|
||||||
|
#if WITH_GENERICSOCKET
|
||||||
|
|
||||||
static
|
static
|
||||||
int xioopen_socket_connect(int argc, const char *argv[], struct opt *opts,
|
int xioopen_socket_connect(int argc, const char *argv[], struct opt *opts,
|
||||||
int xioflags, xiofile_t *xxfd, unsigned groups,
|
int xioflags, xiofile_t *xxfd, unsigned groups,
|
||||||
|
@ -272,6 +279,7 @@ int xioopen_socket_connect(int argc, const char *argv[], struct opt *opts,
|
||||||
return STAT_OK;
|
return STAT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WITH_LISTEN
|
||||||
static
|
static
|
||||||
int xioopen_socket_listen(int argc, const char *argv[], struct opt *opts,
|
int xioopen_socket_listen(int argc, const char *argv[], struct opt *opts,
|
||||||
int xioflags, xiofile_t *xxfd, unsigned groups,
|
int xioflags, xiofile_t *xxfd, unsigned groups,
|
||||||
|
@ -339,6 +347,7 @@ int xioopen_socket_listen(int argc, const char *argv[], struct opt *opts,
|
||||||
return result;
|
return result;
|
||||||
return STAT_OK;
|
return STAT_OK;
|
||||||
}
|
}
|
||||||
|
#endif /* WITH_LISTEN */
|
||||||
|
|
||||||
/* we expect the form: ...:domain:type:protocol:remote-address */
|
/* we expect the form: ...:domain:type:protocol:remote-address */
|
||||||
static
|
static
|
||||||
|
@ -684,6 +693,8 @@ int xioopen_socket_datagram(int argc, const char *argv[], struct opt *opts,
|
||||||
return STAT_OK;
|
return STAT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* WITH_GENERICSOCKET */
|
||||||
|
|
||||||
|
|
||||||
/* a subroutine that is common to all socket addresses that want to connect
|
/* a subroutine that is common to all socket addresses that want to connect
|
||||||
to a peer address.
|
to a peer address.
|
||||||
|
@ -1594,18 +1605,22 @@ int xiodopacketinfo(struct msghdr *msgh, bool withlog, bool withenv) {
|
||||||
envbuff, sizeof(envbuff)-1,
|
envbuff, sizeof(envbuff)-1,
|
||||||
valbuff, sizeof(valbuff)-1);
|
valbuff, sizeof(valbuff)-1);
|
||||||
break;
|
break;
|
||||||
|
#if WITH_IP4 || WITH_IP6
|
||||||
case SOL_IP:
|
case SOL_IP:
|
||||||
xiolog_ancillary_ip(cmsg, &num, typbuff, sizeof(typbuff)-1,
|
xiolog_ancillary_ip(cmsg, &num, typbuff, sizeof(typbuff)-1,
|
||||||
nambuff, sizeof(nambuff)-1,
|
nambuff, sizeof(nambuff)-1,
|
||||||
envbuff, sizeof(envbuff)-1,
|
envbuff, sizeof(envbuff)-1,
|
||||||
valbuff, sizeof(valbuff)-1);
|
valbuff, sizeof(valbuff)-1);
|
||||||
break;
|
break;
|
||||||
|
#endif /* WITH_IP4 || WITH_IP6 */
|
||||||
|
#if WITH_IP6
|
||||||
case SOL_IPV6:
|
case SOL_IPV6:
|
||||||
xiolog_ancillary_ip6(cmsg, &num, typbuff, sizeof(typbuff)-1,
|
xiolog_ancillary_ip6(cmsg, &num, typbuff, sizeof(typbuff)-1,
|
||||||
nambuff, sizeof(nambuff)-1,
|
nambuff, sizeof(nambuff)-1,
|
||||||
envbuff, sizeof(envbuff)-1,
|
envbuff, sizeof(envbuff)-1,
|
||||||
valbuff, sizeof(valbuff)-1);
|
valbuff, sizeof(valbuff)-1);
|
||||||
break;
|
break;
|
||||||
|
#endif /* WITH_IP6 */
|
||||||
default:
|
default:
|
||||||
num = 1;
|
num = 1;
|
||||||
snprintf(typbuff, sizeof(typbuff)-1, "LEVEL%u", cmsg->cmsg_level);
|
snprintf(typbuff, sizeof(typbuff)-1, "LEVEL%u", cmsg->cmsg_level);
|
||||||
|
@ -1988,6 +2003,7 @@ int xiosetsockaddrenv(const char *lr,
|
||||||
|
|
||||||
strcpy(namebuff, lr);
|
strcpy(namebuff, lr);
|
||||||
switch (sau->soa.sa_family) {
|
switch (sau->soa.sa_family) {
|
||||||
|
#if WITH_UNIX
|
||||||
case PF_UNIX:
|
case PF_UNIX:
|
||||||
result =
|
result =
|
||||||
xiosetsockaddrenv_unix(idx, strchr(namebuff, '\0'), XIOSOCKADDRENVLEN-strlen(lr),
|
xiosetsockaddrenv_unix(idx, strchr(namebuff, '\0'), XIOSOCKADDRENVLEN-strlen(lr),
|
||||||
|
@ -1995,6 +2011,8 @@ int xiosetsockaddrenv(const char *lr,
|
||||||
&sau->un, salen, proto);
|
&sau->un, salen, proto);
|
||||||
xiosetenv(namebuff, valuebuff, 1);
|
xiosetenv(namebuff, valuebuff, 1);
|
||||||
break;
|
break;
|
||||||
|
#endif /* WITH_UNIX */
|
||||||
|
#if WITH_IP4
|
||||||
case PF_INET:
|
case PF_INET:
|
||||||
do {
|
do {
|
||||||
result =
|
result =
|
||||||
|
@ -2005,6 +2023,8 @@ int xiosetsockaddrenv(const char *lr,
|
||||||
namebuff[strlen(lr)] = '\0'; ++idx;
|
namebuff[strlen(lr)] = '\0'; ++idx;
|
||||||
} while (result > 0);
|
} while (result > 0);
|
||||||
break;
|
break;
|
||||||
|
#endif /* WITH_IP4 */
|
||||||
|
#if WITH_IP6
|
||||||
case PF_INET6:
|
case PF_INET6:
|
||||||
strcpy(namebuff, lr);
|
strcpy(namebuff, lr);
|
||||||
do {
|
do {
|
||||||
|
@ -2016,6 +2036,7 @@ int xiosetsockaddrenv(const char *lr,
|
||||||
namebuff[strlen(lr)] = '\0'; ++idx;
|
namebuff[strlen(lr)] = '\0'; ++idx;
|
||||||
} while (result > 0);
|
} while (result > 0);
|
||||||
break;
|
break;
|
||||||
|
#endif /* WITH_IP6 */
|
||||||
#if LATER
|
#if LATER
|
||||||
case PF_PACKET:
|
case PF_PACKET:
|
||||||
result = xiosetsockaddrenv_packet(lr, (void *)sau, proto); break;
|
result = xiosetsockaddrenv_packet(lr, (void *)sau, proto); break;
|
||||||
|
|
|
@ -148,18 +148,22 @@ const struct addrname addressnames[] = {
|
||||||
{ "sctp-l", &addr_sctp_listen },
|
{ "sctp-l", &addr_sctp_listen },
|
||||||
{ "sctp-listen", &addr_sctp_listen },
|
{ "sctp-listen", &addr_sctp_listen },
|
||||||
#endif
|
#endif
|
||||||
|
#if WITH_IP4
|
||||||
{ "sctp4", &addr_sctp4_connect },
|
{ "sctp4", &addr_sctp4_connect },
|
||||||
{ "sctp4-connect", &addr_sctp4_connect },
|
{ "sctp4-connect", &addr_sctp4_connect },
|
||||||
#if WITH_LISTEN
|
#if WITH_LISTEN
|
||||||
{ "sctp4-l", &addr_sctp4_listen },
|
{ "sctp4-l", &addr_sctp4_listen },
|
||||||
{ "sctp4-listen", &addr_sctp4_listen },
|
{ "sctp4-listen", &addr_sctp4_listen },
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* WITH_IP4 */
|
||||||
|
#if WITH_IP6
|
||||||
{ "sctp6", &addr_sctp6_connect },
|
{ "sctp6", &addr_sctp6_connect },
|
||||||
{ "sctp6-connect", &addr_sctp6_connect },
|
{ "sctp6-connect", &addr_sctp6_connect },
|
||||||
#if WITH_LISTEN
|
#if WITH_LISTEN
|
||||||
{ "sctp6-l", &addr_sctp6_listen },
|
{ "sctp6-l", &addr_sctp6_listen },
|
||||||
{ "sctp6-listen", &addr_sctp6_listen },
|
{ "sctp6-listen", &addr_sctp6_listen },
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* WITH_IP6 */
|
||||||
#endif /* (WITH_IP4 || WITH_IP6) && WITH_SCTP */
|
#endif /* (WITH_IP4 || WITH_IP6) && WITH_SCTP */
|
||||||
#if WITH_GENERICSOCKET
|
#if WITH_GENERICSOCKET
|
||||||
{ "sendto", &xioaddr_socket_sendto },
|
{ "sendto", &xioaddr_socket_sendto },
|
||||||
|
@ -167,7 +171,9 @@ const struct addrname addressnames[] = {
|
||||||
#if WITH_GENERICSOCKET
|
#if WITH_GENERICSOCKET
|
||||||
{ "socket-connect", &xioaddr_socket_connect },
|
{ "socket-connect", &xioaddr_socket_connect },
|
||||||
{ "socket-datagram", &xioaddr_socket_datagram },
|
{ "socket-datagram", &xioaddr_socket_datagram },
|
||||||
|
#if WITH_LISTEN
|
||||||
{ "socket-listen", &xioaddr_socket_listen },
|
{ "socket-listen", &xioaddr_socket_listen },
|
||||||
|
#endif /* WITH_LISTEN */
|
||||||
{ "socket-recv", &xioaddr_socket_recv },
|
{ "socket-recv", &xioaddr_socket_recv },
|
||||||
{ "socket-recvfrom", &xioaddr_socket_recvfrom },
|
{ "socket-recvfrom", &xioaddr_socket_recvfrom },
|
||||||
{ "socket-sendto", &xioaddr_socket_sendto },
|
{ "socket-sendto", &xioaddr_socket_sendto },
|
||||||
|
|
|
@ -146,14 +146,14 @@ ssize_t xioread(xiofile_t *file, void *buff, size_t bufsiz) {
|
||||||
}
|
}
|
||||||
/* on packet type we also receive outgoing packets, this is not desired
|
/* on packet type we also receive outgoing packets, this is not desired
|
||||||
*/
|
*/
|
||||||
#ifdef PF_PACKET
|
#if defined(PF_PACKET) && defined(PACKET_OUTGOING)
|
||||||
if (from.soa.sa_family == PF_PACKET) {
|
if (from.soa.sa_family == PF_PACKET) {
|
||||||
if ((((struct sockaddr_ll *)&from.soa)->sll_pkttype & PACKET_OUTGOING)
|
if ((((struct sockaddr_ll *)&from.soa)->sll_pkttype & PACKET_OUTGOING)
|
||||||
== 0) {
|
== 0) {
|
||||||
errno = EAGAIN; return -1;
|
errno = EAGAIN; return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* PF_PACKET */
|
#endif /* defined(PF_PACKET) && defined(PACKET_OUTGOING) */
|
||||||
|
|
||||||
Notice2("received packet with "F_Zu" bytes from %s",
|
Notice2("received packet with "F_Zu" bytes from %s",
|
||||||
bytes,
|
bytes,
|
||||||
|
|
Loading…
Reference in a new issue