[Python-Dev] _socket efficiencies ideas

Guido van Rossum guido@python.org
Wed, 09 Apr 2003 10:54:18 -0400


> On Wed, Apr 09, 2003 at 09:51:26AM -0400, Guido van Rossum wrote:
> >I didn't even know this, and I think it's bad style to use something
> >that obscure
> 
> Perhaps...  It's also bad style to break the obscure cases that are
> defined by the specifications...  ;-)

Sure.  I propose to special-case only what we *absolutely* *know* we
can handle, and if on closer inspection we can't (e.g. someone writes
999.999.999.999) we pass it on to the official code.  Here's the 2.1
code, which takes that approach:

	if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 &&
	    0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 &&
	    0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) {
		addr_ret->sin_addr.s_addr = htonl(
			((long) d1 << 24) | ((long) d2 << 16) |
			((long) d3 << 8) | ((long) d4 << 0));
		return 4;
	}

> >But since you seem to know about this stuff, perhaps you can submit a
> >patch?
> 
> I've updated my local CVS repository, I'll see if I can get a change
> done on the airplane today.

Great!

--Guido van Rossum (home page: http://www.python.org/~guido/)