/** * Prints a string representation of FieldData to stdout. */ void printFieldData(FieldType type, FieldData* pattern) { char* s; switch (type.id) { case IPFIX_TYPEID_protocolIdentifier: printf("protocolIdentifier:"); printProtocol(type, pattern); break; case IPFIX_TYPEID_sourceIPv4Address: printf("sourceIPv4Address:"); printIPv4(type, pattern); break; case IPFIX_TYPEID_destinationIPv4Address: printf("destinationIPv4Address:"); printIPv4(type, pattern); break; case IPFIX_TYPEID_sourceTransportPort: printf("sourceTransportPort:"); printPort(type, pattern); break; case IPFIX_TYPEID_destinationtransportPort: printf("destinationtransportPort:"); printPort(type, pattern); break; default: s = typeid2string(type.id); if (s != NULL) { printf("%s:", s); printUint(type, pattern); } else { DPRINTF("Field with ID %d unparseable\n", type.id); } break; } }
/** * Prints a string representation of IpfixRecord::Data to stdout. */ void printFieldData(IpfixRecord::FieldInfo::Type type, IpfixRecord::Data* pattern) { char* s; timeval t; uint64_t hbnum; switch (type.id) { case IPFIX_TYPEID_protocolIdentifier: printf("protocolIdentifier: "); printProtocol(type, pattern); break; case IPFIX_TYPEID_sourceIPv4Address: printf("sourceIPv4Address: "); printIPv4(type, pattern); break; case IPFIX_TYPEID_destinationIPv4Address: printf("destinationIPv4Address: "); printIPv4(type, pattern); break; case IPFIX_TYPEID_sourceTransportPort: printf("sourceTransportPort: "); printPort(type, pattern); break; case IPFIX_TYPEID_destinationTransportPort: printf("destinationTransportPort: "); printPort(type, pattern); break; case IPFIX_TYPEID_flowStartNanoSeconds: case IPFIX_TYPEID_flowEndNanoSeconds: case IPFIX_ETYPEID_revFlowStartNanoSeconds: case IPFIX_ETYPEID_revFlowEndNanoSeconds: printf("%s: ", typeid2string(type.id)); hbnum = ntohll(*(uint64_t*)pattern); if (hbnum>0) { t = timentp64(*((ntp64*)(&hbnum))); printf("%d.%06d seconds", (int32_t)t.tv_sec, (int32_t)t.tv_usec); } else { printf("no value (only zeroes in field)"); } break; case IPFIX_ETYPEID_frontPayload: case IPFIX_ETYPEID_revFrontPayload: printf("%s: ", typeid2string(type.id)); printFrontPayload(type, pattern); break; default: s = typeid2string(type.id); if (s != NULL) { printf("%s: ", s); printUint(type, pattern); } else { DPRINTF("Field with ID %d unparseable\n", type.id); } break; } }
/** * @brief Prints a description of the given rule. * * @param singleRule */ void printSingleRule(const char * singleRule) { char name[20] = ""; unsigned short direction; unsigned int srcIp; unsigned short srcPrefixSize; unsigned int dstIp; unsigned short dstPrefixSsize; unsigned short srcPort; unsigned short dstPort; unsigned short protocol; unsigned short ack; unsigned short action; sscanf(singleRule, "%s %hu %d %hu %d %hu %hu %hu %hu %hu %hu", name, &direction, &srcIp, &srcPrefixSize, &dstIp, &dstPrefixSsize, &protocol, &srcPort, &dstPort, &ack, &action); /* Printing the rule */ printf("%s %s ", name, getDirectionString(direction)); printSubnetString(srcIp, srcPrefixSize); printf(" "); printSubnetString(dstIp, dstPrefixSsize); printf(" "); printf("%s ", getProtocolString(protocol)); printPort(srcPort); printf(" "); printPort(dstPort); printf(" %s %s\n", getAckString(ack), getActionString(action)); }
/** * Prints a string representation of IpfixRecord::Data to stdout. */ void PrintHelpers::printFieldData(InformationElement::IeInfo type, IpfixRecord::Data* pattern) { timeval t; uint64_t hbnum; string typeStr = type.toString(); // try to get the values aligned if (typeStr.length() < 60) fprintf(fh, "%-60s: ", type.toString().c_str()); else fprintf(fh, "%s: ", type.toString().c_str()); switch (type.enterprise) { case 0: switch (type.id) { case IPFIX_TYPEID_protocolIdentifier: printProtocol(type, pattern); return; case IPFIX_TYPEID_sourceIPv4Address: printIPv4(type, pattern); return; case IPFIX_TYPEID_destinationIPv4Address: printIPv4(type, pattern); return; case IPFIX_TYPEID_sourceTransportPort: printPort(type, pattern); return; case IPFIX_TYPEID_destinationTransportPort: printPort(type, pattern); return; case IPFIX_TYPEID_flowStartSeconds: case IPFIX_TYPEID_flowEndSeconds: case IPFIX_TYPEID_flowStartMilliSeconds: case IPFIX_TYPEID_flowEndMilliSeconds: case PSAMP_TYPEID_observationTimeSeconds: printLocaltime(type, pattern); return; case IPFIX_TYPEID_flowStartNanoSeconds: case IPFIX_TYPEID_flowEndNanoSeconds: hbnum = ntohll(*(uint64_t*)pattern); if (hbnum>0) { t = timentp64(*((ntp64*)(&hbnum))); fprintf(fh, "%u.%06d seconds", (int32_t)t.tv_sec, (int32_t)t.tv_usec); } else { fprintf(fh, "no value (only zeroes in field)"); } return; } break; case IPFIX_PEN_reverse: switch (type.id) { case IPFIX_TYPEID_flowStartNanoSeconds: case IPFIX_TYPEID_flowEndNanoSeconds: hbnum = ntohll(*(uint64_t*)pattern); if (hbnum>0) { t = timentp64(*((ntp64*)(&hbnum))); fprintf(fh, "%u.%06d seconds", (int32_t)t.tv_sec, (int32_t)t.tv_usec); } else { fprintf(fh, "no value (only zeroes in field)"); } return; } break; default: { if (type==InformationElement::IeInfo(IPFIX_ETYPEID_frontPayload, IPFIX_PEN_vermont) || type==InformationElement::IeInfo(IPFIX_ETYPEID_frontPayload, IPFIX_PEN_vermont|IPFIX_PEN_reverse)) { printFrontPayload(type, pattern); return; } } } printUint(type, pattern); }
bool CmdPin::execute(CommandInterpreter &/*interpreter*/, int argc, const CommandInterpreter::Argument *argv) { bool config = false; bool poll = false; if (argv[0].value.s[3] == 'c') config = true; if (argv[0].value.s[3] == 'p') poll = true; if (argc == 1) { for (unsigned int index = 0; index < mGpioCount; ++index) { printPort(index, config); } return true; } char c = argv[1].value.s[0]; unsigned int index = c - 'A'; if (index > mGpioCount) index = c - 'a'; if (index > mGpioCount) { printf("Invalid GPIO, GPIO A-%c (or a-%c) is allowed.\n", 'A' + mGpioCount - 1, 'a' + mGpioCount - 1); return false; } if (argv[1].value.s[1] == 0) { printPort(index, config); } else { char* end; unsigned int pin = strtoul(argv[1].value.s + 1, &end, 10); if (*end != 0 || pin > 15) { printf("Invalid index, GPIO has only 16 pins, so 0-15 is allowed.\n"); return false; } if (argc == 2) { printf("GPIO %c%i: ", 'A' + index, pin); if (config) { printConfig(mGpio[index], pin); } else { uint64_t lastTime = System::instance()->ns(); bool lastValue = mGpio[index]->get(static_cast<Gpio::Index>(pin)); printValue(mGpio[index], pin); int count = 1000000; int change = 0; while (poll && count > 0 && change < 10) { --count; bool value = mGpio[index]->get(static_cast<Gpio::Index>(pin)); if (value != lastValue) { ++change; uint64_t time = System::instance()->ns(); printf(" for %llu us, ", (time - lastTime) / 1000); lastTime = time; lastValue = value; printValue(mGpio[index], pin); } } } printf("\n"); } else { if (config) { printf("Sorry, can't configure pins.\n"); } else { if (argv[2].value.b) mGpio[index]->set(static_cast<Gpio::Index>(pin)); else mGpio[index]->reset(static_cast<Gpio::Index>(pin)); } } } return true; }