aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-10-02 12:10:29 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-10-02 12:12:28 -0700
commit0035201655ece68da0e1f201e2028562869328d5 (patch)
treece4462607c831386db7bd543d3b2b24489315704 /src
parent550dc59e5461f276a146ee25940b45854ed1ca76 (diff)
gethostbyname initial support
Diffstat (limited to 'src')
-rw-r--r--src/library.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index d072d946..5d97b41f 100644
--- a/src/library.js
+++ b/src/library.js
@@ -6344,6 +6344,49 @@ LibraryManager.library = {
},
// ==========================================================================
+ // netdb.h
+ // ==========================================================================
+
+ // All we can do is alias names to ips. you give this a name, it returns an
+ // "ip" that we later know to use as a name. There is no way to do actual
+ // name resolving clientside in a browser.
+ // we do the aliasing in 172.29.*.*, giving us 65536 possibilities
+ // note: lots of leaking here!
+ 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;
+ }
+ var id = _gethostbyname.id++;
+ assert(id < 65535);
+ _gethostbyname.table[id] = name;
+ // generate hostent
+ var ret = _malloc(_gethostbyname.hostent_layout.__size__);
+ var nameBuf = _malloc(name.length+1);
+ writeStringToMemory(name, nameBuf);
+ setValue(ret+_gethostbyname.hostent_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');
+ 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**');
+ return ret;
+ },
+
+ // ==========================================================================
// sockets
// ==========================================================================