[Commit] nickle socket.5c,NONE,1.1

Keith Packard commit at keithp.com
Tue Jun 10 23:02:44 PDT 2003


Committed by: keithp

Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv10121

Added Files:
	socket.5c 
Log Message:
Add a couple of network address conversion utilities

--- NEW FILE: socket.5c ---
extend namespace Socket {
    public string addr_to_string (int addr) {
	return sprintf ("%d.%d.%d.%d",
			(addr >> 24) & 0xff,
			(addr >> 16) & 0xff,
			(addr >> 8) & 0xff,
			(addr) & 0xff);
    }
    
    public int string_to_addr (string addr) {
	int r = File::sscanf (addr, "%d.%d.%d.%d", 
			&(int a), &(int b), &(int c), &(int d));
	if (r != 4)
	    raise invalid_argument ("invalid network address format",
				    r, addr);
	return (a << 24) + (b << 16) + (c << 8) + d;
    }
}

/*
 * backwards compatibility for old namespace name 
 */

namespace Sockets {
    public import Socket;
}




More information about the Commit mailing list