Source Code (Use browser search to find items of interest.)

Class Index

kppp'PPPStats (./kdenetwork/kppp/pppstats.h:33)

class PPPStats : public QObject {
  Q_OBJECT
public:
  PPPStats();
  ~PPPStats();
  bool initStats();
  bool doStats();
  bool ifIsUp();
  void setUnit(int u);
  void start();
  void stop();

signals:
  void statsChanged(int);

private slots:
  void timerClick();

public:
  int ibytes, obytes;
  int totalbytes;
  int ipackets, opackets;
  int compressedin;
  int uncompressedin;
  int compressed;
  int errorin;
  int packetsunc, packetsoutunc;

  QString local_ip_address;
  QString remote_ip_address;

  enum IOStatus { BytesNone = 0, BytesIn, BytesOut, BytesBoth };

private:
  bool get_ppp_stats(struct ppp_stats *curp);
  bool strioctl(int fd, int cmd, char* ptr,int ilen, int olen);

  int ibytes_last, obytes_last;
  int s;                      // socket file descriptor
  int unit;
  char unitName[5];
  enum IOStatus ioStatus;
  QTimer *timer;
};

kppp'PPPStats::PPPStats() (./kdenetwork/kppp/pppstats.cpp:95)

PPPStats::PPPStats() {
  timer = new QTimer;
  connect(timer, SIGNAL(timeout()), SLOT(timerClick()));
}



kppp'PPPStats::~PPPStats() (./kdenetwork/kppp/pppstats.cpp:101)

PPPStats::~PPPStats() {
  stop();
  delete timer;
}



kppp'PPPStats::timerClick() (./kdenetwork/kppp/pppstats.cpp:107)

void PPPStats::timerClick() {
  enum IOStatus newStatus;

  doStats();

  if((ibytes != ibytes_last) && (obytes != obytes_last))
    newStatus = BytesBoth;
  else if(ibytes != ibytes_last)
    newStatus = BytesIn;
  else if(obytes != obytes_last)
    newStatus = BytesOut;
  else
    newStatus = BytesNone;
  
  if(newStatus != ioStatus)
    emit statsChanged(ioStatus = newStatus);

  ibytes_last = ibytes;
  obytes_last = obytes;
}


kppp'PPPStats::setUnit() (./kdenetwork/kppp/pppstats.cpp:128)

void PPPStats::setUnit(int u) {
  unit = u;
  sprintf(unitName, "ppp%d", unit);
}



kppp'PPPStats::start() (./kdenetwork/kppp/pppstats.cpp:134)

void PPPStats::start() {
  timer->start(PPP_STATS_INTERVAL);
}



kppp'PPPStats::stop() (./kdenetwork/kppp/pppstats.cpp:139)

void PPPStats::stop() {
  emit statsChanged(BytesNone);
  timer->stop();
}



kppp'PPPStats::ifIsUp() (./kdenetwork/kppp/pppstats.cpp:145)

bool PPPStats::ifIsUp() {
  bool is_up;
  struct ifreq ifr;

#ifdef __svr4__
    if ((s = open("/dev/ppp", O_RDONLY)) < 0) {
	perror("pppstats: Couldn't open /dev/ppp: ");
	return false;
    }
    if (strioctl(s, PPPIO_ATTACH, &unit, sizeof(int), 0) < 0) {
	fprintf(stderr, "pppstats: ppp%d is not available\n", unit);
	return false;
    }
#else
    if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
	perror("Couldn't create IP socket");
	return false;
    }
#endif

    strncpy(ifr.ifr_name, unitName, sizeof(ifr.ifr_name));

    if(ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
        if (sys_nerr)
          fprintf(stderr, "Couldn't find interface %s: %s\n",
                  unitName, sys_errlist[sys_nerr]);
	::close(s);
	s = 0;
	return 0;
    }

    if ((ifr.ifr_flags & (IFF_UP|IFF_RUNNING)) != 0) {
	is_up = true;
	kdDebug(5002) << "Interface is up" << endl;
    } 
    else{
      is_up = false;
      ::close(s);
      s = 0;
      kdDebug(5002) << "Interface is down" << endl;
    }
    
    return is_up;
}



kppp'PPPStats::initStats() (./kdenetwork/kppp/pppstats.cpp:191)

