const dns = require('dns')

const localIP = '192.168.178.0'
// TODO: make local IP a variable or in config file

function getRoutesFromPacketArray (packetArray) {
    var routesArray = []
    for (var packet in packetArray) {
        try {
            routesArray.push(getRouteFromPacket(packet))
        } catch (exception) {
            console.log(exception)
        }
    }
}

function getRouteFromPacket (packet) {
    switch (packet.payload.ethertype) {
        case 0x800:
            // console.log('Ipv4')
            // use module.exports.function for testability
            return module.exports.handleIPv4Packet(packet.payload.payload)
        case 0x86dd:
            // console.log('Ipv6')
            return module.exports.handleIPv6Packet(packet.payload.payload)
        default:
            throw new Error('Don\'t know how to handle this packet of ethertype ' + packet.payload.ethertype)
    }
}

// TODO: check if packet is valid, check if IPs are valid
function handleIPv4Packet (packet) {
    var route = {
        senderIP: packet.saddr.toString(),
        receiverIP: packet.daddr.toString()
    }
    // console.log('IPv4: ', result)
    return route
}

// TODO: same as IPv4
function handleIPv6Packet (packet) {
    console.log('Ipv6 in function')
    return 'IPv6 Packet'
}

// TODO: check if IP valid, return ipAddress if dns.reverse fails
function reverseLookupOfIP (ipAddress) {
    // console.log(ipAddress)
    return new Promise((resolve, reject) => {
        dns.reverse(ipAddress, (err, domains) => {
            if (err) {
                reject(err)
            }
            // console.log('reverse for ' + ipAddress + ': ' + domains)
            resolve(domains)
        })
    })
}

// TODO: check if IPs valid
function getLocalAddress (sender, receiver) {
    if (getNetworkPartOfIP(sender) === getNetworkPartOfIP(localIP)) {
        return {local: sender, receiver}
    } else {
        // if sender is not local, then receiver must be local
        return {local: receiver, receiver: sender}
    }
}

// TODO: check if IP valid
function getNetworkPartOfIP (ipAddress) {
    return ipAddress.substring(0, ipAddress.lastIndexOf('.'))
}

module.exports = {
    reverseLookupOfIP,
    handleIPv4Packet,
    handleIPv6Packet,
    getRoutesFromPacketArray,
    getRouteFromPacket,
    getLocalAddress
}

@@ -524,89 +524,15 @@
     
-// use module.exports.function for testability%0A            return module.exports.
+return 
 hand
@@ -647,23 +647,8 @@
 urn 
-module.exports.
 hand
@@ -2128,52 +2128,8 @@
 IP,%0A
-    handleIPv4Packet,%0A    handleIPv6Packet,%0A
     

Remove surplus exports