00001 /*************************************************************************** 00002 * Copyright (C) 2001,2002,2003,2004,2005,2006,2007,2008,2009 * 00003 * by Rick L. Vinyard, Jr. * 00004 * rvinyard@cs.nmsu.edu * 00005 * * 00006 * This file is part of the conexus library. * 00007 * * 00008 * The conexus library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU General Public License * 00010 * version 3 as published by the Free Software Foundation. * 00011 * * 00012 * The conexus library is distributed in the hope that it will be * 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00015 * General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this software. If not see <http://www.gnu.org/licenses/>. * 00019 ***************************************************************************/ 00020 #ifndef CONEXUSNETWORK_DEVICE_H 00021 #define CONEXUSNETWORK_DEVICE_H 00022 00023 #include <string> 00024 #include <vector> 00025 00026 #include <sys/ioctl.h> 00027 #include <net/if.h> 00028 00029 namespace Conexus 00030 { 00031 namespace Network 00032 { 00033 00034 unsigned interface_index( const std::string& name ); 00035 std::string interface_name( unsigned ifindex ); 00036 std::vector<std::string> interface_names(); 00037 std::vector<std::pair<unsigned,std::string> > interfaces(); 00038 std::vector<std::pair<std::string, std::string> > interface_ip_addresses(); 00039 00044 class Device 00045 { 00046 public: 00047 00048 Device( const std::string& name ); 00049 00050 Device( int index ); 00051 00052 virtual ~Device(); 00053 00054 int index(); 00055 00056 void set_index( int index ); 00057 00058 std::string name(); 00059 00060 void set_name( const std::string& name ); 00061 00062 bool is_up(); 00063 00064 bool has_broadcast(); 00065 00066 bool is_debug(); 00067 00068 bool is_loopback(); 00069 00070 bool is_point_to_point(); 00071 00072 bool is_running(); 00073 00074 bool no_arp(); 00075 00076 bool is_promiscuous(); 00077 00078 bool no_trailers(); 00079 00080 bool receives_all_multicast(); 00081 00082 bool is_master(); 00083 00084 bool is_slave(); 00085 00086 bool is_multicast_capable(); 00087 00088 bool port_selectable(); 00089 00090 bool auto_media_active(); 00091 00092 bool is_dynamic(); 00093 00094 int mtu(); 00095 00096 void set_mtu(int mtu); 00097 00098 protected: 00099 00100 std::string m_name; 00101 00102 int m_index; 00103 00104 struct ifreq m_ifreq; 00105 00106 }; 00107 00108 } 00109 } 00110 00111 #endif