bool PPPStats::initStats() {

  struct sockaddr_in *sinp;
  struct ifreq ifr;

  ibytes = 0;
  ipackets = 0;
  ibytes_last = 0;
  obytes_last = 0;
  compressedin = 0;
  uncompressedin = 0;
  errorin = 0;
  obytes = 0;
  opackets = 0;
  compressed = 0;
  packetsunc = 0;
  packetsoutunc = 0;
  ioStatus = BytesNone;

  strcpy(ifr.ifr_name, unitName);
    
  if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {	
  }

  sinp = (struct sockaddr_in*)&ifr.ifr_addr;	
  
  if(sinp->sin_addr.s_addr)
    local_ip_address = inet_ntoa(sinp->sin_addr);	
  else
    local_ip_address = "";
  kdDebug(5002) << "Local IP: " << local_ip_address << endl;

  if (ioctl(s, SIOCGIFDSTADDR, &ifr) < 0)
    ;  

  sinp = (struct sockaddr_in*)&ifr.ifr_dstaddr;	

  if(sinp->sin_addr.s_addr)
    remote_ip_address = inet_ntoa(sinp->sin_addr);	
  else
    remote_ip_address = "";  
  kdDebug(5002) << "Remote IP: " << remote_ip_address << endl;    

  return true;

}



kppp'PPPStats::doStats() (./kdenetwork/kppp/pppstats.cpp:239)

bool PPPStats::doStats() {
  struct ppp_stats cur;

  if(! get_ppp_stats(&cur)){
    return false;
  }

  // "in"  "pack"  "comp"  "uncomp"  "err"
  // IN    PACK    VJCOMP  VJUNC     VJERR

  ibytes =   cur.p.ppp_ibytes; 			// bytes received
  ipackets =   cur.p.ppp_ipackets; 		// packets recieved
  compressedin =  cur.vj.vjs_compressedin; 	// inbound compressed packets
  uncompressedin =   cur.vj.vjs_uncompressedin; // inbound uncompressed packets
  errorin =  cur.vj.vjs_errorin; 		//receive errors

  //  "out"  "pack"  "comp"  "uncomp"  "ip"
  // OUT       PACK   JCOMP   VJUNC    NON-VJ

  obytes =  cur.p.ppp_obytes; 		       	// raw bytes sent
  opackets =  cur.p.ppp_opackets; 		// packets sent
  compressed =  cur.vj.vjs_compressed; 		//outbound compressed packets

  // outbound packets - outbound compressed packets
  packetsunc =  cur.vj.vjs_packets - cur.vj.vjs_compressed;

  // packets sent - oubount compressed
  packetsoutunc = cur.p.ppp_opackets - cur.vj.vjs_packets; 

  return true;
}


kppp'PPPStats::get_ppp_stats() (./kdenetwork/kppp/pppstats.cpp:273)

bool PPPStats::get_ppp_stats(struct ppp_stats *curp){

  struct ifpppstatsreq req;

    if(s==0)
      return false;

#ifdef linux
    req.stats_ptr = (caddr_t) &req.stats;
    sprintf(req.ifr__name, "ppp%d", unit);
#else
    sprintf(req.ifr_name, "ppp%d", unit);
#endif
    if (ioctl(s, SIOCGPPPSTATS, &req) < 0) {
	if (errno == ENOTTY)
	    fprintf(stderr, "pppstats: kernel support missing\n");
	else
	    perror("ioctl(SIOCGPPPSTATS)");
	return false;
    }
    *curp = req.stats;
    return true;
}

kppp'PPPStats::get_ppp_stats() (./kdenetwork/kppp/pppstats.cpp:298)

bool PPPStats::get_ppp_stats( struct ppp_stats *curp){

    if (strioctl(s, PPPIO_GETSTAT, curp, 0, sizeof(*curp)) < 0) {
	if (errno == EINVAL)
	    fprintf(stderr, "pppstats: kernel support missing\n");
	else
	    perror("pppstats: Couldn't get statistics");
	return false;
    }
}


kppp'PPPStats::strioctl() (./kdenetwork/kppp/pppstats.cpp:309)

bool PPPStats::strioctl(int fd, int cmd, char* ptr, int ilen, int olen){

    struct strioctl str;

    str.ic_cmd = cmd;
    str.ic_timout = 0;
    str.ic_len = ilen;
    str.ic_dp = ptr;
    if (ioctl(fd, I_STR, &str) == -1)
	return false;
    if (str.ic_len != olen)
	fprintf(stderr, "strioctl: expected %d bytes, got %d for cmd %x\n",
	       olen, str.ic_len, cmd);
    return true;
}
#endif /* __svr4__ */