lkml.org 
[lkml]   [2000]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
Subjectsendto call on a UDP socket gives ECONNREFUSED



Hi,

I am using linux kernel 2.2.14 on an i686 platform. I tried a simple program as
given below

------------------snip----------------------

emudev~/workshop $ cat sendto.c
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <errno.h>

main()
{
struct sockaddr_in sin;
int sd, i;

memset(&sin, 0, sizeof(sin));
sin.sin_port = htons(4000);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr("127.0.0.1");

sd = socket(AF_INET, SOCK_DGRAM, 0);

for (i = 0; i < 4; i++)
if (sendto(sd, NULL, 0, 0, (struct sockaddr *)&sin, sizeof(sin)) == -1)
perror("sendto");
}

emudev~/workshop $ make sendto
cc sendto.c -o sendto
emudev~/workshop $ ./sendto
sendto: Connection refused
sendto: Connection refused
emudev~/workshop $
-----------------------------snip------------------------------

As you can see in the output given above sendto returns failure with error
ECONNREFUSED.
The sento call succeeds if we have a receiving socket on the remote end i.e. at
port 4000.
Since it as a UDP socket sendto must not fail even if the remote end does not
exist also the error its giving seems to be quite irrelevant.
This happens only if the remote endpoint is on the local host.
Another point to note is that sendto succeeds and fails in alternate calls, thus
in four tries it fails two times and succeeds two times in the example given
above.

Why is this happening?


Thanks and Regards

-harendra



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:56    [W:0.064 / U:0.152 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site