Amiga-C (153/157)

From:Herbert Klackl
Date:30 Sep 2001 at 23:27:44
Subject:[amiga-c] Speedup recognition of ip:port

Hi,

I'm trying to process a file which consists of lines with IP-addresses and
portnumber.

All I want to do is to check whether each IP-address:Port is available or not.

So, what I do is that for each line
a) I create a socket
b) fill a sockaddr_in structure with the appropriate data
c) connect to destination IP:Port
e) check whether it was successfull or not
f) close the socket
like in the following lines:

--- cut ---
/* create socket for connection with servent */
socketfd = socket(AF_INET, SOCK_STREAM, 0);

/* fill sockaddr_in struct for connection */
memset(&(dest_servent), 0x00, sizeof(dest_servent));
dest_servent.sin_family = AF_INET;
dest_servent.sin_port = htons(dest_servent_port);
dest_servent.sin_addr.s_addr = inet_addr(dest_servent_ip);

/* try to connect to servent */
retval = connect(socketfd, (struct sockaddr*)&dest_servent,
sizeof(struct sockaddr));

/* check whether successfull or not */
if (retval == -1) {
printf("...failed!\n");
} else {
printf("...ok!\n");
}

/* close socket */
CloseSocket(socketfd);
--- cut ---

The upper code works (of course the loop and reading of the data is missing).

However the problem is that - if a destination can not be reached - it takes
ages (5 to 30+ sec) until i get a response from connect.

Does anyone know a faster/more secure way to solve this problem?
After all, it is unacceptable for the user if he has to wait several minutes
to get about 4 connections from several dozens (or even hundreds) of lines.

BTW: I'm using the AmiTCP-SDK from Aminet for the networking routines. AFAIK
Miami and Genesis are AmiTCP compatible and therefore I can be sure to reach
the most user.

Bye Herby

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get your FREE VeriSign guide to security solutions for your web site: encrypting transactions, securing intranets, and more!
http://us.click.yahoo.com/UnN2wB/m5_CAA/yigFAA/dpFolB/TM
---------------------------------------------------------------------~->

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/