Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C#

Network Stuff (easy socket v3)

Rate me:
Please Sign up or sign in to vote.
4.87/5 (52 votes)
2 Jun 2005 215.9K   6.1K   137  
A class with event handlers for TCP, UDP or ICMP sockets; includes ping, traceroute, whois, ARP, and IPHelper functions and raw packets forging/ capturing.
/*
Copyright (C) 2004 Jacquelin POTIER <jacquelin.potier@free.fr>
Dynamic aspect ratio code Copyright (C) 2004 Jacquelin POTIER <jacquelin.potier@free.fr>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
using System;
using System.Runtime.InteropServices;

    /// <summary>
    /// Summary description for API_error.
    /// </summary>
    public class API_error
    {
        private const int FORMAT_MESSAGE_FROM_SYSTEM  = 0x00001000;
        [ DllImport( "kernel32" ,SetLastError=true)]
        private static extern UInt32 FormatMessage( UInt32 flags, IntPtr source, UInt32 messageId,
            UInt32 languageId, System.Text.StringBuilder buffer, UInt32 size, IntPtr arguments ); 


        public static string GetAPIErrorMessageDescription(UInt32 ApiErrNumber ) 
        {
            System.Text.StringBuilder sError = new System.Text.StringBuilder(512); 
            UInt32 lErrorMessageLength; 
            lErrorMessageLength = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,(IntPtr)0, ApiErrNumber, 0, sError, (UInt32)sError.Capacity, (IntPtr)0) ;
            
            if(lErrorMessageLength > 0)
            { 
                string strgError = sError.ToString();
                strgError=strgError.Substring(0,strgError.Length-2);
                return strgError+" ("+ApiErrNumber.ToString()+")";
            }
            return "none";

        }
        [DllImport("kernel32",EntryPoint="GetLastError",SetLastError=true)]
        public static extern uint GetLastError();
    }

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
France France

Comments and Discussions