[erlang-questions] inet_res:getbyname/2 and udp:connect/3
Per Hedeland
per@REDACTED
Thu Jun 17 00:33:49 CEST 2010
Tony Rogvall <tony@REDACTED> wrote:
>Cool!
>send is failing on subsequent send, but recv is not ???? This is strange
>times.
Erlang gen_udp:recv() is not failing.
>Do you think this behavior is documented anywhere?
'man inet_drv' maybe?
>A small C program may clear this issue for us ?
A small C program (below) works perfectly:
$ ./conn_udp
recv: Connection refused
I might point out that the "connect UDP socket in resolver code" trick
was invented in BSD code at a point in time when not much else even
*had* TCP/IP.:-)
But inet_drv is "slightly" more complex than that program...
>To get the {error, econnrefused} speed things up when trying servers
>where DNS servers may have crashed.
Yes, but it's not DNS-specific of course, it can be useful for any
UDP-based protocol.
>But in the general case, server may be down/burned, routers is
>down/corrupt, this will not help since no one will send
>the ICMP reply message on the network.
True - and add to that misconfigured firewalls that drop all ICMP
packets and there is probably not much usefulness left. Maybe just as a
way to quickly find out if you are running a local server.
--Per
conn_udp.c---------------------------------------------
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
int error(char *str)
{
perror(str);
exit(1);
}
int main()
{
struct sockaddr_in addr;
int fd;
char buf[1];
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_family = AF_INET;
addr.sin_port = htons(12345);
buf[0] = 'x';
if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
error("socket");
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
error("connect");
if (send(fd, buf, sizeof(buf), 0) < 0)
error("send");
if (recv(fd, buf, sizeof(buf), 0) < 0)
error("recv");
return 0;
}
More information about the erlang-questions
mailing list