cvs: peardoc /en/package networking.xml /en/package/networking net-mac.xml /en/package/networking/net-mac check.xml constants.xml constructor.xml
findvendor.xml format.xml importvendors.xml net-mac-exception.xml setmac.xml
| From: | Andrew Teixeira | Date: | Sat, 30 Dec 2006 22:57:48 +0000 |
| Subject: | cvs: peardoc /en/package networking.xml /en/package/networking net-mac.xml /en/package/networking/net-mac check.xml constants.xml constructor.xml findvendor.xml format.xml importvendors.xml net-mac-exception.xml setmac.xml |
||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-9173@lists.php.net to get a copy of this message | ||
atex Sat Dec 30 22:57:48 2006 UTC
Added files:
/peardoc/en/package/networking net-mac.xml
/peardoc/en/package/networking/net-mac check.xml constants.xml
constructor.xml
findvendor.xml format.xml
importvendors.xml
net-mac-exception.xml
setmac.xml
Modified files:
/peardoc/en/package networking.xml
Log:
- Added the en/package/networking/net-mac directory to house the
Net_MAC docmentation
- Added documentation files to en/package/networking/net-mac/
- Added en/package/networking/net-mac.xml
- Updated en/package/networking.xml to contain a link to the new
Net_MAC package
http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking.xml?r1=1.19&r2=1.20&diff_format=u Index: peardoc/en/package/networking.xml diff -u peardoc/en/package/networking.xml:1.19 peardoc/en/package/networking.xml:1.20 --- peardoc/en/package/networking.xml:1.19 Sun Oct 29 21:24:36 2006 +++ peardoc/en/package/networking.xml Sat Dec 30 22:57:48 2006 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.19 $ --> +<!-- $Revision: 1.20 $ --> <chapter id="package.networking"> <title>Networking</title> @@ -19,6 +19,7 @@ &package.networking.net-geoip; &package.networking.net-ipv4; &package.networking.net-ipv6; + &package.networking.net-mac; &package.networking.net-nntp; &package.networking.net-ping; &package.networking.net-pop3; http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac.xml +++ peardoc/en/package/networking/net-mac.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.networking.net-mac"> <title>Net_MAC</title> <para> This package validates and cleanly formats Media Access Control (MAC) addresses. The Net_MAC class can also import a list of MAC address vendors and store them in a database which the class can then use to identify vendors of any MAC address. </para> &package.networking.net-mac.constants; &package.networking.net-mac.check; &package.networking.net-mac.format; &package.networking.net-mac.constructor; &package.networking.net-mac.setmac; &package.networking.net-mac.importvendors; &package.networking.net-mac.findvendor; &package.networking.net-mac.net-mac-exception; </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/check.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/check.xml +++ peardoc/en/package/networking/net-mac/check.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.check"> <refnamediv> <refname>Net_MAC::check()</refname> <refpurpose>Validates Media Access Control (MAC) addresses</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>string <function>Net_MAC::check</function></funcdef> <paramdef>string <parameter>$input</parameter></paramdef> <paramdef>string <parameter>$delimiter</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.check.desc"> &title.desc; <para> This function will check a MAC address to make sure it is valid. </para> </refsect1> <refsect1 id="package.networking.net-mac.check.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $input</parameter> - The string containing the MAC Address <parameter>string $delimiter</parameter> - The string representing the delimiter to use when checking the MAC Address </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.check.return"> &title.returns; <para> <parameter>bool</parameter> - &true if the MAC address is valid, &false otherwise </para> </refsect1> <refsect1 id="package.networking.net-mac.check.note"> &title.note; ¬e.canstatic; </refsect1> <refsect1 id="package.networking.net-mac.check.example"> &title.example; <example> <title>Using <function>check</function></title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::check("AB:CD:EF:00:11:22"); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ab:cd:ef:00:11:22</screen> </para> </example> <example> <title>Using <function>check</function> to get a MAC address with a different delimiter</title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::check("AB:CD:EF:00:11:22", '-'); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ab-cd-ef-00-11-22</screen> </para> </example> <example> <title>Using <function>check</function> to get a MAC address with all capital alpha characters</title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::check("AB:CD:EF:00:11:22", '', true); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ABCDEF001122</screen> </para> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/constants.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/constants.xml +++ peardoc/en/package/networking/net-mac/constants.xml <!-- $Revision: 1.1 $ --> <refentry id="packages.networking.net-mac.constants"> <refnamediv> <refname>Constants</refname> <refpurpose>Predefined Constants</refpurpose> </refnamediv> <refsect1 id="packages.networking.net-mac.constants.line-maxlength"> <title><constant>NET_MAC_LINE_MAXLENGTH</constant></title> <para> Constant to represent the maximum length of a line in the manufacturers file. </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-ok"> <title><constant>NET_MAC_ERROR_OK</constant></title> <para> Error constant: signifies no problem (OK) </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-badopt"> <title><constant>NET_MAC_ERROR_BADOPT</constant></title> <para> Error constant: signifies a bad option being passed to a function </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-baddata"> <title><constant>NET_MAC_ERROR_BADDATA</constant></title> <para> Error constant: signifies bad data being passed to a function </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-baddb"> <title><constant>NET_MAC_ERROR_BADDB</constant></title> <para> Error constant: signifies a bad database connection </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-badfile"> <title><constant>NET_MAC_ERROR_BADFILE</constant></title> <para> Error constant: signifies a bad manufacturers file </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/constructor.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/constructor.xml +++ peardoc/en/package/networking/net-mac/constructor.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.constructor"> <refnamediv> <refname>Net_MAC::__construct()</refname> <refpurpose>Constructor</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef><function>Net_MAC::__construct</function></funcdef> <paramdef>object <parameter>$db</parameter></paramdef> <paramdef>array <parameter>$options</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.constructor.desc"> &title.desc; <para> This is the constructor that will create and populate a valid Net_MAC object. </para> </refsect1> <refsect1 id="package.networking.net-mac.constructor.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>object $db</parameter>This parameter must be a valid <link linkend="package.database.mdb2.intro-connect">MDB2</link> object. <parameter>array $options</parameter>An array of options to use with the database in retrieving MAC address vendors. The associative array should have key/value pairs as follows: <table> <title>Net_MAC::__construct() options</title> <tgroup> <thead> <row> <entry>Option</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>tablename</entry> <entry>The name of the table where MAC address vendor information lives</entry> </row> <row> <entry>macaddrcol</entry> <entry>The name of the column containing the MAC address prefixes</entry> </row> <row> <entry>vendorcol</entry> <entry>The name of the column containing the vendor name</entry> </row> <row> <entry>desccol</entry> <entry>The name of the column containing any extra descriptive information derived from the vendor list</entry> </row> </tbody> </tgroup> </table> </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.constructor.return"> &title.returns; <para> <parameter>void</parameter> - No return value. A <link linkend="package.networking.net-mac.net-mac-exception">Net_MAC_Exception</link> Exception object will be thrown if there is an error during construction so the constructor should be called from a try/catch block </para> </refsect1> <refsect1 id="package.networking.net-mac.constructor.note"> &title.note; </refsect1> <refsect1 id="package.networking.net-mac.constructor.example"> &title.example; <example> <title>Instantiating a Net_MAC object</title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); try { $nmh =& new Net_MAC($dbh, $dboptions); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/findvendor.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/findvendor.xml +++ peardoc/en/package/networking/net-mac/findvendor.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.findvendor"> <refnamediv> <refname>findVendor()</refname> <refpurpose>Finds the vendor of the MAC address stored in the object</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>mixed <function>findVendor</function></funcdef> <paramdef>string <parameter><optional>$getDescription = &false;</optional></parameter></paramdef> <paramdef>string <parameter><optional>$macList = &null;</optional></parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.findvendor.desc"> &title.desc; <para> This method will search through the database to find a vendor that matches the MAC address stored in the class using <link linkend="package.networking.net-mac.setmac"><function>setMac</function></link>. If the $macList parameter is set, the method will use the array stored in $macList as the data source to find the MAC vendor instead of the database. The array would have to be an array with the same characteristics as one returned from the <link linkend="package.networking.net-mac.importvendors"><function>importVendors</function></link> method when using the $doReturn parameter. </para> </refsect1> <refsect1 id="package.networking.net-mac.findvendor.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $getDescription</parameter>If set to &true;, the return value will be an array with keys 'vendor' and 'description'. Normally the method will simply return the vendor name. <parameter>string $macList</parameter>An optional list of MAC-to-vendor relationships to search instead of using the database. </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.findvendor.return"> &title.returns; <para> <parameter>mixed</parameter> - Returns an associative array if $getDescription is &true;, returns a string with the vendor name if $getDescription is &false;. If the MAC vendor cannot be found in the vendor list, &false; is returned. </para> </refsect1> <refsect1 id="package.networking.net-mac.findvendor.note"> &title.note; </refsect1> <refsect1 id="package.networking.net-mac.findvendor.example"> &title.example; <example> <title>Using <function>findVendor</function></title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); try { $nmh =& new Net_MAC($dbh, $dboptions); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } $nmh->setMAC('00:11:22:33:44:55'); $result = $nmh->findVendor(true); if (is_array($result)) { foreach($result as $key => $value) { echo "$key: $value<br>\n"; } } else { echo $result; } ]]> </programlisting> <para> This would output the following: <screen>vendor: Cimsys description: CIMSYS Inc</screen> </para> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/format.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/format.xml +++ peardoc/en/package/networking/net-mac/format.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.format"> <refnamediv> <refname>Net_MAC::format()</refname> <refpurpose>Cleanly formats Media Access Control (MAC) addresses</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>string <function>Net_MAC::format</function></funcdef> <paramdef>string <parameter>$input</parameter></paramdef> <paramdef>string <parameter>$delimiter</parameter></paramdef> <paramdef>bool <parameter>$uppercase</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.format.desc"> &title.desc; <para> This function will format a MAC address into XX:XX:XX:XX:XX:XX format from whatever format is passed to the function. The delimiter (':' in the example above) will be replaced with whatever string is passed to the $delimiter parameter (default ':'). </para> </refsect1> <refsect1 id="package.networking.net-mac.format.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $input</parameter> - The string containing the MAC Address <parameter>string $delimiter</parameter> - The string representing the delimiter to use when formatting the MAC Address <parameter>string $uppercase</parameter> - If set to &true (default), the alpha characters in the hexadecimal values in the MAC Address will be returned in uppercase. If &false, the alpha characters in the hexadecimal values will be returned in lowercase. </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.format.return"> &title.returns; <para> <parameter>string</parameter> - The formatted MAC Address or &false if the syntax of the MAC address is invalid </para> </refsect1> <refsect1 id="package.networking.net-mac.format.note"> &title.note; ¬e.canstatic; </refsect1> <refsect1 id="package.networking.net-mac.format.example"> &title.example; <example> <title>Using <function>format</function></title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::format("AB:CD:EF:00:11:22"); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ab:cd:ef:00:11:22</screen> </para> </example> <example> <title>Using <function>format</function> to get a MAC address with a different delimiter</title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::format("AB:CD:EF:00:11:22", '-'); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ab-cd-ef-00-11-22</screen> </para> </example> <example> <title>Using <function>format</function> to get a MAC address with all capital alpha characters</title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::format("AB:CD:EF:00:11:22", '', true); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ABCDEF001122</screen> </para> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/importvendors.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/importvendors.xml +++ peardoc/en/package/networking/net-mac/importvendors.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.importvendors"> <refnamediv> <refname>importVendors()</refname> <refpurpose>Import a manufacturers' file to the database or to an array</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>mixed <function>importVendors</function></funcdef> <paramdef>string <parameter>$file</parameter></paramdef> <paramdef>boolean <parameter><optional>$doReturn = &false;</optional></parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.importvendors.desc"> &title.desc; <para> This method will parse a manufacturers' file, such as the one from <ulink url="http://anonsvn.wireshark.org/wireshark/trunk/manuf"/>, containing a list of MAC address prefix-to-vendor relationships. If the $doReturn parameter is &false;, then the data will be imported into the database defined by the factory of this class. However, if $doReturn is &true;, then the return will be an associative array with the key being the MAC address prefix and the data being an associative array with the keys 'vendor' and 'description'. </para> </refsect1> <refsect1 id="package.networking.net-mac.importvendors.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $file</parameter>The filename or URL of the manufacturers' file to parse <parameter>string $doReturn</parameter>If &true;, an array will be returned, if &false;, the data will be imported into the database. </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.importvendors.return"> &title.returns; <para> <parameter>mixed</parameter> - If $doReturn is &true;, the method will return an array. Otherwise, the method will return &true; on success. A <link linkend="package.networking.net-mac.net-mac-exception">Net_MAC_Exception</link> Exception object will be thrown on failure in either case. </para> </refsect1> <refsect1 id="package.networking.net-mac.importvendors.note"> &title.note; </refsect1> <refsect1 id="package.networking.net-mac.importvendors.example"> &title.example; <example> <title>Using <function>importVendors</function> with a URL</title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); try { $nmh =& new Net_MAC($dbh, $dboptions); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } try { $nmh->importVendors('http://anonsvn.wireshark.org/wireshark/trunk/manuf'); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } ]]> </programlisting> <para> This would output an error only if there is an error importing the file from the URL. </para> </example> <example> <title>Using <function>importVendors</function> with a file, returning an array</title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); $nmh =& Net_MAC::factory($dbh, $dboptions); if (PEAR::isError($nmh)){ echo 'Net_MAC Error: '.$nmh->getMessage(); } $vendorArr = $nmh->importVendors('./manuf') if (PEAR::isError(!$vendorArr)) { echo 'Net_MAC: ' . $err->getUserInfo(); exit; } print_r($vendorArr); ]]> </programlisting> <para> This would output the entire list of MAC address vendors on success and an error message on failure. </para> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/net-mac-exception.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/net-mac-exception.xml +++ peardoc/en/package/networking/net-mac/net-mac-exception.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.networking.net-mac.net-mac-exception"> <title>Net_MAC_Exception</title> <para> This class is a simple derivation of the <ulink url="http://pear.php.net/package/PEAR/docs/latest/PEAR/PEAR_Exception.html">PEAR_Exception</ulink> class and simply exists for the use of throwing exceptions for this class. </para> </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/setmac.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/setmac.xml +++ peardoc/en/package/networking/net-mac/setmac.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.setmac"> <refnamediv> <refname>setMAC()</refname> <refpurpose>Sets the MAC address in the object</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>mixed <function>setMAC</function></funcdef> <paramdef>string <parameter>$macaddr</parameter></paramdef> <paramdef>string <parameter>$delimiter = ':'</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.setmac.desc"> &title.desc; <para> This method will set the MAC address in the object given the passed MAC address and the MAC address delimiter. This method also makes use of the <link linkend="package.networking.net-mac.check"><function>check</function></link> method to make sure that the MAC address is valid. </para> </refsect1> <refsect1 id="package.networking.net-mac.setmac.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $macaddr</parameter>The string representing the MAC address <parameter>string $delimiter</parameter>The string representing the delimiter to use when verifying the MAC Address </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.setmac.return"> &title.returns; <para> <parameter>boolean</parameter> - Returns &true; if the MAC address is set correctly, &false; otherwise (i.e. the MAC address is not valid). </para> </refsect1> <refsect1 id="package.networking.net-mac.setmac.note"> &title.note; </refsect1> <refsect1 id="package.networking.net-mac.setmac.example"> &title.example; <example> <title>Using <function>setMAC</function></title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); try { $nmh =& new Net_MAC($dbh, $dboptions); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } $nmh->setMAC('00:11:22:33:44:55'); ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking.xml?r1=1.19&r2=1.20&diff_format=u Index: peardoc/en/package/networking.xml diff -u peardoc/en/package/networking.xml:1.19 peardoc/en/package/networking.xml:1.20 --- peardoc/en/package/networking.xml:1.19 Sun Oct 29 21:24:36 2006 +++ peardoc/en/package/networking.xml Sat Dec 30 22:57:48 2006 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.19 $ --> +<!-- $Revision: 1.20 $ --> <chapter id="package.networking"> <title>Networking</title> @@ -19,6 +19,7 @@ &package.networking.net-geoip; &package.networking.net-ipv4; &package.networking.net-ipv6; + &package.networking.net-mac; &package.networking.net-nntp; &package.networking.net-ping; &package.networking.net-pop3; http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac.xml +++ peardoc/en/package/networking/net-mac.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.networking.net-mac"> <title>Net_MAC</title> <para> This package validates and cleanly formats Media Access Control (MAC) addresses. The Net_MAC class can also import a list of MAC address vendors and store them in a database which the class can then use to identify vendors of any MAC address. </para> &package.networking.net-mac.constants; &package.networking.net-mac.check; &package.networking.net-mac.format; &package.networking.net-mac.constructor; &package.networking.net-mac.setmac; &package.networking.net-mac.importvendors; &package.networking.net-mac.findvendor; &package.networking.net-mac.net-mac-exception; </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/check.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/check.xml +++ peardoc/en/package/networking/net-mac/check.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.check"> <refnamediv> <refname>Net_MAC::check()</refname> <refpurpose>Validates Media Access Control (MAC) addresses</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>string <function>Net_MAC::check</function></funcdef> <paramdef>string <parameter>$input</parameter></paramdef> <paramdef>string <parameter>$delimiter</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.check.desc"> &title.desc; <para> This function will check a MAC address to make sure it is valid. </para> </refsect1> <refsect1 id="package.networking.net-mac.check.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $input</parameter> - The string containing the MAC Address <parameter>string $delimiter</parameter> - The string representing the delimiter to use when checking the MAC Address </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.check.return"> &title.returns; <para> <parameter>bool</parameter> - &true if the MAC address is valid, &false otherwise </para> </refsect1> <refsect1 id="package.networking.net-mac.check.note"> &title.note; ¬e.canstatic; </refsect1> <refsect1 id="package.networking.net-mac.check.example"> &title.example; <example> <title>Using <function>check</function></title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::check("AB:CD:EF:00:11:22"); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ab:cd:ef:00:11:22</screen> </para> </example> <example> <title>Using <function>check</function> to get a MAC address with a different delimiter</title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::check("AB:CD:EF:00:11:22", '-'); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ab-cd-ef-00-11-22</screen> </para> </example> <example> <title>Using <function>check</function> to get a MAC address with all capital alpha characters</title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::check("AB:CD:EF:00:11:22", '', true); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ABCDEF001122</screen> </para> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/constants.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/constants.xml +++ peardoc/en/package/networking/net-mac/constants.xml <!-- $Revision: 1.1 $ --> <refentry id="packages.networking.net-mac.constants"> <refnamediv> <refname>Constants</refname> <refpurpose>Predefined Constants</refpurpose> </refnamediv> <refsect1 id="packages.networking.net-mac.constants.line-maxlength"> <title><constant>NET_MAC_LINE_MAXLENGTH</constant></title> <para> Constant to represent the maximum length of a line in the manufacturers file. </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-ok"> <title><constant>NET_MAC_ERROR_OK</constant></title> <para> Error constant: signifies no problem (OK) </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-badopt"> <title><constant>NET_MAC_ERROR_BADOPT</constant></title> <para> Error constant: signifies a bad option being passed to a function </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-baddata"> <title><constant>NET_MAC_ERROR_BADDATA</constant></title> <para> Error constant: signifies bad data being passed to a function </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-baddb"> <title><constant>NET_MAC_ERROR_BADDB</constant></title> <para> Error constant: signifies a bad database connection </para> </refsect1> <refsect1 id="packages.networking.net-mac.constants.error-badfile"> <title><constant>NET_MAC_ERROR_BADFILE</constant></title> <para> Error constant: signifies a bad manufacturers file </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/constructor.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/constructor.xml +++ peardoc/en/package/networking/net-mac/constructor.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.constructor"> <refnamediv> <refname>Net_MAC::__construct()</refname> <refpurpose>Constructor</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef><function>Net_MAC::__construct</function></funcdef> <paramdef>object <parameter>$db</parameter></paramdef> <paramdef>array <parameter>$options</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.constructor.desc"> &title.desc; <para> This is the constructor that will create and populate a valid Net_MAC object. </para> </refsect1> <refsect1 id="package.networking.net-mac.constructor.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>object $db</parameter>This parameter must be a valid <link linkend="package.database.mdb2.intro-connect">MDB2</link> object. <parameter>array $options</parameter>An array of options to use with the database in retrieving MAC address vendors. The associative array should have key/value pairs as follows: <table> <title>Net_MAC::__construct() options</title> <tgroup> <thead> <row> <entry>Option</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>tablename</entry> <entry>The name of the table where MAC address vendor information lives</entry> </row> <row> <entry>macaddrcol</entry> <entry>The name of the column containing the MAC address prefixes</entry> </row> <row> <entry>vendorcol</entry> <entry>The name of the column containing the vendor name</entry> </row> <row> <entry>desccol</entry> <entry>The name of the column containing any extra descriptive information derived from the vendor list</entry> </row> </tbody> </tgroup> </table> </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.constructor.return"> &title.returns; <para> <parameter>void</parameter> - No return value. A <link linkend="package.networking.net-mac.net-mac-exception">Net_MAC_Exception</link> Exception object will be thrown if there is an error during construction so the constructor should be called from a try/catch block </para> </refsect1> <refsect1 id="package.networking.net-mac.constructor.note"> &title.note; </refsect1> <refsect1 id="package.networking.net-mac.constructor.example"> &title.example; <example> <title>Instantiating a Net_MAC object</title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); try { $nmh =& new Net_MAC($dbh, $dboptions); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/findvendor.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/findvendor.xml +++ peardoc/en/package/networking/net-mac/findvendor.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.findvendor"> <refnamediv> <refname>findVendor()</refname> <refpurpose>Finds the vendor of the MAC address stored in the object</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>mixed <function>findVendor</function></funcdef> <paramdef>string <parameter><optional>$getDescription = &false;</optional></parameter></paramdef> <paramdef>string <parameter><optional>$macList = &null;</optional></parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.findvendor.desc"> &title.desc; <para> This method will search through the database to find a vendor that matches the MAC address stored in the class using <link linkend="package.networking.net-mac.setmac"><function>setMac</function></link>. If the $macList parameter is set, the method will use the array stored in $macList as the data source to find the MAC vendor instead of the database. The array would have to be an array with the same characteristics as one returned from the <link linkend="package.networking.net-mac.importvendors"><function>importVendors</function></link> method when using the $doReturn parameter. </para> </refsect1> <refsect1 id="package.networking.net-mac.findvendor.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $getDescription</parameter>If set to &true;, the return value will be an array with keys 'vendor' and 'description'. Normally the method will simply return the vendor name. <parameter>string $macList</parameter>An optional list of MAC-to-vendor relationships to search instead of using the database. </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.findvendor.return"> &title.returns; <para> <parameter>mixed</parameter> - Returns an associative array if $getDescription is &true;, returns a string with the vendor name if $getDescription is &false;. If the MAC vendor cannot be found in the vendor list, &false; is returned. </para> </refsect1> <refsect1 id="package.networking.net-mac.findvendor.note"> &title.note; </refsect1> <refsect1 id="package.networking.net-mac.findvendor.example"> &title.example; <example> <title>Using <function>findVendor</function></title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); try { $nmh =& new Net_MAC($dbh, $dboptions); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } $nmh->setMAC('00:11:22:33:44:55'); $result = $nmh->findVendor(true); if (is_array($result)) { foreach($result as $key => $value) { echo "$key: $value<br>\n"; } } else { echo $result; } ]]> </programlisting> <para> This would output the following: <screen>vendor: Cimsys description: CIMSYS Inc</screen> </para> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/format.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/format.xml +++ peardoc/en/package/networking/net-mac/format.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.format"> <refnamediv> <refname>Net_MAC::format()</refname> <refpurpose>Cleanly formats Media Access Control (MAC) addresses</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>string <function>Net_MAC::format</function></funcdef> <paramdef>string <parameter>$input</parameter></paramdef> <paramdef>string <parameter>$delimiter</parameter></paramdef> <paramdef>bool <parameter>$uppercase</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.format.desc"> &title.desc; <para> This function will format a MAC address into XX:XX:XX:XX:XX:XX format from whatever format is passed to the function. The delimiter (':' in the example above) will be replaced with whatever string is passed to the $delimiter parameter (default ':'). </para> </refsect1> <refsect1 id="package.networking.net-mac.format.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $input</parameter> - The string containing the MAC Address <parameter>string $delimiter</parameter> - The string representing the delimiter to use when formatting the MAC Address <parameter>string $uppercase</parameter> - If set to &true (default), the alpha characters in the hexadecimal values in the MAC Address will be returned in uppercase. If &false, the alpha characters in the hexadecimal values will be returned in lowercase. </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.format.return"> &title.returns; <para> <parameter>string</parameter> - The formatted MAC Address or &false if the syntax of the MAC address is invalid </para> </refsect1> <refsect1 id="package.networking.net-mac.format.note"> &title.note; ¬e.canstatic; </refsect1> <refsect1 id="package.networking.net-mac.format.example"> &title.example; <example> <title>Using <function>format</function></title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::format("AB:CD:EF:00:11:22"); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ab:cd:ef:00:11:22</screen> </para> </example> <example> <title>Using <function>format</function> to get a MAC address with a different delimiter</title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::format("AB:CD:EF:00:11:22", '-'); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ab-cd-ef-00-11-22</screen> </para> </example> <example> <title>Using <function>format</function> to get a MAC address with all capital alpha characters</title> <programlisting role="php"> <![CDATA[ require_once "Net/MAC.php"; $mac = Net_MAC::format("AB:CD:EF:00:11:22", '', true); if ($mac) { echo "$mac"; } else { echo "MAC address is invalid"; } ]]> </programlisting> <para> This would output the following: <screen>ABCDEF001122</screen> </para> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/importvendors.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/importvendors.xml +++ peardoc/en/package/networking/net-mac/importvendors.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.importvendors"> <refnamediv> <refname>importVendors()</refname> <refpurpose>Import a manufacturers' file to the database or to an array</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>mixed <function>importVendors</function></funcdef> <paramdef>string <parameter>$file</parameter></paramdef> <paramdef>boolean <parameter><optional>$doReturn = &false;</optional></parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.importvendors.desc"> &title.desc; <para> This method will parse a manufacturers' file, such as the one from <ulink url="http://anonsvn.wireshark.org/wireshark/trunk/manuf"/>, containing a list of MAC address prefix-to-vendor relationships. If the $doReturn parameter is &false;, then the data will be imported into the database defined by the factory of this class. However, if $doReturn is &true;, then the return will be an associative array with the key being the MAC address prefix and the data being an associative array with the keys 'vendor' and 'description'. </para> </refsect1> <refsect1 id="package.networking.net-mac.importvendors.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $file</parameter>The filename or URL of the manufacturers' file to parse <parameter>string $doReturn</parameter>If &true;, an array will be returned, if &false;, the data will be imported into the database. </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.importvendors.return"> &title.returns; <para> <parameter>mixed</parameter> - If $doReturn is &true;, the method will return an array. Otherwise, the method will return &true; on success. A <link linkend="package.networking.net-mac.net-mac-exception">Net_MAC_Exception</link> Exception object will be thrown on failure in either case. </para> </refsect1> <refsect1 id="package.networking.net-mac.importvendors.note"> &title.note; </refsect1> <refsect1 id="package.networking.net-mac.importvendors.example"> &title.example; <example> <title>Using <function>importVendors</function> with a URL</title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); try { $nmh =& new Net_MAC($dbh, $dboptions); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } try { $nmh->importVendors('http://anonsvn.wireshark.org/wireshark/trunk/manuf'); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } ]]> </programlisting> <para> This would output an error only if there is an error importing the file from the URL. </para> </example> <example> <title>Using <function>importVendors</function> with a file, returning an array</title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); $nmh =& Net_MAC::factory($dbh, $dboptions); if (PEAR::isError($nmh)){ echo 'Net_MAC Error: '.$nmh->getMessage(); } $vendorArr = $nmh->importVendors('./manuf') if (PEAR::isError(!$vendorArr)) { echo 'Net_MAC: ' . $err->getUserInfo(); exit; } print_r($vendorArr); ]]> </programlisting> <para> This would output the entire list of MAC address vendors on success and an error message on failure. </para> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/net-mac-exception.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/net-mac-exception.xml +++ peardoc/en/package/networking/net-mac/net-mac-exception.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.networking.net-mac.net-mac-exception"> <title>Net_MAC_Exception</title> <para> This class is a simple derivation of the <ulink url="http://pear.php.net/package/PEAR/docs/latest/PEAR/PEAR_Exception.html">PEAR_Exception</ulink> class and simply exists for the use of throwing exceptions for this class. </para> </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-mac/setmac.xml?view=markup&rev=1.1 Index: peardoc/en/package/networking/net-mac/setmac.xml +++ peardoc/en/package/networking/net-mac/setmac.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-mac.setmac"> <refnamediv> <refname>setMAC()</refname> <refpurpose>Sets the MAC address in the object</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once 'Net/MAC.php'; </funcsynopsisinfo> <funcprototype> <funcdef>mixed <function>setMAC</function></funcdef> <paramdef>string <parameter>$macaddr</parameter></paramdef> <paramdef>string <parameter>$delimiter = ':'</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-mac.setmac.desc"> &title.desc; <para> This method will set the MAC address in the object given the passed MAC address and the MAC address delimiter. This method also makes use of the <link linkend="package.networking.net-mac.check"><function>check</function></link> method to make sure that the MAC address is valid. </para> </refsect1> <refsect1 id="package.networking.net-mac.setmac.parameter"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $macaddr</parameter>The string representing the MAC address <parameter>string $delimiter</parameter>The string representing the delimiter to use when verifying the MAC Address </para> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-mac.setmac.return"> &title.returns; <para> <parameter>boolean</parameter> - Returns &true; if the MAC address is set correctly, &false; otherwise (i.e. the MAC address is not valid). </para> </refsect1> <refsect1 id="package.networking.net-mac.setmac.note"> &title.note; </refsect1> <refsect1 id="package.networking.net-mac.setmac.example"> &title.example; <example> <title>Using <function>setMAC</function></title> <programlisting role="php"> <![CDATA[ require_once 'Net/MAC.php'; require_once 'MDB2.php'; $db_type = 'pgsql'; $db_host = 'localhost'; $db_user = 'username'; $db_name = 'dbname'; $db_pass = 'password'; $dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; $dbh =& MDB2::factory($dsn); if (MDB2::isError($dbh)) { echo "MDB2 Error: ".$dbh->getUserInfo(); } $dboptions = array('tablename' => 'macvendors', 'macaddrcol' => 'macaddr', 'vendorcol' => 'vendor', 'desccol' => 'description'); try { $nmh =& new Net_MAC($dbh, $dboptions); } catch (Net_MAC_Exception $e) { echo 'Net_MAC Error: ' . $e->getMessage(); exit; } $nmh->setMAC('00:11:22:33:44:55'); ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->