Everything is fine until the "connect" line whereupon I get a return value
of SOCKET_ERROR - using WSAGetLastError returns 0.
The same code (allowing for syntax) works very well in borland C 5.02.
Any ideas? (sorry the formatting has gone a bit wrong below)
Thanks in advance.
function smtp_connect(server : PChar) : Integer;
var
wsadata : TWSADATA;
Hostent : PHostEnt;
nb : LongInt;
ok : Integer;
server_addr : TSockAddrIn;
begin
if (WSAStartup($0101, wsadata) <> 0) then
begin
ShowMessage('Unable to open WINSOCK');
Exit;
end;
s := socket(AF_INET, SOCK_STREAM, 0);
if (s = INVALID_SOCKET) then
begin
ShowMessage('Unable to create socket');
Exit;
end;
nb := 1;
ioctlsocket(s, FIONBIO, nb);
Hostent := gethostbyname(server);
if Hostent = nil then
begin
ShowMessage('Host not found');
Exit;
end;
server_addr.sin_family := AF_INET;
server_addr.sin_port := htons (25);
with server_addr.sin_addr.S_un_b, Hostent^ do
begin
s_b1 := h_addr^[0];
s_b2 := h_addr^[1];
s_b3 := h_addr^[2];
s_b4 := h_addr^[3];
end;
ok := connect(s, server_addr, SizeOf(server_addr));
if (ok <> 0) then
begin
ShowMessage('Connect Failed (' + IntToStr(ok) + ')');
Result := -1;
if (ok = SOCKET_ERROR) then ShowMessage('Socket Error');
end
else Result := 0;
end;
Where the socket is described as follows:
var
s : TSocket;
The usual cause of incorrect WSAGetLastError() results is that you've called
some other API function between the Winsock function and the call to
WSAGetLastError. In Win32, WSAGetLastError is an alias for GetLastError.
Alun.
~~~~
[Please don't email posters, if a Usenet response is appropriate.]
--
Texas Imperial Software | Try WFTPD, the Windows FTP Server. Find us at
1602 Harvest Moon Place | http://www.wftpd.com or email al...@texis.com
Cedar Park TX 78613-1419 | VISA/MC accepted. NT-based sites, be sure to
Fax/Voice +1(512)258-9858 | read details of WFTPD Pro for NT.