Tool
An update to the verry handy cool solution Sample Code - LDAPNetAddr
I found that recently our edir returned an addresstype 9 (tcp) instead of 1 (IP), which wasn't handled correctly by the sample code. I've modified the code to handle these addresses correctly.
function LDAPNetAddr ($networkaddress) {
/*
Initial version: Jay Burrell, Systems & Networks, Mississippi State University
Updated by Peter Havekes to support addresstype 9
NetAddr - extract readable network address from the LDAP encoded networkAddress attribute.
Novell Docs, see: http://developer.novell.com/ndk/doc/ndslib/schm_en...
for Address types: http://developer.novell.com/ndk/doc/ndslib/index.h...
LDAP Format, String:
taggedData = uint32String "#" octetstring
byte 0 = uint32String = Address Type: 0= IPX Address; 1 = IP Address
byte 1 = char = "#" - separator
byte 2+ = octetstring - the ordinal value of the address
Note: with eDirectory 8.6.2, the IP address (type 1) returns correctly, however, an IPX address does not seem to. eDir 8.7 may correct this.
*/
$addr = "";
$addrtype = intval(substr($networkaddress, 0, 1));
$networkaddress = substr($networkaddress, 2); // throw away bytes 0 and 1 which should be the addrtype and the "#" separator
$addrtypes = array('IPX', 'IP', 'SDLC', 'Token Ring', 'OSI', 'AppleTalk', 'NetBEUI', 'Socket', 'UDP', 'TCP', 'UDP6', 'TCP6', 'Reserved (12)', 'URL', 'Count');
$len = strlen($networkaddress);
if ($len > 0) {
for ($i=0; $i<$len; $i+=1) {
$byte = substr($networkaddress, $i, 1);
$addr .= ord($byte);
if ($addrtype == 1){ // dot separate IP addresses...
$addr .= ".";
}
if ($addrtype == 9 ){
$addr .= ".";
}
}
if ($addrtype == 1) { // strip last period from end of $addr
$addr = substr($addr, 0, strlen($addr)-1);
}
if ($addrtype == 9 ){
$addr = substr($addr,4,strlen($addr)-5);
}
}
else {
$addr .= "address not available.";
}
return ($addr);
}
Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).
It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.
Related Articles
User Comments
- Be the first to comment! To leave a comment you need to Login or Register
- 6124 reads


0