// Path: app/src/main/java/com/github/xfalcon/vhosts/util/LogUtils.java
// public class LogUtils {
// 
// 
//     public static Context context;
// 
//     private static void sendLogData(String tag,String msg){
// 
//     }
// 
//     public static void v(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.v(tag,msg);
//     }
// 
//     public static void v(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.v(tag,msg,tr);
//     }
// 
//     public static void d(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.d(tag,msg);
//     }
// 
//     public static void d(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.d(tag,msg,tr);
//     }
// 
//     public static void i(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.i(tag,msg);
//     }
// 
//     public static void i(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.i(tag,msg,tr);
//     }
// 
//     public static void w(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.w(tag,msg);
//     }
// 
//     public static void w(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.w(tag,msg,tr);
//     }
// 
//     public static void e(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.e(tag,msg);
//     }
// 
//     public static void e(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.e(tag,msg,tr);
//     }
// 
// }


import com.github.xfalcon.vhosts.util.LogUtils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
/*
** Copyright 2015, Mohamed Naufal
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

package com.github.xfalcon.vhosts.vservice;




/**
 * Representation of an IP Packet
 */
// TODO: Reduce public mutability
public class Packet {
    private static final int IP4_HEADER_SIZE = 20;
    private static final int IP6_HEADER_SIZE = 40;
    private static final int TCP_HEADER_SIZE = 20;
    private static final int UDP_HEADER_SIZE = 8;
    private static final int TCP = 6;
    private static final int UDP = 17;
    private int IP_HEADER_SIZE;
    public int IP_TRAN_SIZE;
    public IPHeader ipHeader;
    public TCPHeader tcpHeader;
    public UDPHeader udpHeader;
    public ByteBuffer backingBuffer;

    private boolean isTCP;
    private boolean isUDP;

    public Packet(ByteBuffer buffer) throws UnknownHostException {
        byte versionAndIHL = buffer.get();
        byte version = (byte) (versionAndIHL >> 4);
        if (version == 4) {
            IP_HEADER_SIZE = IP4_HEADER_SIZE;
            byte IHL = (byte) (versionAndIHL & 0x0F);
            int headerLength = IHL << 2;
            this.ipHeader = new IP4Header(buffer, version, IHL, headerLength);
        } else if (version == 6) {
            IP_HEADER_SIZE = IP6_HEADER_SIZE;
            this.ipHeader = new IP6Header(buffer, version);
        } else {
// Path: app/src/main/java/com/github/xfalcon/vhosts/util/LogUtils.java
// public class LogUtils {
// 
// 
//     public static Context context;
// 
//     private static void sendLogData(String tag,String msg){
// 
//     }
// 
//     public static void v(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.v(tag,msg);
//     }
// 
//     public static void v(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.v(tag,msg,tr);
//     }
// 
//     public static void d(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.d(tag,msg);
//     }
// 
//     public static void d(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.d(tag,msg,tr);
//     }
// 
//     public static void i(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.i(tag,msg);
//     }
// 
//     public static void i(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.i(tag,msg,tr);
//     }
// 
//     public static void w(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.w(tag,msg);
//     }
// 
//     public static void w(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.w(tag,msg,tr);
//     }
// 
//     public static void e(String tag, String msg) {
//         sendLogData(tag,msg);
//         Log.e(tag,msg);
//     }
// 
//     public static void e(String tag, String msg, Throwable tr) {
//         sendLogData(tag,msg+"   ;"+tr.getMessage());
//         Log.e(tag,msg,tr);
//     }
// 
// }


// Path: app/src/main/java/com/github/xfalcon/vhosts/vservice/Packet.java
import com.github.xfalcon.vhosts.util.LogUtils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;

/*
** Copyright 2015, Mohamed Naufal
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

package com.github.xfalcon.vhosts.vservice;




/**
 * Representation of an IP Packet
 */
// TODO: Reduce public mutability
public class Packet {
    private static final int IP4_HEADER_SIZE = 20;
    private static final int IP6_HEADER_SIZE = 40;
    private static final int TCP_HEADER_SIZE = 20;
    private static final int UDP_HEADER_SIZE = 8;
    private static final int TCP = 6;
    private static final int UDP = 17;
    private int IP_HEADER_SIZE;
    public int IP_TRAN_SIZE;
    public IPHeader ipHeader;
    public TCPHeader tcpHeader;
    public UDPHeader udpHeader;
    public ByteBuffer backingBuffer;

    private boolean isTCP;
    private boolean isUDP;

    public Packet(ByteBuffer buffer) throws UnknownHostException {
        byte versionAndIHL = buffer.get();
        byte version = (byte) (versionAndIHL >> 4);
        if (version == 4) {
            IP_HEADER_SIZE = IP4_HEADER_SIZE;
            byte IHL = (byte) (versionAndIHL & 0x0F);
            int headerLength = IHL << 2;
            this.ipHeader = new IP4Header(buffer, version, IHL, headerLength);
        } else if (version == 6) {
            IP_HEADER_SIZE = IP6_HEADER_SIZE;
            this.ipHeader = new IP6Header(buffer, version);
        } else {
            LogUtils.d("Un Know Packet", version + "");