[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] getaddrinfo() in socketopen() (io.c) fails for AF_INET[46] --
From: |
Houder |
Subject: |
[bug-gawk] getaddrinfo() in socketopen() (io.c) fails for AF_INET[46] -- unnecessarily |
Date: |
Thu, 08 Feb 2018 18:59:04 +0100 |
User-agent: |
XS4ALL Webmail |
L.S.,
(Using Fedora 24)
gawkinet.pdf ("TCP/IP (Inter)Networking with gawk") outlines a simple
"Panic" webserver in section 3.1 (page 35).
The script is as follows:
BEGIN {
RS = ORS = "\r\n"
if (MyPort == 0) MyPort = 8080
HttpService = "/inet/tcp/" MyPort "/0/0"
#HttpService = "/inet4/tcp/" MyPort "/0/0"
#HttpService = "/inet6/tcp/" MyPort "/0/0"
Hello = "<HTML><HEAD><TITLE>Out Of Service</TITLE>" \
"</HEAD><BODY><H1>" \
"This site is temporarily out of service." \
"</H1></BODY></HTML>"
Len = length(Hello) + length(ORS)
print "Ha!"
HttpService
#while ("awk" != "complex") {
while (" ") {
print "HTTP/1.0 200 OK" |& HttpService
print "Content-Length: " Len ORS |& HttpService
print Hello |& HttpService
while ((HttpService |& getline) > 0)
continue;
close(HttpService)
}
}
If "/inet" in the definition of HttpService (see above) is replaced
by either "/inet4" or "/inet6",
the script fails in case the loopback interface is the only one
that is up (i.e. all other network interfaces are down)
@@ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel
state UP group default qlen 1000
link/ether 74:d0:2b:a0:4b:40 brd ff:ff:ff:ff:ff:ff
Using gawk-4.2.0, the script fails with: (if using /inet4 i.s.o. /inet)
warning: local port 8080 invalid in `/inet': Name or service not known
fatal: can't open two way pipe `/inet4/tcp/8080/0/0' for input/output
(No such file or directory)
The script fails because getaddrinfo() in socketopen() (gawk-4.2.0/io.c)
fails ... but unnecessarily (I believe).
Modifying gawk-4.2.0/io.c as follows, prevents getaddrinfo() from
failing:
static int
socketopen(int family, int type, const char *localpname,
const char *remotepname, const char *remotehostname, bool
*hard_error)
{
[snip]
memset(& lhints, '\0', sizeof (lhints));
/* if only the loopback interface is up and hints.ai_flags has
AI_ADDRCONFIG,
getaddrinfo() will return the addresses of the loopback
interface, but only
if hints.ai_family == AF_UNSPEC
*/
lhints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
lhints.ai_socktype = type;
lhints.ai_family = family;
// do return the loopback address in case the loopback interface is
the only one that
// is up (and hints.ai_family == AF_INET[46])
if ( (lhints.ai_family == AF_INET) || (lhints.ai_family == AF_INET6) )
lhints.ai_flags = AI_PASSIVE;
lerror = getaddrinfo(NULL, localpname, & lhints, & lres);
...
Henri
- [bug-gawk] getaddrinfo() in socketopen() (io.c) fails for AF_INET[46] -- unnecessarily,
Houder <=