public static EndPoint Create(this EndPoint thisObj, Internals.SocketAddress socketAddress) { AddressFamily family = socketAddress.Family; if (family != thisObj.AddressFamily) { throw new ArgumentException(SR.Format(SR.net_InvalidAddressFamily, family.ToString(), thisObj.GetType().FullName, thisObj.AddressFamily.ToString()), nameof(socketAddress)); } if (family == AddressFamily.InterNetwork || family == AddressFamily.InterNetworkV6) { if (socketAddress.Size < 8) { throw new ArgumentException(SR.Format(SR.net_InvalidSocketAddressSize, socketAddress.GetType().FullName, thisObj.GetType().FullName), nameof(socketAddress)); } return(socketAddress.GetIPEndPoint()); } else if (family == AddressFamily.Unknown) { return(thisObj); } System.Net.SocketAddress address = GetNetSocketAddress(socketAddress); return(thisObj.Create(address)); }
static int _m_Create(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); System.Net.EndPoint gen_to_be_invoked = (System.Net.EndPoint)translator.FastGetCSObj(L, 1); { System.Net.SocketAddress _socketAddress = (System.Net.SocketAddress)translator.GetObject(L, 2, typeof(System.Net.SocketAddress)); System.Net.EndPoint gen_ret = gen_to_be_invoked.Create( _socketAddress); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
/// <summary> /// Create <see cref="T:System.Net.SocketAddress"/> filling it with /// the contents of the specified buffer. /// </summary> public static System.Net.SocketAddress Factory_SocketAddress(System.Net.Sockets.AddressFamily af, byte[] buffer) { System.Net.SocketAddress sa = new System.Net.SocketAddress(af, buffer.Length); for (int i = 0; i < buffer.Length; ++i) { sa[i] = buffer[i]; }//foreach return(sa); }
private static System.Net.SocketAddress GetNetSocketAddress(Internals.SocketAddress address) { var result = new System.Net.SocketAddress(address.Family, address.Size); for (int index = 0; index < address.Size; index++) { result[index] = address[index]; } return result; }
private static System.Net.SocketAddress GetNetSocketAddress(Internals.SocketAddress address) { var result = new System.Net.SocketAddress(address.Family, address.Size); for (int index = 0; index < address.Size; index++) { result[index] = address[index]; } return(result); }
private static byte[] SocketAddressToArray(System.Net.SocketAddress socketAddress) { byte[] buffer = new byte[socketAddress.Size + 1]; buffer[0] = (byte)socketAddress.Family; for (int i = 1; i < buffer.Length; i++) { buffer[i] = socketAddress[i]; } return(buffer); }
private static byte[] SocketAddressToArray(System.Net.SocketAddress socketAddress) { byte[] buffer = new byte[socketAddress.Size]; buffer[0] = (byte)socketAddress.Family; System.Diagnostics.Debug.WriteLine(buffer[0]); for (int i = 1; i < buffer.Length; i++) { buffer[i] = socketAddress[i]; System.Diagnostics.Debug.WriteLine(buffer[i]); } return(buffer); }
public static Internals.SocketAddress Serialize(EndPoint endpoint) { Debug.Assert(!(endpoint is DnsEndPoint)); var ipEndPoint = endpoint as IPEndPoint; if (ipEndPoint != null) { return(new Internals.SocketAddress(ipEndPoint.Address, ipEndPoint.Port)); } System.Net.SocketAddress address = endpoint.Serialize(); return(GetInternalSocketAddress(address)); }
public InternetEndPoint(int port, System.Net.Sockets.AddressFamily addressFamily, System.Net.SocketAddress socketAddress, System.Net.Sockets.ProtocolType protocolType, System.Net.Sockets.ProtocolFamily protocolFamily) : this(port, addressFamily, protocolType, protocolFamily) { if (socketAddress == null) { throw new System.ArgumentNullException("socketAddress"); } if (false.Equals(socketAddress.Family == AddressFamily)) { throw new System.InvalidOperationException("AddressFamily must match the socketAddress.Family"); } SocketAddress = socketAddress; }
static void Main(string[] args) { int Port = 5150; try { System.Net.IPAddress IPAddress; IPAddress = System.Net.IPAddress.Any; System.Net.IPEndPoint LocalEP = new System.Net.IPEndPoint(IPAddress, Port); System.Net.Sockets.Socket ReceivingSocket = new System.Net.Sockets.Socket( System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp); ReceivingSocket.Bind(LocalEP); System.Console.WriteLine("Waiting for data..."); byte [] buffer = new byte[1024]; System.Net.IPAddress RemoteIPAddress = System.Net.IPAddress.Any; System.Net.IPEndPoint RemoteIPEndPoint = new System.Net.IPEndPoint( RemoteIPAddress, 0); System.Net.SocketAddress RemoteAddress = new System.Net.SocketAddress( System.Net.Sockets.AddressFamily.InterNetwork); System.Net.EndPoint RefRemoteEP = RemoteIPEndPoint.Create(RemoteAddress); int BytesReceived = ReceivingSocket.ReceiveFrom(buffer, ref RefRemoteEP); System.Console.WriteLine("Successfully received " + BytesReceived.ToString() + " byte(s) from " + RefRemoteEP.ToString()); ReceivingSocket.Close(); } catch (System.Net.Sockets.SocketException err) { Console.WriteLine("Error: " + err.Message); } }
public void CreateA() { byte[] buffer = { /* AF */ 26, 0, /* ID */ 1, 2, 3, 4, /* SN */ (byte)'S', (byte)'v',(byte)'c', (byte)'N',(byte)'a', (byte)'m', (byte)'e',(byte)'1', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* struct alignment pad */ (byte)'!' }; System.Net.SocketAddress sa = Factory_SocketAddressForIrDA(buffer); IrDAEndPoint ep = (IrDAEndPoint) new IrDAEndPoint(Values.AddressOne, "x").Create(sa); // Assert.AreEqual(new byte[] { 1, 2, 3, 4 }, ep.Address.ToByteArray()); Assert.AreEqual("SvcName1", ep.ServiceName); }
// Should this fail? The ServiceName char[] is _not_ null-terminated!!! public void CreateBNoPadByte() { byte[] buffer = { /* AF */ 26, 0, /* ID */ 1, 2, 3, 4, /* SN */ (byte)'a', (byte)'a',(byte)'a', (byte)'a',(byte)'a', (byte)'a', (byte)'a',(byte)'a', (byte)'a',(byte)'a', (byte)'a', (byte)'a',(byte)'a', (byte)'a',(byte)'a', (byte)'a', (byte)'a',(byte)'a', (byte)'a',(byte)'a', (byte)'a', (byte)'a',(byte)'a', (byte)'a',(byte)'a', /* No padding byte. */ }; System.Net.SocketAddress sa = Factory_SocketAddressForIrDA(buffer); IrDAEndPoint ep = (IrDAEndPoint) new IrDAEndPoint(Values.AddressOne, "x").Create(sa); // Assert.AreEqual(new byte[] { 1, 2, 3, 4 }, ep.Address.ToByteArray()); Assert.AreEqual(new String('a', 24), ep.ServiceName); }
public static bool _Create_System_Net_EndPoint_System_Net_SocketAddress( ) { //Parameters System.Net.SocketAddress socketAddress = null; //ReturnType/Value System.Net.EndPoint returnVal_Real = null; System.Net.EndPoint returnVal_Intercepted = null; //Exception Exception exception_Real = null; Exception exception_Intercepted = null; InterceptionMaintenance.disableInterception( ); try { returnValue_Real = System.Net.EndPoint.Create(socketAddress); } catch (Exception e) { exception_Real = e; } InterceptionMaintenance.enableInterception( ); try { returnValue_Intercepted = System.Net.EndPoint.Create(socketAddress); } catch (Exception e) { exception_Intercepted = e; } Return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted)); }
public static bool _Serialize_System_Net_IPEndPoint( ) { //Parameters //ReturnType/Value System.Net.SocketAddress returnVal_Real = null; System.Net.SocketAddress returnVal_Intercepted = null; //Exception Exception exception_Real = null; Exception exception_Intercepted = null; InterceptionMaintenance.disableInterception( ); try { returnValue_Real = System.Net.IPEndPoint.Serialize(); } catch (Exception e) { exception_Real = e; } InterceptionMaintenance.enableInterception( ); try { returnValue_Intercepted = System.Net.IPEndPoint.Serialize(); } catch (Exception e) { exception_Intercepted = e; } Return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted)); }
static int _m_Serialize(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); System.Net.IPEndPoint gen_to_be_invoked = (System.Net.IPEndPoint)translator.FastGetCSObj(L, 1); { System.Net.SocketAddress gen_ret = gen_to_be_invoked.Serialize( ); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
public override System.Net.SocketAddress Serialize() { System.Net.SocketAddress sa = new System.Net.SocketAddress(AddressFamily.Unspecified, saLength); // AddressFamily sa[0] = 32; // copy in the remote bt address for (int i = 0; i < 8; i++) { sa[addressOffset + i] = deviceAddress[i]; } // copy in the guid of the service we want to connect with byte[] guidArray = serviceGuid.ToByteArray(); for (int i = 0; i < guidArray.Length; i++) { sa[guidOffset + i] = guidArray[i]; } return(sa); }
public override System.Net.EndPoint Create(System.Net.SocketAddress socketAddress) { // device Address byte[] addr = new byte[8]; for (int i = 0; i < 8; i++) { addr[i] = socketAddress[addressOffset + i]; } // guid byte[] serviceGuid = new byte[16]; for (int i = 0; i < 16; i++) { serviceGuid[i] = socketAddress[guidOffset + i]; } byte[] deviceAddr = addr; Guid g = new Guid(serviceGuid); // port number byte[] portNumArray = new byte[4]; for (int i = 0; i < 4; i++) { portNumArray[i] = socketAddress[channelOffset + i]; } int portNum = BitConverter.ToInt32(portNumArray, 0); return(new BluetoothEndPoint(deviceAddr, g, portNum)); }
public override System.Net.EndPoint Create(System.Net.SocketAddress socketAddress) { throw null; }
public virtual System.Net.EndPoint Create(System.Net.SocketAddress socketAddress) { throw null; }
public override System.Net.SocketAddress Serialize() { System.Net.SocketAddress sa = new System.Net.SocketAddress(AddressFamily.Unspecified, saLength); // AddressFamily sa[0] = 32; // copy in the remote bt address for (int i = 0; i < 8; i++) { sa[addressOffset + i] = deviceAddress[i]; } // copy in the guid of the service we want to connect with byte[] guidArray = serviceGuid.ToByteArray(); for (int i = 0; i < guidArray.Length; i++) { sa[guidOffset + i] = guidArray[i]; } return sa; }
public static void AssertAreEqualSocketAddressBuffer(byte[] expectedSockaddr, System.Net.SocketAddress sa) { byte[] result = new byte[sa.Size]; for (int i = 0; i < result.Length; ++i) { result[i] = sa[i]; } Assert.AreEqual(expectedSockaddr, result); }
public override System.Net.EndPoint Create(System.Net.SocketAddress socketAddress) { return(default(System.Net.EndPoint)); }
public virtual System.Net.EndPoint Create(System.Net.SocketAddress socketAddress) { return(default(System.Net.EndPoint)); }