mirror of
https://repo.or.cz/socat.git
synced 2025-07-27 04:57:51 +00:00
merged features ioctl, setsockopt, generic-socket
This commit is contained in:
commit
d78b080ef0
44 changed files with 2035 additions and 263 deletions
86
xio-ip.c
86
xio-ip.c
|
@ -444,92 +444,6 @@ int xiogetaddrinfo(const char *node, const char *service,
|
|||
}
|
||||
|
||||
|
||||
int xioparsenetwork(const char *rangename, int pf, union xiorange_union *range) {
|
||||
#if WITH_IP4
|
||||
struct in_addr *netaddr_in = &range->ip4.netaddr;
|
||||
struct in_addr *netmask_in = &range->ip4.netmask;
|
||||
#endif /* WITH_IP4 */
|
||||
struct hostent *maskaddr;
|
||||
char *delimpos; /* absolute address of delimiter */
|
||||
int bits;
|
||||
|
||||
switch (pf) {
|
||||
#if WITH_IP4
|
||||
char *rangename1; /* a copy of rangename with writing allowed */
|
||||
case PF_INET:
|
||||
if ((rangename1 = strdup(rangename)) == NULL) {
|
||||
Error1("strdup(\"%s\"): out of memory", rangename);
|
||||
return STAT_RETRYLATER;
|
||||
}
|
||||
|
||||
if (delimpos = strchr(rangename1, '/')) {
|
||||
bits = strtoul(delimpos+1, NULL, 10);
|
||||
netmask_in->s_addr = htonl((0xffffffff << (32-bits)));
|
||||
} else if (delimpos = strchr(rangename1, ':')) {
|
||||
if ((maskaddr = Gethostbyname(delimpos+1)) == NULL) {
|
||||
Error2("gethostbyname(\"%s\"): %s", delimpos+1,
|
||||
h_errno == NETDB_INTERNAL ? strerror(errno) :
|
||||
hstrerror(h_errno));
|
||||
return STAT_NORETRY;
|
||||
}
|
||||
netmask_in->s_addr = *(uint32_t *)maskaddr->h_addr_list[0];
|
||||
} else {
|
||||
Error1("xioparsenetwork(\"%s\",,): missing netmask delimiter", rangename);
|
||||
free(rangename1);
|
||||
return STAT_NORETRY;
|
||||
}
|
||||
{
|
||||
struct hostent *nameaddr;
|
||||
*delimpos = 0;
|
||||
if ((nameaddr = Gethostbyname(rangename1)) == NULL) {
|
||||
Error2("gethostbyname(\"%s\"): %s", rangename1,
|
||||
h_errno == NETDB_INTERNAL ? strerror(errno) :
|
||||
hstrerror(h_errno));
|
||||
free(rangename1);
|
||||
return STAT_NORETRY;
|
||||
}
|
||||
netaddr_in->s_addr = *(unsigned long *)nameaddr->h_addr_list[0];
|
||||
}
|
||||
free(rangename1);
|
||||
break;
|
||||
#endif /* WITH_IP4 */
|
||||
#if WITH_IP6
|
||||
case PF_INET6:
|
||||
return xioparsenetwork_ip6(rangename, &range->ip6);
|
||||
break;
|
||||
#endif /* WITH_IP6 */
|
||||
default:
|
||||
Error1("range option not supported with address family %d", pf);
|
||||
return STAT_NORETRY;
|
||||
}
|
||||
return STAT_OK;
|
||||
}
|
||||
|
||||
/* parses a string of form address/bits or address:mask, and fills the fields
|
||||
of the range union. The addr component is masked with mask. */
|
||||
int parserange(const char *rangename, int pf, union xiorange_union *range) {
|
||||
if (xioparsenetwork(rangename, pf, range) < 0) {
|
||||
return -1;
|
||||
}
|
||||
switch (pf) {
|
||||
#if WITH_IP4
|
||||
case PF_INET:
|
||||
range->ip4.netaddr.s_addr &= range->ip4.netmask.s_addr;
|
||||
break;
|
||||
#endif /* WITH_IP4 */
|
||||
#if WITH_IP6
|
||||
case PF_INET6:
|
||||
return xiorange_ip6andmask(&range->ip6);
|
||||
break;
|
||||
#endif /* WITH_IP6 */
|
||||
default:
|
||||
Error1("range option not supported with address family %d", pf);
|
||||
return STAT_NORETRY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if defined(HAVE_STRUCT_CMSGHDR) && defined(CMSG_DATA)
|
||||
/* these are valid for IPv4 and IPv6 */
|
||||
int xiolog_ancillary_ip(struct cmsghdr *cmsg, int *num,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue