// Path: src/main/java/com/github/ffalcinelli/jdivert/exceptions/WinDivertException.java
// public class WinDivertException extends Exception {
//     protected int code;
//     protected String message;
//     protected LastErrorException lee;
// 
//     public WinDivertException(int code) {
//         this(code, Kernel32Util.formatMessage(code));
//     }
// 
//     public WinDivertException(int code, String message) {
//         this(code, message, null);
//     }
// 
//     public WinDivertException(int code, String message, Throwable cause) {
//         super(message, cause);
//         this.code = code;
//     }
// 
//     /**
//      * Throw a WinDivertException whenever GetLastError returned a code different from
//      * <ul>
//      * <li>0 (Success)</li>
//      * <li>997 (Overlapped I/O is in progress)</li>
//      *</ul>
//      * @return The GetLastError code.
//      * @throws WinDivertException When {@code GetLastError} returns a code different from 0 or 997, {@link WinDivertException} is thrown.
//      */
//     public static int throwExceptionOnGetLastError() throws WinDivertException {
//         int lastError = Native.getLastError();
//         if (lastError != 0 && lastError != 997) {
//             throw new WinDivertException(lastError);
//         }
//         return lastError;
//     }
// 
//     public int getCode() {
//         return code;
//     }
// 
//     @Override
//     public String toString() {
//         return "WinDivertException{" +
//                 "code=" + code +
//                 ", message='" + message + '\'' +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/github/ffalcinelli/jdivert/windivert/WinDivertAddress.java
// public class WinDivertAddress extends Structure {
//     public WinDef.UINT IfIdx;
//     public WinDef.UINT SubIfIdx;
//     public WinDef.USHORT Direction;
// 
//     @Override
//     protected List getFieldOrder() {
//         return Arrays.asList("IfIdx",
//                 "SubIfIdx",
//                 "Direction");
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         WinDivertAddress that = (WinDivertAddress) o;
// 
//         return IfIdx.intValue() == that.IfIdx.intValue() &&
//                 SubIfIdx.intValue() == that.SubIfIdx.intValue() &&
//                 Direction.intValue() == that.Direction.intValue();
// 
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = 31 * IfIdx.hashCode();
//         result = 31 * result + SubIfIdx.hashCode();
//         result = 31 * result + Direction.hashCode();
//         return result;
//     }
// }
// 
// Path: src/main/java/com/github/ffalcinelli/jdivert/Util.java
// public static byte[] parseHexBinary(String s) {
//     final int len = s.length();
// 
//     // "111" is not a valid hex encoding.
//     if (len % 2 != 0)
//         throw new IllegalArgumentException("hexBinary needs to be even-length: " + s);
// 
//     byte[] out = new byte[len / 2];
// 
//     for (int i = 0; i < len; i += 2) {
//         int h = hexToBin(s.charAt(i));
//         int l = hexToBin(s.charAt(i + 1));
//         if (h == -1 || l == -1)
//             throw new IllegalArgumentException("contains illegal character for hexBinary: " + s);
// 
//         out[i / 2] = (byte) (h * 16 + l);
//     }
// 
//     return out;
// }
// 
// Path: src/main/java/com/github/ffalcinelli/jdivert/Util.java
// public static String printHexBinary(ByteBuffer data) {
//     return printHexBinary(getBytesAtOffset(data, 0, data.capacity()));
// }


import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.*;
import com.github.ffalcinelli.jdivert.exceptions.WinDivertException;
import com.github.ffalcinelli.jdivert.windivert.WinDivertAddress;
import com.sun.jna.platform.win32.WinDef;
import org.junit.Before;
import org.junit.Test;
import java.net.UnknownHostException;
import static com.github.ffalcinelli.jdivert.Enums.CalcChecksumsOption.NO_TCP_CHECKSUM;
import static com.github.ffalcinelli.jdivert.Enums.Direction.OUTBOUND;
import static com.github.ffalcinelli.jdivert.Util.parseHexBinary;
import static com.github.ffalcinelli.jdivert.Util.printHexBinary;
import static com.github.ffalcinelli.jdivert.headers.Tcp.Flag.FIN;
/*
 * Copyright (c) Fabio Falcinelli 2016.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.github.ffalcinelli.jdivert;




/**
 * Created by fabio on 03/11/2016.
 */
public class PacketTestCase {

    Packet packet;
    byte[] raw;
    byte[] payload;
    WinDivertAddress addr;
    String localhost = "127.0.0.1";

// Path: src/main/java/com/github/ffalcinelli/jdivert/exceptions/WinDivertException.java
// public class WinDivertException extends Exception {
//     protected int code;
//     protected String message;
//     protected LastErrorException lee;
// 
//     public WinDivertException(int code) {
//         this(code, Kernel32Util.formatMessage(code));
//     }
// 
//     public WinDivertException(int code, String message) {
//         this(code, message, null);
//     }
// 
//     public WinDivertException(int code, String message, Throwable cause) {
//         super(message, cause);
//         this.code = code;
//     }
// 
//     /**
//      * Throw a WinDivertException whenever GetLastError returned a code different from
//      * <ul>
//      * <li>0 (Success)</li>
//      * <li>997 (Overlapped I/O is in progress)</li>
//      *</ul>
//      * @return The GetLastError code.
//      * @throws WinDivertException When {@code GetLastError} returns a code different from 0 or 997, {@link WinDivertException} is thrown.
//      */
//     public static int throwExceptionOnGetLastError() throws WinDivertException {
//         int lastError = Native.getLastError();
//         if (lastError != 0 && lastError != 997) {
//             throw new WinDivertException(lastError);
//         }
//         return lastError;
//     }
// 
//     public int getCode() {
//         return code;
//     }
// 
//     @Override
//     public String toString() {
//         return "WinDivertException{" +
//                 "code=" + code +
//                 ", message='" + message + '\'' +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/github/ffalcinelli/jdivert/windivert/WinDivertAddress.java
// public class WinDivertAddress extends Structure {
//     public WinDef.UINT IfIdx;
//     public WinDef.UINT SubIfIdx;
//     public WinDef.USHORT Direction;
// 
//     @Override
//     protected List getFieldOrder() {
//         return Arrays.asList("IfIdx",
//                 "SubIfIdx",
//                 "Direction");
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         WinDivertAddress that = (WinDivertAddress) o;
// 
//         return IfIdx.intValue() == that.IfIdx.intValue() &&
//                 SubIfIdx.intValue() == that.SubIfIdx.intValue() &&
//                 Direction.intValue() == that.Direction.intValue();
// 
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = 31 * IfIdx.hashCode();
//         result = 31 * result + SubIfIdx.hashCode();
//         result = 31 * result + Direction.hashCode();
//         return result;
//     }
// }
// 
// Path: src/main/java/com/github/ffalcinelli/jdivert/Util.java
// public static byte[] parseHexBinary(String s) {
//     final int len = s.length();
// 
//     // "111" is not a valid hex encoding.
//     if (len % 2 != 0)
//         throw new IllegalArgumentException("hexBinary needs to be even-length: " + s);
// 
//     byte[] out = new byte[len / 2];
// 
//     for (int i = 0; i < len; i += 2) {
//         int h = hexToBin(s.charAt(i));
//         int l = hexToBin(s.charAt(i + 1));
//         if (h == -1 || l == -1)
//             throw new IllegalArgumentException("contains illegal character for hexBinary: " + s);
// 
//         out[i / 2] = (byte) (h * 16 + l);
//     }
// 
//     return out;
// }
// 
// Path: src/main/java/com/github/ffalcinelli/jdivert/Util.java
// public static String printHexBinary(ByteBuffer data) {
//     return printHexBinary(getBytesAtOffset(data, 0, data.capacity()));
// }


// Path: src/test/java/com/github/ffalcinelli/jdivert/PacketTestCase.java
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.*;
import com.github.ffalcinelli.jdivert.exceptions.WinDivertException;
import com.github.ffalcinelli.jdivert.windivert.WinDivertAddress;
import com.sun.jna.platform.win32.WinDef;
import org.junit.Before;
import org.junit.Test;
import java.net.UnknownHostException;
import static com.github.ffalcinelli.jdivert.Enums.CalcChecksumsOption.NO_TCP_CHECKSUM;
import static com.github.ffalcinelli.jdivert.Enums.Direction.OUTBOUND;
import static com.github.ffalcinelli.jdivert.Util.parseHexBinary;
import static com.github.ffalcinelli.jdivert.Util.printHexBinary;
import static com.github.ffalcinelli.jdivert.headers.Tcp.Flag.FIN;

/*
 * Copyright (c) Fabio Falcinelli 2016.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.github.ffalcinelli.jdivert;




/**
 * Created by fabio on 03/11/2016.
 */
public class PacketTestCase {

    Packet packet;
    byte[] raw;
    byte[] payload;
    WinDivertAddress addr;
    String localhost = "127.0.0.1";

    @Before