Created
September 3, 2010 01:20
-
-
Save harthur/563250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Components.utils.import("resource://gre/modules/ctypes.jsm"); | |
var EXPORTED_SYMBOLS = ["open"]; | |
nspr = ctypes.open('/Applications/Minefield.app/Contents/MacOS/libnspr4.dylib'); | |
var PR_AF_INET = 2; | |
var port = 2387; | |
// PR_SetNetAddr(val, PR_AF_INET, aPort, &addr); | |
var PR_IpAddrAny = 1; | |
var addrType = ctypes.StructType("PRNetAddr", | |
[{'family': ctypes.int16_t}, {'port': ctypes.int16_t}, {'ip': ctypes.int32_t}, | |
{'pad' : ctypes.char.array(8)}] | |
); | |
var PR_SetNetAddr = nspr.declare("PR_SetNetAddr", | |
ctypes.default_abi, | |
ctypes.int32_t, // really doesn't return anything | |
ctypes.int32_t, // val | |
ctypes.int16_t, // af | |
ctypes.int16_t, // port | |
addrType.ptr) | |
var addr = addrType(); | |
var ret = PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET, port, addr.address()); | |
// PR_Bind(serverFD, &addr); | |
/* open */ | |
var PR_OpenTCPSocket = nspr.declare("PR_OpenTCPSocket", // symbol name | |
ctypes.default_abi, // cdecl calling convention | |
ctypes.StructType("PRFileDesc").ptr, // return (PRFileDesc*) | |
ctypes.int32_t) // first arg | |
var fd = PR_OpenTCPSocket(PR_AF_INET); | |
var PR_Bind = nspr.declare("PR_Bind", | |
ctypes.default_abi, | |
ctypes.int32_t, | |
ctypes.StructType("PRFileDesc").ptr, | |
addrType.ptr); | |
var success = PR_Bind(fd, addr.address()); | |
dump(success) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error: expected type pointer, got PRFileDesc.ptr(ctypes.UInt64("0x157ad110"))
Source File: resource://jsbridge/modules/socket.js
Line: 48