/*public*/ void PrintRoutesAction::actionPerformed(ActionEvent* /*e*/)
 {
  log->debug("Print all routes");
  // obtain a HardcopyWriter to do this
  HardcopyWriter* writer = NULL;
  //try {
      writer = new HardcopyWriter(mFrame, tr(
              "Print all routes"), Control::reportFontSize, .5, .5, .5, .5,
              isPreview);
//     } catch (HardcopyWriter.PrintCanceledException ex) {
//         log.debug("Print cancelled");
//         return;
//     }
  QList<Route*> routes = RouteManager::instance()->getRoutesByNameList();
  for (int i = 0; i < routes.size(); i++) {
      Route* route = routes.at(i);
      //try {
          writer->write(route->getName() + NEW_LINE);
          printRoute(writer, route);
          if (i != routes.size() - 1) {
              writer->write(QString(FORM_FEED));
          }
//         } catch (IOException e1) {
//             log.error("Exception in print routes");
//         }
  }
  // and force completion of the printing
  writer->close();
 }
Esempio n. 2
0
/* For parsing the route info returned */
void parseRoutes(struct nlmsghdr *nlHdr, struct route_info *rtInfo,char *gateway)
{
	 struct rtmsg *rtMsg;
	  struct rtattr *rtAttr;
	   int rtLen;
	    char *tempBuf = NULL;

		 tempBuf = (char *)malloc(100);
		  rtMsg = (struct rtmsg *)NLMSG_DATA(nlHdr);

		   /* If the route is not for AF_INET or does not belong to main routing table
			   then return. */
		   if((rtMsg->rtm_family != AF_INET) || (rtMsg->rtm_table != RT_TABLE_MAIN))
			    return;

		    /* get the rtattr field */
		    rtAttr = (struct rtattr *)RTM_RTA(rtMsg);
			 rtLen = RTM_PAYLOAD(nlHdr);
			  for(;RTA_OK(rtAttr,rtLen);rtAttr = RTA_NEXT(rtAttr,rtLen)){
				    switch(rtAttr->rta_type) {
						  case RTA_OIF:
							     if_indextoname(*(int *)RTA_DATA(rtAttr), rtInfo->ifName);
								    break;
									  case RTA_GATEWAY:
									   rtInfo->gateWay = *(u_int *)RTA_DATA(rtAttr);
									      break;
										    case RTA_PREFSRC:
										     rtInfo->srcAddr = *(u_int *)RTA_DATA(rtAttr);
											    break;
												  case RTA_DST:
												   rtInfo->dstAddr = *(u_int *)RTA_DATA(rtAttr);
												      break;
													    }
					 }
			   //printf("%s\n", (char *)inet_ntoa(rtInfo->dstAddr));

			   // ADDED BY BOB - ALSO COMMENTED printRoute

			   if (strstr((char *)inet_ntoa(rtInfo->dstAddr), "0.0.0.0"))
				     sprintf(gateway, (char *)inet_ntoa(rtInfo->gateWay));
			     printRoute(rtInfo);

			    free(tempBuf);
				 return;
}