3535 * Internal functions for working with struct etherinfo
3636 *
3737 */
38+
39+ /**
40+ * Simple macro which makes sure the destination string is freed if used earlier.
41+ *
42+ * @param dst Destination pointer
43+ * @param src Source pointer
44+ *
45+ */
3846#define SET_STR_VALUE (dst , src ) { \
3947 if( dst ) { \
4048 free(dst); \
4351 }
4452
4553
54+ /**
55+ * Frees the memory used by a struct ipv6address pointer chain. All elements are freed
56+ *
57+ * @param ptr Pointer to a struct ipv6address chain.
58+ */
4659void free_ipv6addresses (struct ipv6address * ptr ) {
4760 struct ipv6address * ipv6ptr = ptr ;
4861
@@ -59,6 +72,11 @@ void free_ipv6addresses(struct ipv6address *ptr) {
5972 }
6073}
6174
75+ /**
76+ * Frees the memory used by struct etherinfo, including all struct ipv6address children.
77+ *
78+ * @param ptr Pointer to a struct etherninfo element
79+ */
6280void free_etherinfo (struct etherinfo * ptr )
6381{
6482 if ( ptr == NULL ) { // Just for safety
@@ -82,6 +100,17 @@ void free_etherinfo(struct etherinfo *ptr)
82100 free (ptr );
83101}
84102
103+
104+ /**
105+ * Add a new IPv6 address record to a struct ipv6address chain
106+ *
107+ * @param addrptr Pointer to the current IPv6 address chain.
108+ * @param addr IPv6 address, represented as char * string
109+ * @param netmask IPv6 netmask, as returned by libnl rtnl_addr_get_prefixlen()
110+ * @param scope IPV6 address scope, as returned by libnl rtnl_addr_get_scope()
111+ *
112+ * @return Returns a new pointer to the chain containing the new element
113+ */
85114struct ipv6address * etherinfo_add_ipv6 (struct ipv6address * addrptr , const char * addr , int netmask , int scope ) {
86115 struct ipv6address * newaddr = NULL ;
87116
@@ -100,11 +129,13 @@ struct ipv6address * etherinfo_add_ipv6(struct ipv6address *addrptr, const char
100129}
101130
102131
103- /*
104- * libnl callback functions
132+ /**
133+ * libnl callback function. Does the real parsing of a record returned by NETLINK. This function
134+ * parses LINK related packets
105135 *
136+ * @param obj Pointer to a struct nl_object response
137+ * @param arg Pointer to a struct etherinfo element where the parse result will be saved
106138 */
107-
108139static void callback_nl_link (struct nl_object * obj , void * arg )
109140{
110141 struct etherinfo * ethi = (struct etherinfo * ) arg ;
@@ -137,6 +168,13 @@ static void callback_nl_link(struct nl_object *obj, void *arg)
137168}
138169
139170
171+ /**
172+ * libnl callback function. Does the real parsing of a record returned by NETLINK. This function
173+ * parses ADDRESS related packets
174+ *
175+ * @param obj Pointer to a struct nl_object response
176+ * @param arg Pointer to a struct etherinfo element where the parse result will be saved
177+ */
140178static void callback_nl_address (struct nl_object * obj , void * arg )
141179{
142180 struct etherinfo * ethi = (struct etherinfo * ) arg ;
@@ -188,6 +226,12 @@ static void callback_nl_address(struct nl_object *obj, void *arg)
188226 *
189227 */
190228
229+ /**
230+ * Dumps the contents of a struct etherinfo element to file
231+ *
232+ * @param fp FILE pointer where to dump
233+ * @param ptr Pointer to a struct etherinfo element
234+ */
191235void dump_etherinfo (FILE * fp , struct etherinfo * ptr )
192236{
193237
@@ -220,6 +264,16 @@ void dump_etherinfo(FILE *fp, struct etherinfo *ptr)
220264}
221265
222266
267+ /**
268+ * Query NETLINK for ethernet configuration
269+ *
270+ * @param ethinf Pointer to an available struct etherinfo element. The 'device' member
271+ * must contain a valid string to the device to query for information
272+ * @param nlc Pointer to the libnl handle, which is used for the query against NETLINK
273+ * @param query What to query for. Must be NLQRY_LINK or NLQRY_ADDR.
274+ *
275+ * @return Returns 1 on success, otherwise 0.
276+ */
223277int get_etherinfo (struct etherinfo * ethinf , struct _nlconnection * nlc , nlQuery query )
224278{
225279 struct nl_cache * link_cache ;
0 commit comments