aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-01-26 21:04:21 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-01-26 21:04:21 -0800
commit66b60aebd4f94069136ee6af5e768ad586eb948f (patch)
treeb42a8211fbf468439f7fe44fd85e54e218e0e67a
parent01e21e541251d271d28e92b2c6b28a8290994470 (diff)
ntohl etc.
-rw-r--r--src/library.js14
-rwxr-xr-xtests/runner.py12
2 files changed, 26 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index 5a429131..355a0c61 100644
--- a/src/library.js
+++ b/src/library.js
@@ -5715,6 +5715,20 @@ LibraryManager.library = {
},
// ==========================================================================
+ // arpa/inet.h
+ // ==========================================================================
+
+ htonl: function(value) {
+ return ((value & 0xff) << 24) + ((value & 0xff00) << 8) +
+ ((value & 0xff0000) >> 8) + ((value & 0xff000000) >> 24);
+ },
+ htons: function(value) {
+ return ((value & 0xff) << 8) + ((value & 0xff00) >> 8);
+ },
+ ntohl: 'htonl',
+ ntohs: 'htons',
+
+ // ==========================================================================
// emscripten.h
// ==========================================================================
diff --git a/tests/runner.py b/tests/runner.py
index 126071a0..68ad6361 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -3837,6 +3837,18 @@ def process(filename):
'''
self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected))
+ def test_inet(self):
+ src = r'''
+ #include <stdio.h>
+ #include <arpa/inet.h>
+
+ int main() {
+ printf("*%x,%x,%x,%x*\n", htonl(0x12345678), htons(0xabcd), ntohl(0x43211234), ntohs(0xbeaf));
+ return 0;
+ }
+ '''
+ self.do_run(src, '*78563412,cdab,34122143,afbe*')
+
def test_ctype(self):
# The bit fiddling done by the macros using __ctype_b_loc requires this.
Settings.CORRECT_SIGNS = 1