diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-03 11:29:51 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-03 11:29:51 -0700 |
commit | 20cd14971fd5aeb5c731ef0e17b586c5a46b27f9 (patch) | |
tree | 07107dd7edf73be37a4c6cf62cdc4bf4c19d2589 /src | |
parent | cc14e2ad3a8764b3ee56fee0a7a71dc5be3de5ec (diff) |
fix gethostbyname closure error
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/library.js b/src/library.js index 7757bf75..72fb07e7 100644 --- a/src/library.js +++ b/src/library.js @@ -6352,37 +6352,39 @@ LibraryManager.library = { // name resolving clientside in a browser. // we do the aliasing in 172.29.*.*, giving us 65536 possibilities // note: lots of leaking here! + __hostent_struct_layout: Runtime.generateStructInfo([ + ['i8*', 'h_name'], + ['i8**', 'h_aliases'], + ['i32', 'h_addrtype'], + ['i32', 'h_length'], + ['i8**', 'h_addr_list'], + ]), + gethostbyname__deps: ['__hostent_struct_layout'], gethostbyname: function(name) { name = Pointer_stringify(name); - if (!_gethostbyname.hostent_layout) { - _gethostbyname.hostent_layout = Runtime.generateStructInfo([ - ['i8*', 'h_name'], - ['i8**', 'h_aliases'], - ['i32', 'h_addrtype'], - ['i32', 'h_length'], - ['i8**', 'h_addr_list'], - ]); - _gethostbyname.table = {}; - _gethostbyname.id = 0; - } + if (!_gethostbyname.id) { + _gethostbyname.id = 1; + _gethostbyname.table = {}; + } var id = _gethostbyname.id++; assert(id < 65535); + var fakeAddr = 172 | (29 << 8) | ((id & 0xff) << 16) | ((id & 0xff00) << 24); _gethostbyname.table[id] = name; // generate hostent - var ret = _malloc(_gethostbyname.hostent_layout.__size__); + var ret = _malloc(___hostent_struct_layout.__size__); var nameBuf = _malloc(name.length+1); writeStringToMemory(name, nameBuf); - setValue(ret+_gethostbyname.hostent_layout.h_name, nameBuf, 'i8*'); + setValue(ret+___hostent_struct_layout.h_name, nameBuf, 'i8*'); var aliasesBuf = _malloc(4); setValue(aliasesBuf, 0, 'i8*'); - setValue(ret+_gethostbyname.hostent_layout.h_aliases, aliasesBuf, 'i8**'); - setValue(ret+_gethostbyname.hostent_layout.h_addrtype, {{{ cDefine("AF_INET") }}}, 'i32'); - setValue(ret+_gethostbyname.hostent_layout.h_length, 4, 'i32'); + setValue(ret+___hostent_struct_layout.h_aliases, aliasesBuf, 'i8**'); + setValue(ret+___hostent_struct_layout.h_addrtype, {{{ cDefine("AF_INET") }}}, 'i32'); + setValue(ret+___hostent_struct_layout.h_length, 4, 'i32'); var addrListBuf = _malloc(12); setValue(addrListBuf, addrListBuf+8, 'i32*'); setValue(addrListBuf+4, 0, 'i32*'); - setValue(addrListBuf+8, 172 | (29 << 8) | ((id & 0xff) << 16) | ((id & 0xff00) << 24), 'i32'); - setValue(ret+_gethostbyname.hostent_layout.h_addr_list, addrListBuf, 'i8**'); + setValue(addrListBuf+8, fakeAddr, 'i32'); + setValue(ret+___hostent_struct_layout.h_addr_list, addrListBuf, 'i8**'); return ret; }, |