/*
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *         (C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#ifndef __NETINTERFACE_H
#define __NETINTERFACE_H

#include <device.h>

#include <qptrlist.h>

class LAN;
class IPv4Addr;
class IPv4Netmask;

struct ifmediareq;
struct ifreq;

/** @brief Represents a network interface.
  *
  * All methods operate directly on the underlying
  * device. No information is stored. This makes
  * sure no outdated information is used.
  *
  * Example: The getIP() method always uses ioctls to
  *          retrieve this information instead of caching
  *          it where the information can get outdated.
  *
  * @attention
  *  When connection to a lan, running DHCP clients are
  *  stopped. A better solutions here would be good.
  */
class NetInterface : public Device
{
public:

	/** Link states. */
	enum Status {
		Invalid,

		Active,
		NoCarrier,
		Associated  /**< only for IEEE 802.11 (WLAN) */
	};

	NetInterface(const QString&);

	virtual  bool  connectTo(const LAN&);

	bool  setIP(const IPv4Addr&);
	bool  setNetmask(const IPv4Netmask&);

	bool  isDHCPEnabled()  const;
	bool  setDHCPEnabled(bool);

	int  up();
	int  down();
	bool remove();

	int  isUp()        const;
	int  isLoopback()  const;
	int  isWireless()  const;

	IPv4Addr    getIP()       const;
	IPv4Netmask getNetmask()  const;

	virtual Status  getStatus()  const;

	static  QPtrList<NetInterface>  getIfs(bool = true,  bool = false);

protected:
	int    newSocket()  const;
	
	virtual QString getCurrentConf();
	bool setRCConfEntry(const QString &);

private:

	struct ifreq       *getIfrFlags()   const;
	struct ifmediareq  *getIfMediaReq()  const;
};

#endif /* __NETINTERFACE_H */
