Index: tclUnixChan.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixChan.c,v
retrieving revision 1.42
diff -p -r1.42 tclUnixChan.c
*** tclUnixChan.c	21 Feb 2003 02:36:27 -0000	1.42
--- tclUnixChan.c	27 Sep 2003 16:24:59 -0000
*************** Tcl_MakeFileChannel(handle, mode)
*** 1889,1896 ****
  #ifdef DEPRECATED
      ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
  #endif /* DEPRECATED */
!     int socketType = 0;
!     socklen_t argLength = sizeof(int);
  
      if (mode == 0) {
  	return NULL;
--- 1889,1896 ----
  #ifdef DEPRECATED
      ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
  #endif /* DEPRECATED */
!     struct sockaddr_storage sockaddr;
!     socklen_t sockaddrLen = sizeof(sockaddr);
  
      if (mode == 0) {
  	return NULL;
*************** Tcl_MakeFileChannel(handle, mode)
*** 1911,1916 ****
--- 1911,1918 ----
      }
  #endif /* DEPRECATED */
  
+     sockaddr.ss_family = AF_UNSPEC;
+ 
  #ifdef SUPPORTS_TTY
      if (isatty(fd)) {
  	fsPtr = TtyInit(fd, 0);
*************** Tcl_MakeFileChannel(handle, mode)
*** 1918,1930 ****
  	sprintf(channelName, "serial%d", fd);
      } else
  #endif /* SUPPORTS_TTY */
!     if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (VOID *)&socketType,
! 		   &argLength) == 0  &&	 socketType == SOCK_STREAM) {
! 	return MakeTcpClientChannelMode((ClientData) fd, mode);
      } else {
! 	channelTypePtr = &fileChannelType;
! 	fsPtr = (FileState *) ckalloc((unsigned) sizeof(FileState));
! 	sprintf(channelName, "file%d", fd);
      }
  
  #ifdef DEPRECATED
--- 1920,1934 ----
  	sprintf(channelName, "serial%d", fd);
      } else
  #endif /* SUPPORTS_TTY */
!     if (getsockname(fd, (struct sockaddr *)&sockaddr, &sockaddrLen) == 0
!             && sockaddrLen > 0
!             && sockaddr.ss_family != AF_UNSPEC
!             && sockaddr.ss_family != AF_LOCAL) {
!         return MakeTcpClientChannelMode((ClientData) fd, mode);
      } else {
!         channelTypePtr = &fileChannelType;
!         fsPtr = (FileState *) ckalloc((unsigned) sizeof(FileState));
!         sprintf(channelName, "file%d", fd);
      }
  
  #ifdef DEPRECATED
