This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: connect() does not work with UNIX domain datagram sockets


Some additional information about my problem :

cygwin 1.3.10 running on Windows NT 4.0.

Here follows a set of programs (client.c, server.c) that exhibit
the problem.
If you #define USE_SENDTO in client.c, the communication works.

I will also send a strace to Egor Duda.

Erik Devriendt



# ---------- makefile -------------
all: server client


client: client.c
	gcc -o client client.c

server: server.c
	gcc -o server server.c

# --------- end of makefile ------

/* ------- begin of server.c ------------ */

#include <errno.h>

#include <sys/types.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/fcntl.h>
#include <time.h>


int main(int argc, char *argv[])
{
   struct sockaddr_un name;
   int socket_id;
   int s;
   struct sockaddr saddr;
   int saddrlen;
   char buf[1024];
   int result;

   name.sun_family = AF_UNIX;
   strcpy(name.sun_path, "./testsock");
   
   if ((socket_id=socket(AF_UNIX, SOCK_DGRAM,0)) <0 )
   {  
      printf("socket() gave errno = %d : %s\n", errno, strerror(errno));
      exit(1);
   }
   
   if ((bind(socket_id,(struct sockaddr *)&name,sizeof(name))) <0)
   {
      printf("bind() gave errno = %d : %s\n", errno, strerror(errno));
      exit(1);
   }
   
   printf("OK, socket_id = %d\n", socket_id);
   
   result = read(socket_id, buf, sizeof(buf));

   if(result > 0)
	printf("read %d bytes : <%s>\n", result, buf);
   return 0;
}

/* ------- end of server.c ------------ */

/* ------- begin of client.c ------------ */

#include <errno.h>

#include <sys/types.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/fcntl.h>
#include <time.h>


int main(int argc, char *argv[])
{
   struct sockaddr_un name;
   int socket_id, socket_id2;
   char buf[100];
   int sendresult;

   name.sun_family = AF_UNIX;
   strcpy(name.sun_path, "./testsock");
   
   if ((socket_id=socket(AF_UNIX, SOCK_DGRAM,0)) <0 )
   {  
      printf("socket() gave errno = %d : %s\n", errno, strerror(errno));
      exit(1);
   }
   
   strcpy(buf, "hallo\n");

/* #define  USE_SENDTO */
   
#ifdef USE_SENDTO
   sendresult = sendto(socket_id, buf, strlen(buf)+1, 0, (struct sockaddr *)&name, sizeof(name) );
#else
   if ( connect(socket_id, (struct sockaddr *)&name, sizeof(name)) < 0)
   {
      printf("connect() gave errno = %d : %s\n", errno, strerror(errno));
      exit(1);
   }
   sendresult = write(socket_id, buf,  strlen(buf)+1);
#endif
   printf("sendresult = %d\n", sendresult);
   if(sendresult < 0)
   {
      printf("sendto() gave errno = %d : %s\n", errno, strerror(errno));
      exit(1);
   }

   
   
   printf("OK, socket_id = %d\n", socket_id);
   
   return 0;
}

/* ------- begin of client.c ------------ */


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]