aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-11-08 12:22:35 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-11-08 12:22:35 -0800
commit118a6bd6c5aca371ecfcf9f7baf748a7dfd43351 (patch)
tree0f36050b3b3702a852e7cbda547539c9d446aae8 /src
parent2ac32ae20a38029c1fffd9e162c92f9370283dd7 (diff)
support inet_ntoa and inet_aton, and fix inet_ntop bug with not writing null terminator
Diffstat (limited to 'src')
-rw-r--r--src/library.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/library.js b/src/library.js
index 73109334..c7fe9fcb 100644
--- a/src/library.js
+++ b/src/library.js
@@ -6459,10 +6459,26 @@ LibraryManager.library = {
inet_ntop: function(af, src, dst, size) {
var addr = getValue(src, 'i32');
var str = __inet_ntop_raw(addr);
- writeStringToMemory(str.substr(0, size), dst, true);
+ writeStringToMemory(str.substr(0, size), dst);
return dst;
},
+ inet_ntoa__deps: ['inet_ntop'],
+ inet_ntoa: function(in_addr) {
+ if (!_inet_ntoa.buffer) {
+ _inet_ntoa.buffer = _malloc(1024);
+ }
+ return _inet_ntop(0, in_addr, _inet_ntoa.buffer, 1024);
+ },
+
+ inet_aton__deps: ['inet_addr'],
+ inet_aton: function(cp, inp) {
+ var addr = _inet_addr(cp);
+ setValue(inp, addr, 'i32');
+ if (addr < 0) return 0;
+ return 1;
+ },
+
// ==========================================================================
// netdb.h
// ==========================================================================