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 ...@@ -173,7 +173,7 @@ namespace PcapDotNet.Core.Test
if (!IsBadHttp(httpDatagram)) if (!IsBadHttp(httpDatagram))
{ {
Assert.AreEqual(fieldShow.ToWiresharkLowerLiteral(), Assert.AreEqual(fieldShow.ToWiresharkLowerLiteral(),
httpDatagram.Header.TransferEncoding.TransferCodings.SequenceToString(',').ToWiresharkLiteral()); httpDatagram.Header.TransferEncoding.TransferCodings.SequenceToString(',').ToLowerInvariant().ToWiresharkLiteral());
} }
break; break;
......
...@@ -24,10 +24,19 @@ PcapDataLink::PcapDataLink(String^ name) ...@@ -24,10 +24,19 @@ PcapDataLink::PcapDataLink(String^ name)
{ {
std::string unmanagedName = MarshalingServices::ManagedToUnmanagedString(name); std::string unmanagedName = MarshalingServices::ManagedToUnmanagedString(name);
int value = pcap_datalink_name_to_val(unmanagedName.c_str()); int value = pcap_datalink_name_to_val(unmanagedName.c_str());
if (value == -1) if (value != -1)
throw gcnew ArgumentException("Invalid datalink name " + name, "name"); {
_value = value;
return;
}
_value = value; if (name == "PPP_WITH_DIR")
{
_value = 204;
return;
}
throw gcnew ArgumentException("Invalid datalink name " + name, "name");
} }
DataLinkKind PcapDataLink::Kind::get() DataLinkKind PcapDataLink::Kind::get()
...@@ -43,6 +52,9 @@ DataLinkKind PcapDataLink::Kind::get() ...@@ -43,6 +52,9 @@ DataLinkKind PcapDataLink::Kind::get()
case 143: case 143:
return DataLinkKind::Docsis; return DataLinkKind::Docsis;
case 204:
return DataLinkKind::PppWithDirection;
default: default:
throw gcnew NotSupportedException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " - " + ToString() + " is unsupported"); throw gcnew NotSupportedException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " - " + ToString() + " is unsupported");
} }
...@@ -57,19 +69,33 @@ int PcapDataLink::Value::get() ...@@ -57,19 +69,33 @@ int PcapDataLink::Value::get()
String^ PcapDataLink::Name::get() String^ PcapDataLink::Name::get()
{ {
const char* name = pcap_datalink_val_to_name(Value); const char* name = pcap_datalink_val_to_name(Value);
if (name == NULL) if (name != NULL)
throw gcnew InvalidOperationException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " has no name"); return gcnew String(name);
switch (Value)
{
case 204:
return "PPP_WITH_DIR";
return gcnew String(name); default:
throw gcnew InvalidOperationException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " has no name");
}
} }
String^ PcapDataLink::Description::get() String^ PcapDataLink::Description::get()
{ {
const char* description = pcap_datalink_val_to_description(Value); const char* description = pcap_datalink_val_to_description(Value);
if (description == NULL) if (description != NULL)
throw gcnew InvalidOperationException(PcapDataLink::typeid->Name + " " + Value.ToString(CultureInfo::InvariantCulture) + " has no description"); return gcnew String(description);
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() String^ PcapDataLink::ToString()
...@@ -123,6 +149,9 @@ int PcapDataLink::KindToValue(DataLinkKind kind) ...@@ -123,6 +149,9 @@ int PcapDataLink::KindToValue(DataLinkKind kind)
case DataLinkKind::Docsis: case DataLinkKind::Docsis:
return 143; return 143;
case DataLinkKind::PppWithDirection:
return 204;
default: default:
throw gcnew NotSupportedException(PcapDataLink::typeid->Name + " kind " + kind.ToString() + " is unsupported"); throw gcnew NotSupportedException(PcapDataLink::typeid->Name + " kind " + kind.ToString() + " is unsupported");
} }
......
...@@ -39,14 +39,18 @@ namespace PcapDotNet.Packets.Test ...@@ -39,14 +39,18 @@ namespace PcapDotNet.Packets.Test
[TestMethod] [TestMethod]
public void DataLinkTest() public void DataLinkTest()
{ {
Assert.AreEqual(DataLink.Ethernet, DataLink.Ethernet);
Assert.AreNotEqual(DataLink.Ethernet, 2);
Assert.AreEqual(DataLinkKind.Ethernet.ToString(), DataLink.Ethernet.ToString()); 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());
// ReSharper disable EqualExpressionComparison foreach (DataLink dataLink in new[] { DataLink.Ethernet, DataLink.IpV4 })
Assert.IsTrue(DataLink.Ethernet == DataLink.Ethernet); {
Assert.IsFalse(DataLink.Ethernet != DataLink.Ethernet); Assert.AreEqual(dataLink, dataLink);
// ReSharper restore EqualExpressionComparison Assert.AreNotEqual(dataLink, 2);
Assert.AreEqual(dataLink.GetHashCode(), dataLink.GetHashCode());
// ReSharper disable EqualExpressionComparison
Assert.IsTrue(dataLink == dataLink);
Assert.IsFalse(dataLink != dataLink);
// ReSharper restore EqualExpressionComparison
}
} }
} }
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ namespace PcapDotNet.Packets ...@@ -2,6 +2,7 @@ namespace PcapDotNet.Packets
{ {
/// <summary> /// <summary>
/// Represents the different data links kinds. /// Represents the different data links kinds.
/// See http://www.tcpdump.org/linktypes.html for more data link kinds.
/// </summary> /// </summary>
public enum DataLinkKind public enum DataLinkKind
{ {
...@@ -19,5 +20,12 @@ namespace PcapDotNet.Packets ...@@ -19,5 +20,12 @@ namespace PcapDotNet.Packets
/// Data Over Cable Service Interface Specification. /// Data Over Cable Service Interface Specification.
/// </summary> /// </summary>
Docsis, 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