Updated documentation for 0.2 release
[mtetherd] / net.h
1 /*
2   mtetherd
3   (c) 2010 Gregor Riepl <onitake@gmail.com>
4   
5   Tethering utility for Maemo
6   
7   This program is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11   
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16   
17   You should have received a copy of the GNU General Public License
18   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _MTETHERD_NET_H
22 #define _MTETHERD_NET_H
23
24 #include <glib.h>
25 #include <glib-object.h>
26
27 G_BEGIN_DECLS
28
29 #define TYPE_MTETHERD_DEVICE (mtetherd_device_get_type())
30 #define MTETHERD_DEVICE(object) (G_TYPE_CHECK_INSTANCE_CAST((object), TYPE_MTETHERD_DEVICE, MTetherDDevice))
31 #define MTETHERD_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_MTETHERD_DEVICE, MTetherDDeviceClass))
32 #define IS_MTETHERD_DEVICE(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), TYPE_MTETHERD_DEVICE))
33 #define IS_MTETHERD_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_MTETHERD_DEVICE))
34 #define MTETHERD_DEVICE_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), TYPE_MTETHERD_DEVICE, MTetherDDeviceClass))
35
36 typedef struct _MTetherDDeviceClass MTetherDDeviceClass;
37 typedef struct _MTetherDDevice MTetherDDevice;
38 typedef struct _MTetherDDevicePrivate MTetherDDevicePrivate;
39
40 struct _MTetherDDeviceClass {
41         GObjectClass parent;
42 };
43
44 struct _MTetherDDevice {
45         GObject parent;
46         MTetherDDevicePrivate *priv;
47 };
48
49 GType mtetherd_device_get_type();
50
51 // Allocates a new device object
52 // This object doesn't have addresses assigned yet
53 // Add it to a device list or use mtetherd_device_set_index to construct them
54 MTetherDDevice *mtetherd_device_new(const gchar *interface, const gchar *udi);
55 // Constructs IP address and DHCP ranges from the given index
56 // 192.168.255.0/24 is the supernet for all devices,
57 // each gets a /30 from that range, depending on the index
58 // Example: index = 32 -> subnet = 192.168.255.200/30
59 // The host address is always 1, and the DHCP range goes from 1 to 2
60 void mtetherd_device_set_index(MTetherDDevice *self, guint index);
61 // Returns the interface name
62 const gchar *mtetherd_device_get_interface(MTetherDDevice *self);
63 // Returns the host address
64 // Free when done
65 gchar *mtetherd_device_get_addr(MTetherDDevice *self);
66 // Returns the netmask
67 // Free when done
68 gchar *mtetherd_device_get_netmask(MTetherDDevice *self);
69 // Returns the DHCP range start address
70 // Free when done
71 gchar *mtetherd_device_get_dhcp_start(MTetherDDevice *self);
72 // Returns the DHCP range end address
73 // Free when done
74 gchar *mtetherd_device_get_dhcp_end(MTetherDDevice *self);
75
76 // Device list functions
77 // The list is constrained to 64 entries
78 gpointer mtetherd_device_list_new();
79 // Unrefs all devices contained within and frees the list
80 void mtetherd_device_list_free(gpointer list);
81 // Scans the list for an udi and returns the first device found
82 MTetherDDevice *mtetherd_device_list_find(gpointer list, const gchar *udi);
83 // Adds a device to the next free position
84 // This transfers ownership of the object to the list
85 // Returns FALSE if the list is already full
86 gboolean mtetherd_device_list_add(gpointer list, MTetherDDevice *device);
87 // Removes and deallocates the first device with the given UDI from the list
88 // Returns FALSE if the UDI is not found
89 gboolean mtetherd_device_list_remove(gpointer list, const gchar *udi);
90
91 // Returns true if the device is acceptable for tethering
92 // Currently checks if the interface name starts with usb or bnep
93 gboolean mtetherd_device_ok(const gchar *interface);
94
95 G_END_DECLS
96
97 #endif //_MTETHERD_NET_H
98