Created
          October 15, 2010 23:55 
        
      - 
      
 - 
        
Save orlandov/629171 to your computer and use it in GitHub Desktop.  
    Calling OS zone functions from node with node-ffi
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | FFI = require('./node-ffi/node-ffi'); | |
| var Zone = new FFI.Library("libc", { | |
| // ssize_t getzonenamebyid(zoneid_t id, char *buf, size_t buflen) | |
| "getzonenamebyid": [ "uint32", [ "uint32", 'pointer', "int32" ] ], | |
| "getzoneid": [ "int32", [] ], | |
| "getzoneidbyname": [ "int32", [ 'string' ] ] | |
| }); | |
| var str = new FFI.Pointer(64); | |
| ZONENAME_MAX = 64; | |
| var ret = Zone.getzonenamebyid(1183, str, 64); | |
| console.log("Zone id by name " + Zone.getzoneidbyname("orlandozone0")); | |
| console.log("This zone id " + Zone.getzoneid()); | |
| console.log("zone name " + str.getCString()); | |
| console.log("Return value was " + ret); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | orlando@sagan:master*!collector-emit$ node zone-ffi-test.js | |
| Zone id by name 1183 | |
| This zone id 0 | |
| zone name orlandozone0 | |
| Return value was 13 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment