From: lml@gandalf.inesc.pt (Luis Miguel Lageira)
Subject: DGRAM Sockets
Keywords: Sockets, DGRAM, UDP/IP
Organization: inesc
Date: Sat, 23 Jan 1993 20:16:26 GMT



	... --- ... ( S O S )

	Sorry about my last post. My interface to the USENET news system 
was not working properly and had to be recompiled. I hope it's OK now.


	Hi, there !

	I'm curently working on a project comparing distributed
algorithms for network diagnosis. For remote communication I'm using
DGRAM sockets (and XDR) and I'm having some trouble with the hosts
running SCO UNIX ODT 1.1.
	The problem appears when a datagram is sent to a port which
hasn't a socket associated with it ( because the host is down or the
process is not runing ). The sendto() call returns sucessefuly but the
next time I try to send something with that socket the error
Connection Refused is reported (errno == ECONNREFUSED). The socket
seems to remain in a brain dammaged state and no more messages are sent.
	If I rebind the socket ( what an ugly patch ... ) the socket
is capable of sending messages again but I still have to ignore the
error returned by the new bind() call and (re)send the message that got
the ECONNREFUSED error.
	Am I missing some of the socket options ?
	Is it a bug ?
		If it is, is there any patch for it ?
	Any help is welcome. Please mail it to lml@gandalf.inesc.pt or post
it to this newsgroup.


			Thanks a lot.


/*----------------------------------------------------------------------------+
|
|                      Here are some code fragments
|                                         ^^^^^^^^^
+----------------------------------------------------------------------------*/

/*
 *      Data needed for internet communication.
 */

struct Ethernet_Data {
    int socket_id;
    struct sockaddr_in inet_name;
};


/* ether_data_ptr is Ethernet_Data * type */

/*
 *	Socket creation (The system will select an apropriate protocol)
 */

    if((ether_data_ptr->socket_id = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
    {
        perror("\ncomm : Error opening INTERNET SOCK_DGRAM socket");
        return(-1);
    }

/*
 *	Socket binding to a name
 */

    ether_data_ptr->inet_name.sin_family = AF_INET; /* Internet domain */
    ether_data_ptr->inet_name.sin_addr.s_addr = INADDR_ANY;/* Listens to all*/
                                                      /* network interfaces */
    if (bind(ether_data_ptr->socket_id,
             (struct sockaddr*)&ether_data_ptr->inet_name,
             sizeof(struct sockaddr_in)) == -1) {
        close(ether_data_ptr->socket_id);
        perror("\ncomm : Error binding INTERNET DATAGRAM socket");
        return(-1);
    }

/*
 *	Message sending
 */

    if(sendto(((struct Ethernet_Data *)ether_data_ptr)->socket_id,
               mem_in_out_buf_ptr, /* Memory buffer with XDR data */
               MAX_LENGHT,
               0,
       (struct sockaddr *)&((struct Ethernet_Data *)ether_data_ptr)->inet_name,
               sizeof(struct sockaddr_in)) == -1)
        {
        perror("\ncomm (write): Error sending message to net");
        return(-1);
        }

------------------------------------------------------------------------------ 
   Luis Miguel Lageira @ INESC (Inst. Eng. Sistemas e Computadores)
       R. Alves Redol 9, 6. 1000 Lisbon, - PORTUGAL.
       Phone.: +351 1 3155150 Ext. : 257,341
   e-mail:  lml@gandalf.inesc.pt 
Newsgroups: biz.sco.opendesktop