summaryrefslogtreecommitdiffstats
path: root/python-ethtool/etherinfo_struct.h
blob: d627ba6cd166cdfd6e5cba07660acfb424b7ed1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 2009-2010 Red Hat Inc.
 *
 * David Sommerseth <davids@redhat.com>
 *
 * This application is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; version 2.
 *
 * This application is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

/**
 * @file   etherinfo_struct.h
 * @author David Sommerseth <dsommers@wsdsommers.usersys.redhat.com>
 * @date   Fri Sep  4 19:06:06 2009
 *
 * @brief  Contains the internal ethtool.etherinfo data structure
 *
 */

#ifndef _ETHERINFO_STRUCT_H
#define _ETHERINFO_STRUCT_H

/**
 * Contains IP address information about a particular ethernet device
 *
 */
struct etherinfo {
	char *device;                       /**< Device name */
	int index;                          /**< NETLINK index reference */
	char *hwaddress;                    /**< HW address / MAC address of device */
	char *ipv4_address;                 /**< Configured IPv4 address */
	int ipv4_netmask;                   /**< Configured IPv4 netmask */
	char *ipv4_broadcast;               /**< Configured IPv4 broadcast address */
	struct ipv6address *ipv6_addresses; /**< Configured IPv6 addresses (as a pointer chain) */
};


/**
 * Pointer chain with IPv6 addresses associated with a ethernet interface.  Used
 * by struct etherinfo
 */
struct ipv6address {
	char *address;               /**<  Configured IPv6 address */
	int netmask;                 /**<  Configured IPv6 netmask */
	int scope;                   /**<  Scope for the IPv6 address */
	struct ipv6address *next;    /**<  Pointer to next configured IPv6 address */
};

/**
 *  NETLINK connection handle and related information to be shared
 *  among all the instantiated etherinfo objects.
 */
struct _nlconnection {
	struct nl_handle *nlrt_handle;
};

/**
 * Contains the internal data structure of the
 * ethtool.etherinfo object.
 *
 */
struct etherinfo_obj_data {
	struct _nlconnection *nlc;	/**< Contains NETLINK connection info */
	struct etherinfo *ethinfo;      /**< Contains info about our current interface */
};

/**
 * A Python object of struct etherinfo_obj_data
 *
 */
typedef struct {
	PyObject_HEAD
	struct etherinfo_obj_data *data; /* IPv4 and IPv6 address information, only one element used */
} etherinfo_py;

/**
 * A Python object of struct ipv6address
 *
 */
typedef struct {
	PyObject_HEAD
	struct ipv6address *addrdata; /**< IPv6 address, only one element is used in this case */
} etherinfo_ipv6addr_py;

/**
 * NULL safe PyString_FromString() wrapper.  If input string is NULL, None will be returned
 *
 * @param str Input C string (char *)
 *
 * @return Returns a PyObject with either the input string wrapped up, or a Python None value.
 */
#define RETURN_STRING(str) (str ? PyString_FromString(str) : Py_None)

#endif