2
* Copyright (C) 2013 Tobias Brunner
3
* Copyright (C) 2012 Christoph Buehler
4
* Copyright (C) 2012 Patrick Loetscher
5
* Hochschule fuer Technik Rapperswil
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the
9
* Free Software Foundation; either version 2 of the License, or (at your
10
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18
package org.strongswan.android.logic.imc.attributes;
20
import java.util.LinkedList;
22
import org.strongswan.android.logic.imc.collectors.Protocol;
23
import org.strongswan.android.utils.BufferedByteWriter;
25
import android.util.Pair;
28
* PA-TNC Port Filter attribute (see section 4.2.6 of RFC 5792)
31
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
32
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33
* | Reserved |B| Protocol | Port Number |
34
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35
* | Reserved |B| Protocol | Port Number |
36
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38
public class PortFilterAttribute implements Attribute
40
private final LinkedList<Pair<Protocol, Short>> mPorts = new LinkedList<Pair<Protocol, Short>>();
43
* Add an open port with the given protocol and port number
44
* @param protocol transport protocol
45
* @param port port number
47
public void addPort(Protocol protocol, short port)
49
mPorts.add(new Pair<Protocol, Short>(protocol, port));
53
public byte[] getEncoding()
55
BufferedByteWriter writer = new BufferedByteWriter();
56
for (Pair<Protocol, Short> port : mPorts)
58
/* we report open ports, so the BLOCKED flag is not set */
60
writer.put(port.first.getValue());
61
writer.put16(port.second);
63
return writer.toByteArray();