[Patches] Now including the patch: Adding message text for (some) Winsock errors, adding "0" as a synonym for INADDR_ANY,

Pekka Pessi Pekka.Pessi@nokia.com
Tue, 18 Jul 2000 13:39:41 +0300 (EEST)


--QHKZn1oXFR
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit


	The first patch is for convenience on Windows platform. It contains
	standard (stderror()-like) error messages for (some) Winsock errors.

	The second patch is due to broken gethostbyname() on some
	platforms. ("0" is valid IP address - dot notation without a dot,
	like 0xfffffc00 when specifying a netmask. Unfortunately, "0" is not
	regonized by some Windows platforms.)

	Regards,
				Pekka Pessi


--QHKZn1oXFR
Content-Type: text/plain
Content-Description: patch
Content-Disposition: inline;
	filename="patch"
Content-Transfer-Encoding: 7bit

*** socketmodule.c.orig	Tue Jul 18 13:14:12 2000
--- socketmodule.c	Tue Jul 18 13:18:28 2000
***************
*** 281,288 ****
  {
  #ifdef MS_WINDOWS
  	if (WSAGetLastError()) {
  		PyObject *v;
! 		v = Py_BuildValue("(is)", WSAGetLastError(), "winsock error");
  		if (v != NULL) {
  			PyErr_SetObject(PySocket_Error, v);
  			Py_DECREF(v);
--- 281,359 ----
  {
  #ifdef MS_WINDOWS
  	if (WSAGetLastError()) {
+ 		static struct { int no; const char *msg; } *msgp, msgs[] = {
+ 			{ WSAEINTR, "Interrupted system call" },
+ 			{ WSAEBADF, "Bad file descriptor" },
+ 			{ WSAEACCES, "Permission denied" },
+ 			{ WSAEFAULT, "Bad address" },
+ 			{ WSAEINVAL, "Invalid argument" },
+ 			{ WSAEMFILE, "Too many open files" },
+ 			{ WSAEWOULDBLOCK, "Another winsock call while a "
+ 			  "blocking function was in progress" },
+ 			{ WSAEINPROGRESS, "Operation now in progress" },
+ 			{ WSAEALREADY, "Operation already in progress" },
+ 			{ WSAENOTSOCK, "Socket operation on non-socket" },
+ 			{ WSAEDESTADDRREQ, "Destination address required" },
+ 			{ WSAEMSGSIZE, "Message too long" },
+ 			{ WSAEPROTOTYPE, "Protocol wrong type for socket" },
+ 			{ WSAENOPROTOOPT, "Protocol not available" },
+ 			{ WSAEPROTONOSUPPORT, "Protocol not supported" },
+ 			{ WSAESOCKTNOSUPPORT, "Socket type not supported" },
+ 			{ WSAEOPNOTSUPP, "Operation not supported" },
+ 			{ WSAEPFNOSUPPORT, "Protocol family not supported" },
+ 			{ WSAEAFNOSUPPORT, "Address family not supported" },
+ 			{ WSAEADDRINUSE, "Address already in use" },
+ 			{ WSAEADDRNOTAVAIL, "Can't assign requested address" },
+ 			{ WSAENETDOWN, "Network is down" },
+ 			{ WSAENETUNREACH, "Network is unreachable" },
+ 			{ WSAENETRESET, "Network dropped connection on reset" },
+ 			{ WSAECONNABORTED, "Software caused connection abort" },
+ 			{ WSAECONNRESET, "Connection reset by peer" },
+ 			{ WSAENOBUFS, "No buffer space available" },
+ 			{ WSAEISCONN, "Socket is already connected" },
+ 			{ WSAENOTCONN, "Socket is not connected" },
+ 			{ WSAESHUTDOWN, "Can't send after socket shutdown" },
+ 			{ WSAETOOMANYREFS, "Too many references: "
+ 			  "can't splice" },
+ 			{ WSAETIMEDOUT, "Operation timed out" },
+ 			{ WSAECONNREFUSED, "Connection refused" },
+ 			{ WSAELOOP, "Too many levels of symbolic links" },
+ 			{ WSAENAMETOOLONG, "File name too long" },
+ 			{ WSAEHOSTDOWN, "Host is down" },
+ 			{ WSAEHOSTUNREACH, "No route to host" },
+ 			{ WSAENOTEMPTY, "Directory not empty" },
+ 			{ WSAEPROCLIM, "Too many processes" },
+ 			{ WSAEUSERS, "Too many users" },
+ 			{ WSAEDQUOT, "Disc quota exceeded" },
+ 			{ WSAESTALE, "Stale NFS file handle" },
+ 			{ WSAEREMOTE, "Too many levels of remote in path" },
+ 			{ WSASYSNOTREADY, "Network subsystem is unvailable" },
+ 			{ WSAVERNOTSUPPORTED, "WinSock version is not "
+ 			  "supported" },
+ 			{ WSANOTINITIALISED, "Successful WSAStartup() not yet "
+ 			  "performed" },
+ 			{ WSAEDISCON, "Graceful shutdown in progress" },
+ 			/* Resolver errors */
+ 			{ WSAHOST_NOT_FOUND, "No such host is known" },
+ 			{ WSATRY_AGAIN, "Host not found, or server failed" },
+ 			{ WSANO_RECOVERY, "Unexpected server error "
+ 			  "encountered" },
+ 			{ WSANO_DATA, "Valid name without requested data" },
+ 			{ WSANO_ADDRESS, "No address, look for MX record" },
+ 			{ 0, NULL }
+ 		};
  		PyObject *v;
! 		int no = WSAGetLastError();
! 		const char *msg = "winsock error";
! 		
! 		for (msgp = msgs; msgp->msg; msgp++) {
! 			if (no == msgp->no) {
! 				msg = msgp->msg;
! 				break;
! 			}
! 		}
! 
! 		v = Py_BuildValue("(is)", no, msg);
  		if (v != NULL) {
  			PyErr_SetObject(PySocket_Error, v);
  			Py_DECREF(v);
***************
*** 405,411 ****
  
  /* Convert a string specifying a host name or one of a few symbolic
     names to a numeric IP address.  This usually calls gethostbyname()
!    to do the work; the names "" and "<broadcast>" are special.
     Return the length (should always be 4 bytes), or negative if
     an error occurred; then an exception is raised. */
  
--- 476,482 ----
  
  /* Convert a string specifying a host name or one of a few symbolic
     names to a numeric IP address.  This usually calls gethostbyname()
!    to do the work; the names "", "0", "-1" and "<broadcast>" are special.
     Return the length (should always be 4 bytes), or negative if
     an error occurred; then an exception is raised. */
  
***************
*** 431,441 ****
  #endif /* HAVE_GETHOSTBYNAME_R */
  
  	memset((void *) addr_ret, '\0', sizeof(*addr_ret));
! 	if (name[0] == '\0') {
  		addr_ret->sin_addr.s_addr = INADDR_ANY;
  		return 4;
  	}
! 	if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) {
  		addr_ret->sin_addr.s_addr = INADDR_BROADCAST;
  		return 4;
  	}
--- 502,513 ----
  #endif /* HAVE_GETHOSTBYNAME_R */
  
  	memset((void *) addr_ret, '\0', sizeof(*addr_ret));
! 	if (name[0] == '\0' || name[0] == '0' && name[1] == '\0') {
  		addr_ret->sin_addr.s_addr = INADDR_ANY;
  		return 4;
  	}
! 	if (name[0] == '<' && strcmp(name, "<broadcast>") == 0 ||
! 	    strcmp(name, "-1") == 0) {
  		addr_ret->sin_addr.s_addr = INADDR_BROADCAST;
  		return 4;
  	}


--QHKZn1oXFR
Content-Type: text/plain
Content-Disposition: inline;
	filename="stddisclaimer.py"
Content-Transfer-Encoding: 7bit

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.

--QHKZn1oXFR--