|
楼主 |
发表于 2004-3-8 18:32:58
|
显示全部楼层
下面是我的代码:
请帮忙指出错误
[code:1]
#include "ftpserch.h"
int main(int argc, char *argv[])
{
int sockfd;
int len;
struct in_addr address1;
struct in_addr address2;
struct sockaddr_in tmp;
int result;
if(argc != 3){
printf("usage:command IP1 IP2!!\n");
exit(1);
}
if( ((address1.s_addr = inet_addr(argv[1])) == -1) || ((address2.s_addr = inet_addr(argv[2])) == -1) ){
printf("IP error!!\n");
exit(2);
}
if(strcmp(argv[1],argv[2]) > 0 ){
printf("IP1 should less than IP2!!\n");
exit(3);
}
for(;address1.s_addr <= address2.s_addr;address1.s_addr++){
sockfd = socket(AF_INET,SOCK_STREAM,0);
tmp.sin_family = AF_INET;
tmp.sin_port = htons(21);
tmp.sin_addr.s_addr = address1.s_addr;
len = sizeof(tmp);
result = connect(sockfd,(struct sockaddr *)&tmp,len);
if(result != -1){
printf("%s\n",inet_ntoa(tmp.sin_addr));
}
close(sockfd);
}
exit(0);
}
[/code:1] |
|