Click here to Skip to main content
15,891,976 members
Articles / Web Development / HTML

SharpPcap - A Packet Capture Framework for .NET

,
Rate me:
Please Sign up or sign in to vote.
4.94/5 (192 votes)
5 May 2014MPL21 min read 2.1M   10.3K   518  
A framework for capturing, injecting and analyzing network packets for .NET applications based on the WinPcap packet capture driver
// $Id: AsciiHelper.java,v 1.1 2001/06/14 21:19:58 pcharles Exp $

/// <summary>************************************************************************
/// Copyright (C) 2001, Patrick Charles and Jonas Lehmann                   *
/// Distributed under the Mozilla Public License                            *
/// http://www.mozilla.org/NPL/MPL-1.1.txt                                *
/// *************************************************************************
/// </summary>
namespace Tamir.IPLib.Packets.Util
{
	using System;
	/// <summary> Functions for formatting and printing binary data as ascii.
	/// *
	/// </summary>
	/// <author>  Patrick Charles and Jonas Lehmann
	/// </author>
	/// <version>  $Revision: 1.1 $
	/// @lastModifiedBy $Author: pcharles $
	/// @lastModifiedAt $Date: 2001/06/14 21:19:58 $
	/// 
	/// </version>
	public class AsciiHelper
	{
		/// <summary> Returns a text representation of a byte array.
		/// Bytes in the array which don't convert to text in the range a..Z
		/// are dropped.
		/// *
		/// </summary>
		/// <param name="bytes">a byte array
		/// </param>
		/// <returns> a string containing the text equivalent of the bytes.
		/// 
		/// </returns>
		public static System.String toText(byte[] bytes)
		{
			System.IO.StringWriter sw = new System.IO.StringWriter();
			
			int length = bytes.Length;
			if (length > 0)
			{
				for (int i = 0; i < length; i++)
				{
					byte b = bytes[i];
					if (b > 64 && b < 91 || b > 96 && b < 123)
						sw.Write((char) b);
				}
			}
			return (sw.ToString());
		}
		
		/// <summary> Returns a text representation of a byte array.
		/// Bytes in the array which don't convert to printable ascii characters
		/// are dropped.
		/// *
		/// </summary>
		/// <param name="bytes">a byte array
		/// </param>
		/// <returns> a string containing the ascii equivalent of the bytes.
		/// 
		/// </returns>
		public static System.String toString(byte[] bytes)
		{
			System.IO.StringWriter sw = new System.IO.StringWriter();
			
			int length = bytes.Length;
			if (length > 0)
			{
				for (int i = 0; i < length; i++)
				{
					byte b = bytes[i];
					if (b > 32 && b < 127)
						sw.Write((char) b);
				}
			}
			return (sw.ToString());
		}
		
		
		internal const System.String _rcsid = "$Id: AsciiHelper.java,v 1.1 2001/06/14 21:19:58 pcharles Exp $";
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Mozilla Public License 1.1 (MPL 1.1)


Written By
Software Developer
Israel Israel
Works as a Network Engineer for a leading networking company.

Written By
United States United States
Entrepreneur and product developer with a wide range of technical and business experience.

Comments and Discussions