Commit 03748780 authored by Brickner_cp's avatar Brickner_cp

Add support for PPP With Directional Info Datalink.

parent 24414bbe
......@@ -173,7 +173,7 @@ namespace PcapDotNet.Core.Test
if (!IsBadHttp(httpDatagram))
{
Assert.AreEqual(fieldShow.ToWiresharkLowerLiteral(),
httpDatagram.Header.TransferEncoding.TransferCodings.SequenceToString(',').ToWiresharkLiteral());
httpDatagram.Header.TransferEncoding.TransferCodings.SequenceToString(',').ToLowerInvariant().ToWiresharkLiteral());
}
break;
......
......@@ -24,10 +24,19 @@ PcapDataLink::PcapDataLink(String^ name)
{
std::string unmanagedName = MarshalingServices::ManagedToUnmanagedString(name);
int value = pcap_datalink_name_to_val(unmanagedName.c_str());
if (value == -1)
throw gcnew ArgumentException("Invalid datalink name " + name, "name");
if (value != -1)
{
_value = value;
return;
}
if (name == "PPP_WITH_DIR")
{
_value = 204;
return;
}
throw gcnew ArgumentException("Invalid datalink name " + name, "name");
}
DataLinkKind PcapDataLink::Kind::get()
......@@ -43,6 +52,9 @@ DataLinkKind PcapDataLink::Kind::get()
case 143:
return DataLinkKind::Docsis;
case 204:
return DataLinkKind::PppWithDirection;
default:
throw gcnew NotSupportedException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " - " + ToString() + " is unsupported");
}
......@@ -57,19 +69,33 @@ int PcapDataLink::Value::get()
String^ PcapDataLink::Name::get()
{
const char* name = pcap_datalink_val_to_name(Value);
if (name == NULL)
throw gcnew InvalidOperationException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " has no name");
if (name != NULL)
return gcnew String(name);
switch (Value)
{
case 204:
return "PPP_WITH_DIR";
default:
throw gcnew InvalidOperationException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " has no name");
}
}
String^ PcapDataLink::Description::get()
{
const char* description = pcap_datalink_val_to_description(Value);
if (description == NULL)
throw gcnew InvalidOperationException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " has no description");
if (description != NULL)
return gcnew String(description);
switch (Value)
{
case 204:
return "PPP with Directional Info";
default:
throw gcnew InvalidOperationException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " has no description");
}
}
String^ PcapDataLink::ToString()
......@@ -123,6 +149,9 @@ int PcapDataLink::KindToValue(DataLinkKind kind)
case DataLinkKind::Docsis:
return 143;
case DataLinkKind::PppWithDirection:
return 204;
default:
throw gcnew NotSupportedException(PcapDataLink::typeid->Name + " kind " + kind.ToString() + " is unsupported");
}
......
......@@ -39,14 +39,18 @@ namespace PcapDotNet.Packets.Test
[TestMethod]
public void DataLinkTest()
{
Assert.AreEqual(DataLink.Ethernet, DataLink.Ethernet);
Assert.AreNotEqual(DataLink.Ethernet, 2);
Assert.AreEqual(DataLinkKind.Ethernet.ToString(), DataLink.Ethernet.ToString());
Assert.AreEqual(DataLink.Ethernet.GetHashCode(), DataLink.Ethernet.GetHashCode());
Assert.AreEqual(DataLinkKind.PppWithDirection.ToString(), new DataLink(DataLinkKind.PppWithDirection).ToString());
foreach (DataLink dataLink in new[] { DataLink.Ethernet, DataLink.IpV4 })
{
Assert.AreEqual(dataLink, dataLink);
Assert.AreNotEqual(dataLink, 2);
Assert.AreEqual(dataLink.GetHashCode(), dataLink.GetHashCode());
// ReSharper disable EqualExpressionComparison
Assert.IsTrue(DataLink.Ethernet == DataLink.Ethernet);
Assert.IsFalse(DataLink.Ethernet != DataLink.Ethernet);
Assert.IsTrue(dataLink == dataLink);
Assert.IsFalse(dataLink != dataLink);
// ReSharper restore EqualExpressionComparison
}
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ namespace PcapDotNet.Packets
{
/// <summary>
/// Represents the different data links kinds.
/// See http://www.tcpdump.org/linktypes.html for more data link kinds.
/// </summary>
public enum DataLinkKind
{
......@@ -19,5 +20,12 @@ namespace PcapDotNet.Packets
/// Data Over Cable Service Interface Specification.
/// </summary>
Docsis,
/// <summary>
/// PPP With Directional Info.
/// PPP, as per RFC 1661 and RFC 1662, preceded with a one-byte pseudo-header with a zero value meaning "received by this host"
/// and a non-zero value meaning "sent by this host".
/// </summary>
PppWithDirection,
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment