I tryed to convert the ConnectToAddress(IPAddress, Port) to allow IPv6 adr. My problem is, I have to create a ipv6 adrsocket-struct.
Code:
/**************************************************************
connect to a IPv6
***************************************************************
*/
ConnectToAddress(IPAddress, Port){
VarSetCapacity(wsaData, 32) ; The struct is only about 14 in size, so 32 is conservative.
;ipv6 requires wsock 2.2
WSOCK_20 := 0x0002 ;wsock 2.0
WSOCK_22 := 0x0202 ;wsock 2.2
result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0202, "UInt", &wsaData) ; Request Winsock 2.0 (0x0202)
; Since WSAStartup() will likely be the first Winsock function called by this script,
; check ErrorLevel to see if the OS has Winsock 2.2 available:
if (ErrorLevel){
MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required.
return -1
}
if (result){ ; Non-zero, which means it failed (most Winsock functions return 0 upon success).
MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
AF_INET := 2 ;for IPv4
AF_INET6 := 23 ;for IPv6
SOCK_STREAM := 1
IPPROTO_TCP := 6
socket := DllCall("Ws2_32\socket", "Int", AF_INET6, "Int", SOCK_STREAM, "Int", IPPROTO_TCP)
if socket = -1
{
MsgBox % "socket() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
;...until here it works, but now I need the sockaddr_in6 Data-struct.
/* struct def postet by Lexicos
typedef struct sockaddr_in6 {
ADDRESS_FAMILY sin6_family; // AF_INET6.
USHORT sin6_port; // Transport level port number.
ULONG sin6_flowinfo; // IPv6 flow information.
IN6_ADDR sin6_addr; // IPv6 address.
union {
ULONG sin6_scope_id; // Set of interfaces for a scope.
SCOPE_ID sin6_scope_struct;
};
} SOCKADDR_IN6_LH, *PSOCKADDR_IN6_LH, FAR *LPSOCKADDR_IN6_LH;
typedef struct in6_addr {
union {
UCHAR Byte[16];
USHORT Word[8];
} u;
} IN6_ADDR, *PIN6_ADDR, FAR *LPIN6_ADDR;
*/
/* THIS IS IPv4 sockadr Struct
; Prepare for connection:
SizeOfSocketAddress = 16
VarSetCapacity(SocketAddress, SizeOfSocketAddress)
InsertInteger(2, SocketAddress, 0, AF_INET) ; sin_family
InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2) ; sin_port
InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), SocketAddress, 4, 4) ; sin_addr.s_addr
*/
; Attempt connection:
if DllCall("Ws2_32\connect", "UInt", socket, "UInt", &SocketAddress, "Int", SizeOfSocketAddress)
{
MsgBox % "connect() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError") . "?"
return -1
}
return socket ; Indicate success by returning a valid socket ID rather than -1.
}
I tried a bit, but I doesnt work. So, is there a struct-pro here, who can help me to create this ipv6-struct?
greets
IsNull
EDIT:
Maby this could be of interest:
http://msdn.microsoft.com/en-us/library/ms737937(VS.85).aspx
WSAConnectByName does include the following steps:
Quote:
Resolve a hostname to a set of IP addresses.
For each IP address:
Create a socket of the appropriate address family.
Attempts to connect to the remote IP address. If the connection was successful, it returns; otherwise the next remote IP address for the host is tried
..so we can maby make this client/server script more simple.