Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SendTo (ws2_32)
 
.

C# Signature:

[DllImport("ws2_32.dll", EntryPoint="sendto")]

public static extern int SendTo (IntPtr Socket, IntPtr buff, int len, SendDataFlags flags, ref SockAddr To, int tomlen);

VB Signature:

User-Defined Types:

    [Flags]
    public enum SendDataFlags
    {
    /// <summary></summary>
    None = 0,
    /// <summary>    Specifies that the data should not be subject to routing. A Windows Sockets service provider can choose to ignore this flag</summary>
    DontRoute = 1,
    /// <summary>Sends OOB data (stream-style socket such as SOCK_STREAM only)</summary>
    OOB = 2
    }

    /// <summary>Структура адреса для сокета</summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct SockAddr
    {
    /// <summary>Семейство протоколов</summary>
    public short Family;
    /// <summary>Номер порта для сокета</summary>
    public ushort Port;
    /// <summary>Локальный IP адрес сокета</summary>
    public AddressIP4 IPAddress;
    /// <summary>8 байт для выравнивания структуры</summary>
    private Int64 Zero;

    public SockAddr (short Family, ushort Port, AddressIP4 IP)
    { this.Family = Family; this.Port = Port; this.IPAddress = IP; this.Zero = 0; }
    }

    /// <summary>IP адресс</summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct AddressIP4
    {
    /// <summary>Первый байт IP адреса</summary>
    public byte a1;
    /// <summary>Второй байт IP адреса</summary>
    public byte a2;
    /// <summary>Третий байт IP адреса</summary>
    public byte a3;
    /// <summary>Четвертый байт IP адреса</summary>
    public byte a4;

    /// <summary>Широковещательный IP адрес</summary>
    public static AddressIP4 Broadcast { get { return new AddressIP4 (255,255,255,255); } }
    /// <summary>Любой IP адрес</summary>
    public static AddressIP4 AnyAddress { get { return new AddressIP4 (0,0,0,0); } }
    /// <summary>IP адрес локального хоста</summary>
    public static AddressIP4 Loopback { get { return new AddressIP4 (127,0,0,1); } }

    public AddressIP4 (byte a1, byte a2, byte a3, byte a4)
    { this.a1 = a1; this.a2 = a2; this.a3 = a3; this.a4 = a4; }
    }

Alternative Managed API:

System.Net.Sockets.Socket (class) Socket.SendTo () - better to use It))

Notes:

Return Value

English:

If no error occurs, sendto returns the total number of bytes sent, which can be less than the number indicated by len. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.

Russian:

Если возвращенное значение меньше чем len, то функция завершилась ошибкой, код которой вы можете узнав вызвав

WSAGetLastError.

Tips & Tricks:

Please add some!

Sample Code:

Фиг вам..

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions