Link to home
Start Free TrialLog in
Avatar of softbreeze
softbreezeFlag for United States of America

asked on

WSAAdressToString example Delphi code needed

I have written a function to gather network adapter information using the GetAdaptersAddresses API call. One of the member fields of the IP_ADAPTER_ADDRESSES structures that are returned is called 'FirstUniCastAddress' of type PIP_ADAPTER_UNICAST_ADDRESS. Each IP_ADAPTER_UNICAST_ADDRESS structure contains a member call 'Address' of type SOCKET_ADDRESS. I'm trying to use the WSAAddressToString (Winsock2) function to return the IPv4 or IPv6 address in a string. Normally I would only worry about the IPv4 addresses and would use the inet_itoa() function. However it doesn't support IPv6. I can't seem to get the parameters right for this call and I am looking for a example of Delphi code or help in identifying my mistake.

Here is what I have been doing, that gets an error during compile. It doesn't like the arguments I'm passing to the WSAAddressToString function. It is the first argument that is giving me the problem. I think.

function My_WSAAddressToString(SA: SOCKET_ADDRESS): String;
var
   WSAData:    TWSAData;
   Rtn:              Integer;
   PBuf:           PWideChar;
   BufLen:       DWord;
begin
     WSAStartup($202,WSAData);
     Result := '';
     GetMem(PBuf,64);
     BufLen := 64;
     Rtn := WSAAddressToString(SA.lpSockaddr,                    <--- Compile error?
                                                     SA.iSockaddrLength,
                                                     nil,
                                                     PBuf,
                                                    BufLen);
     if (Rtn <> SOCKET_ERROR) then
       Result := PBuf;
     WSACleanup;
end;


Thanks in advance for any help on this.
Ken
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of softbreeze

ASKER

Found a working example at http://www.magsys.co.uk/delphi/
You get the points for at least responding. Thanks