Subject: Networking problem.
From: Eric Monsler <[email-masked]>
To: [email-masked]
Date: Mon, 22 Jan 2001 11:03:13 -0800

Hi,

I'm having a problem with a rather small cygwin project.  I installed
the latest net release as of 01/04/2001.

I've written a server application that opens a serial port, opens a
network socket and binds to a UDP port, and then waits for traffic on
one or the other.

Under cygwin, it initially seemed to compile and run properly, and two
such applications would bounce messages between each other on the serial
ports.

After writing the client application and attempting to test the UDP
connectivity, the server never receives UDP packets under cygwin.  

If I rerun "./configure" and re-make under Solaris, the server will
receive UDP packets and respond as expected.  It works both when the
client uses 127.0.0.1 from the same machine, or for a client on another
machine using the IP of the Sun.

Since the calls to socket, bind, and select all seem to succeed, and the
code runs under Solaris, I'm not quite sure how to proceed with
debugging this problem.  Any suggestions?  Relevent code snippets are
below.

TIA,

Eric Monsler

/* This code opens the socket and binds it to a UDP port */
int init_udp_if(void)
{
  
  int	sockfd;
  int	bind_ret;

  int len;
  struct sockaddr_in boundaddr;

  /* Create the Socket */
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
#if DEBUG
  printf("Opening socket returned: %d\n", sockfd);
#endif
  if(sockfd < 0)
    {
      /* Error, return fail */
      return sockfd;
    }

  /* Clear and initialize server address structure */
  memset(&servaddr, 0x0, sizeof(servaddr));

  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = (AV_DEFAULT_UDP_PORT);

  /* Bind our socket to the desired port
	"Bind" wraps "bind" and checks return value. */
  Bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  
  len = sizeof(boundaddr);
  getsockname(sockfd, (struct sockaddr *)&boundaddr, &len);
  printf("Socket bound to IP 0x%08x port %d\n", 
	 boundaddr.sin_addr.s_addr,
	 boundaddr.sin_port);

  return sockfd;
      
}

/*
	This is the pending for message portion of the server code
*/

  while(!(have_msg))
    {
      /* Clear and set up file descriptor array, descriptors read for
     reading, for 'select' */

      //      printf("About to FD_ZERO\n");

      FD_ZERO(&rset);

      /* Set up fd_set and call select. */
      FD_SET(udp_socket_fd,&rset);
      FD_SET(serial_fd,&rset);
      maxfdp = MAX(udp_socket_fd,serial_fd) +1;
      
      /* Now pend on our input file descriptors, until data is
	 available or unti we timeout. */
      sel_ret = select(maxfdp, &rset, NULL, NULL, &sel_timeout);

      /* Check if we timed out.  If so, increment a counter; if not,
	 try to read data */
      if(sel_ret == 0)
	{
	  /* We timed out! */
	  /* Do some metrics, or something */

	  printf("Timed out waiting for messages\n");
	}
      else
	{
	  /* Check if we have UDP data to get */
	  if( FD_ISSET(udp_socket_fd,&rset) )
	    {
	      unsigned long 	ip_msg_sender;
	      unsigned short	port_msg_sender;
	      unsigned long	msg_length;
	      
	      /* Try to receive a message!
	     
		 If data is available, it should be a whole packet */

	      printf("Reading UDP datagram\n");
 	      /* Code deleted */
	    }
	  
	  /* Check if we have Serial data to get */
	  if( FD_ISSET(serial_fd,&rset) )
	    {
	      /* Try to receive a message!
		 
		 Note that 'data' available in the serial interface
		 does not mean that the whoe message is available! */
	      unsigned long	msg_length;

	      printf("Reading Serial data\n");

	      /* Code Deleted */	      
	    }	   
	}
    }

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple