File: socket.5c

package info (click to toggle)
nickle 2.68-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,336 kB
  • ctags: 3,288
  • sloc: ansic: 31,198; yacc: 1,860; lex: 858; sh: 830; makefile: 229
file content (34 lines) | stat: -rw-r--r-- 685 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
extend namespace Socket {
    public string addr_to_string (int addr) 
	/*
	 * Return a dotted quad from '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) 
	/*
	 * Parse a dotted quad
	 */
    {
	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;
}