mirror of
https://repo.or.cz/socat.git
synced 2025-07-16 08:03:24 +00:00
Reworked IPAPP clients
This commit is contained in:
parent
63f67101f4
commit
7b26406d96
16 changed files with 1660 additions and 649 deletions
80
xio-ip.c
80
xio-ip.c
|
@ -161,6 +161,79 @@ int Res_init(void) {
|
|||
#endif /* HAVE_RESOLV_H */
|
||||
|
||||
|
||||
/* Looks for a bind option and, if found, passes it to resolver;
|
||||
for IP (v4, v6) and raw (PF_UNSPEC);
|
||||
returns list of addrinfo results;
|
||||
returns STAT_OK if option exists and could be resolved,
|
||||
STAT_NORETRY if option exists but had error,
|
||||
or STAT_NOACTION if it does not exist */
|
||||
int retropt_bind_ip(
|
||||
struct opt *opts,
|
||||
int af,
|
||||
int socktype,
|
||||
int ipproto,
|
||||
struct addrinfo ***bindlist,
|
||||
int feats, /* TCP etc: 1..address allowed,
|
||||
3..address and port allowed
|
||||
*/
|
||||
const int ai_flags[2])
|
||||
{
|
||||
const char portsep[] = ":";
|
||||
const char *ends[] = { portsep, NULL };
|
||||
const char *nests[] = { "[", "]", NULL };
|
||||
bool portallowed;
|
||||
char *bindname, *bindp;
|
||||
char hostname[512], *hostp = hostname, *portp = NULL;
|
||||
size_t hostlen = sizeof(hostname)-1;
|
||||
int parsres;
|
||||
int ai_flags2[2];
|
||||
int result;
|
||||
|
||||
if (retropt_string(opts, OPT_BIND, &bindname) < 0) {
|
||||
return STAT_NOACTION;
|
||||
}
|
||||
bindp = bindname;
|
||||
|
||||
portallowed = (feats>=2);
|
||||
parsres =
|
||||
nestlex((const char **)&bindp, &hostp, &hostlen, ends, NULL, NULL, nests,
|
||||
true, false, false);
|
||||
if (parsres < 0) {
|
||||
Error1("option too long: \"%s\"", bindp);
|
||||
return STAT_NORETRY;
|
||||
} else if (parsres > 0) {
|
||||
Error1("syntax error in \"%s\"", bindp);
|
||||
return STAT_NORETRY;
|
||||
}
|
||||
*hostp++ = '\0';
|
||||
if (!strncmp(bindp, portsep, strlen(portsep))) {
|
||||
if (!portallowed) {
|
||||
Error("port specification not allowed in this bind option");
|
||||
return STAT_NORETRY;
|
||||
} else {
|
||||
portp = bindp + strlen(portsep);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set AI_PASSIVE, except when it is explicitely disabled */
|
||||
ai_flags2[0] = ai_flags[0];
|
||||
ai_flags2[1] = ai_flags[1];
|
||||
if (!(ai_flags2[1] & AI_PASSIVE))
|
||||
ai_flags2[0] |= AI_PASSIVE;
|
||||
|
||||
if ((result =
|
||||
xiogetaddrinfo(hostname[0]!='\0'?hostname:NULL, portp,
|
||||
af, socktype, ipproto,
|
||||
bindlist, ai_flags2))
|
||||
!= STAT_OK) {
|
||||
Error2("error resolving bind option \"%s\" with af=%d", bindname, af);
|
||||
return STAT_NORETRY;
|
||||
}
|
||||
|
||||
return STAT_OK;
|
||||
}
|
||||
|
||||
|
||||
#if WITH_DEVTESTS
|
||||
|
||||
/* Have a couple of hard coded sockaddr records, to be copied and adapted when
|
||||
|
@ -516,11 +589,11 @@ int _xiogetaddrinfo(const char *node, const char *service,
|
|||
continue;
|
||||
}
|
||||
if ((error_num = Getaddrinfo(node, service, &hints, res)) != 0) {
|
||||
Warn7("getaddrinfo(\"%s\", \"%s\", {0x%02x,%d,%d,%d}, {}): %d",
|
||||
Warn7("getaddrinfo(\"%s\", \"%s\", {0x%02x,%d,%d,%d}, {}): %s",
|
||||
node?node:"NULL", service?service:"NULL",
|
||||
hints.ai_flags, hints.ai_family,
|
||||
hints.ai_socktype, hints.ai_protocol,
|
||||
error_num);
|
||||
gai_strerror(error_num));
|
||||
if (numnode)
|
||||
free(numnode);
|
||||
|
||||
|
@ -760,6 +833,9 @@ void xiofreeaddrinfo(struct addrinfo **ai_sorted) {
|
|||
int ain;
|
||||
struct addrinfo *res;
|
||||
|
||||
if (ai_sorted == NULL)
|
||||
return;
|
||||
|
||||
/* Find the original *res from getaddrinfo past NULL */
|
||||
ain = 0;
|
||||
while (ai_sorted[ain] != NULL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue