The Network Kit: Global Functions, Constants, and Defined Types


The Network Kit: Global Functions, Constants, and Defined Types

This section lists miscellaneous API, including global C functions, constants, and defined types, that you'll use when creating network device and protocol add-ons.


Functions


copy_packet()


      void copy_packet(BNetPacket *srcpacket, unsigned srcoffset, BNetPacket *dstpacket, unsigned dstoffset, unsigned size);

copy_packet() copies data from a source packet to a destination packet. size bytes of data are copied beginning at the specified srcoffset within the packet specified by srcpacket and stored starting at the specified dstoffset within the packet pointed to by the dstpacket parameter.


deliver_packet()


      void deliver_packet(BNetPacket *packet, BNetDevice *device);

deliver_packet() delivers the specified packet to the Net Server. You should place a pointer to your add-on's own BNetDevice-derived object in the device parameter. This would be necessary if you implement a device, such as PPP, that receives packets from one interface (like a serial port) and needs to forward them to the Net Server to be processed. The Net Server, in return, will forward the packet to each packet handler that's registered as being interested in getting packets from your device.


find_net_setting()


      char *find_net_setting(net_settings *ncw, const char *heading, const char *setting_name, char *buffer, unsigned buff_size);

Reads a network setting into the specified buffer, which is buff_size bytes long. The setting to be read is identified by its heading (which can be thought of as a group name that identifies all the settings belonging to a particular application or add-on) and its setting_name, which is the name of the particular setting to be read into the buffer. If ncw is NULL, the setting is read from the network settings file. Otherwise, it is read from the net_settings record referenced by ncw.

The only time you should ever specify a value other than NULL for ncw is when the Net Server has provided you with a value to use. In particular, when a network device add-on's Config() function is called, the Net Server will provide you with a value to use for ncw.


register_packet_handler()


      void register_packet_handler(BPacketHandler *handler, BNetDevice *device, int priority = 0);

Registers the specified packet handler with the Net Server. A BNetProtocol-derived object's AddDevice() function should call this function to register itself to receive packets from the specified device. The priority specifies the order in which the handlers will receive packets; the higher the value, the higher-priority the handler. Most devices should use 0, the default. Packet sniffers and other debugging aids should use higher priorities so they don't risk missing packets that other packet handlers might accept.

See also: BNetProtocol::AddDevice()


set_net_setting()


      status_t set_net_setting(net_settings *ncw, const char *heading, const char *setting_name, char *buffer);

Writes a network setting from the specified buffer into the network settings file specified by the ncw parameter. The buffer should be null-terminated.

The setting is stored in the group whose name is provided in the heading parameter, and is given the name setting_name. If a setting by that heading and name already exists, it is replaced with the new value.

If you wish to save the setting into the global network settings file, specify NULL for ncw. The only time you should ever specify a value other than NULL for ncw is when the Net Server has provided you with a value to use; you should usually pass NULL.


unregister_packet_handler()


      void unregister_packet_handler(BPacketHandler *handler, BNetDevice *device);

Tells the Net Server to stop sending packets from the specified device to your packet handler.


Constants


Network Device Types

Constant Meaning
B_NULL_NET_DEVICE Not a real device.
B_ETHER_NET_DEVICE Ethernet device.
B_PPP_NET_DEVICE PPP device.
B_LOOP_NET_DEVICE Loopback device.

These constants define the SNMP types of network device an add-on can represent.


Byte Orderings

Constant Meaning
B_BIG_ENDIAN Data is in big-endian format.
B_LITTLE_ENDIAN Data is in little-endian format.

These constants define the two possible byte orderings.


Defined Types


net_device_type


      typedef enum { . . . } net_device_type;

The network device type defines what kind of networking device the add-on represents. These are SNMP types.


net_settings


      typedef struct _net_settings {
            ...
         } net_settings;

The net_settings type represents a collection of network settings. The members of this structure are private.






The Be Book, in lovely HTML, for BeOS Release 3.

Copyright © 1998 Be, Inc. All rights reserved.

Last modified March 26, 1998.