/* 
 * File:   scada_tester.h
 * Author: Jan Hudec
 *
 * Created on 19. května 2019, 13:54
 */

#ifndef SCADA_TESTER_H
#define SCADA_TESTER_H

#include <pcap.h>

// dependencies
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/if_ether.h> /* includes net/ethernet.h */

// generic libraries
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>

class scada_tester {
public:    
    enum FRAME_TYPE { GOOSE = 1, SV };
    
    scada_tester(std::string device);
    ~scada_tester();
    
    void change_goose_sv(FRAME_TYPE type);
    
private:
    std::stringstream ss;
    const u_char* packet;
    
    
    
    static void get_packet(int count, char* filter_exp);
    void packet_handler(u_char *args, const struct pcap_pkthdr* header, const u_char* packet);
    
    void dissect_packet(FRAME_TYPE type);
    
    void payload_to_ss(const u_char* payload, int length);
    int64_t get_int_from_payload(const u_char* payload, int length);
    float get_float_from_payload(const u_char* payload, int length);
    int get_timestamp_from_payload(const u_char* payload, int length);
    std::string get_string_from_payload(const u_char* payload, int length);
};



#endif /* SCADA_TESTER_H */

