support3.xml 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <section id="support-network">
  2. <title>
  3. Network Functions
  4. </title>
  5. <section id="support-networkbridges">
  6. <title>
  7. NetworkBridges
  8. </title>
  9. <funcsynopsis>
  10. <funcprototype>
  11. <funcdef>size_t <function>NetworkBridges</function></funcdef>
  12. <paramdef>struct channel * <parameter>channel</parameter></paramdef>
  13. <paramdef>void * <parameter>memory</parameter></paramdef>
  14. <paramdef>size_t <parameter>extent</parameter></paramdef>
  15. </funcprototype>
  16. </funcsynopsis>
  17. <para>
  18. Search a channel for local powerline devices (bridges) and store their Ethernet hardware in consecutive <varname>memory</varname> locations. The memory <varname>extent</varname> is specified in bytes. The number of devices found is returned as the function value, provided enough space is available to store all addressed. Unlike function <link linkend='support-networkdevices'>NetworkDevices</link>, the channel <varname>peer</varname> address is ignored.
  19. </para>
  20. <para>
  21. We call local devices <quote>bridges</quote> because each serves as an Ethernet-to-Powerline bridge for the local host.
  22. </para>
  23. <example>
  24. <title>
  25. Enumerating Local Devices
  26. </title>
  27. <programlisting>
  28. #include &lt;net/if.h&gt;
  29. #include &quot;../ether/channel.h&quot;
  30. extern struct channel <varname>channel</varname>;
  31. uint8_t <varname>address</varname> [<constant>255</constant>][<constant>ETHER_ADDR_LEN</constant>];
  32. size_t <varname>bridges</varname> = <function>NetworkBridges</function> (&amp;<varname>channel</varname>, <varname>address</varname>, sizeof (<varname>address</varname>));
  33. size_t <varname>bridge</varname> = 0;
  34. while (<varname>bridge</varname> &lt; <varname>bridges</varname>)
  35. {
  36. <function>binout</function> (<varname>address</varname> [<varname>bridge</varname>], <constant>ETHER_ADDR_LEN</constant>, <constant>':'</constant>, stdout);
  37. <function>putc</function> (<constant>'\n'</constant>, <varname>stdout</varname>);
  38. }
  39. </programlisting>
  40. <para>
  41. The code segment shown above illustrates how to use function <varname>NetworkBridges</varname> to identify all local devices. We do not need to set the <link linkend='support-channel'>channel</link> <varname>peer</varname> because <varname>NetworkBridges</varname> always uses the Atheros <varname>localcast</varname> address. Array <varname>address</varname> is declared with two dimensions to simplify access to individual addresses on return.
  42. </para>
  43. </example>
  44. </section>
  45. <section id="support-networkdevices">
  46. <title>
  47. NetworkDevices
  48. </title>
  49. <funcsynopsis>
  50. <funcprototype>
  51. <funcdef>size_t <function>NetworkDevices</function></funcdef>
  52. <paramdef>struct channel * <parameter>channel</parameter></paramdef>
  53. <paramdef>void * <parameter>memory</parameter></paramdef>
  54. <paramdef>size_t <parameter>extent</parameter></paramdef>
  55. </funcprototype>
  56. </funcsynopsis>
  57. <para>
  58. Query a powerline device, specified by <link linkend='support-channel'>channel</link>, for neighboring network devices and store their Ethernet addresses in consecutive <varname>memory</varname> locations. The memory <varname>extent</varname> is specified in bytes. The number of devices found is returned as the function value, provided sufficient space is available to store all addresses. Unlike function <link linkend='support-networkbridges'>NetworkBridges</link>, the <structname>channel</structname> <varname>peer</varname> address is identifies the device to be queried.
  59. </para>
  60. <example>
  61. <title>
  62. Enumerating Network Devices
  63. </title>
  64. <programlisting>
  65. #include &lt;net/if.h&gt;
  66. #include &quot;../ether/channel.h&quot;
  67. extern struct channel <varname>channel</varname>;
  68. uint8_t <varname>address</varname> [<constant>255</constant>][<constant>ETHER_ADDR_LEN</constant>];
  69. size_t <varname>devices</varname> = <function>NetworkDevices</function> (&amp;<varname>channel</varname>, <varname>address</varname>, sizeof (<varname>address</varname>));
  70. size_t <varname>device</varname> = <constant>0</constant>;
  71. while (<varname>device</varname> &lt; <varname>devices</varname>)
  72. {
  73. <function>binout</function> (<varname>address</varname> [<varname>device</varname>], <constant>ETHER_ADDR_LEN</constant>, <constant>':'</constant>, <varname>stdout</varname>);
  74. <function>putc</function> (<constant>'\n'</constant>;, <varname>stdout</varname>);
  75. }
  76. </programlisting>
  77. <para>
  78. The code segment shown above illustrates how to use function <varname>NetworkDevices</varname> to identify all devices on a specific network. You must set the <link linkend='support-channel'>channel</link> <varname>peer</varname> address before calling <varname>NetworkDevices</varname>. Array <varname>address</varname> is declared with two dimensions to simplify access to individual addresses on return. If the <link linkend='support-channel'>channel</link> <varname>peer</varname> address is not the Ethernet <varname>broadcast</varname> or Atheros <varname>localcast</varname> address then the first address returned will be the <link linkend='support-channel'>channel</link> <varname>peer</varname> address.
  79. </para>
  80. </example>
  81. </section>
  82. </section>