|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
TIME_WAIT state of the port problem A simple description :
Ftp客户端 access to a document distributed to receive a fixed socket terminal port (1401) to receive documents and preserve the local paper.
Question :
The first performance is normal, but if consecutive output will be as follows (part)
Ret_buffer = 200 PORT command successful.
LEAVES OF 13 SPECIES OF LAURACEAE here in a few seconds, such as the following output */
No data connection ret_buffer =425
: A system call received a parameter that is not valid.
Second performance, the port still TIME_WAIT 1401, but after using the SO_REUSEADDR option still exists, the problem does not seem to achieve the purpose of reuse |
TIME_WAIT state of the port problem SO_REUSEADDR must connect installed before use or bind |
TIME_WAIT state of the port problem Socket after I set up this option for the port, good feelings do not know why this |
TIME_WAIT state of the port problem SO_REUSEPORT look at the options you set up. |
TIME_WAIT state of the port problem Reuse seems to be only port terminal services, client reuse of no significance. |
TIME_WAIT state of the port problem SO_REUSEADD server reference book can be used to stop immediately after the restart, but I absolutely do not understand the server and client (server than can be seen as client端 services? )
Code stickers, and everybody help us to see ^_^
#include "Basic system data types */ sys/types.h>; LEAVES OF 13 SPECIES OF LAURACEAE
#include "Sys/socket.h>; LEAVES OF 13 SPECIES OF LAURACEAE basic socket definitions */
#include "Sys/time.h>; LEAVES OF 13 SPECIES OF LAURACEAE timeval{} for select () */
#include "Time.h>; LEAVES OF 13 SPECIES OF LAURACEAE timespec{} for pselect () */
#include "Netinet/in.h>; LEAVES OF 13 SPECIES OF LAURACEAE sockaddr_in{} and other Internet defns */
#include "Arpa/inet.h>; LEAVES OF 13 SPECIES OF LAURACEAE inet (3) functions */
#include "Errno.h>;
#include "Fcntl.h>; LEAVES OF 13 SPECIES OF LAURACEAE for nonblocking */
#include "Netdb.h>;
#include "Signal.h>;
#include "Stdio.h>;
#include "Stdlib.h>;
#include "String.h>;
#include "Sys/stat.h>; LEAVES OF 13 SPECIES OF LAURACEAE for S_xxx file mode constants */
#include "Sys/uio.h>; LEAVES OF 13 SPECIES OF LAURACEAE for iovec{} and readv/writev */
#include "Unistd.h>;
#include "Sys/wait.h>;
#include "Sys/un.h>; LEAVES OF 13 SPECIES OF LAURACEAE for Unix domain sockets */
Void ftp_send_cmd (int, char*);
Void build_data_socket (int *);
Void main (int argv, char ** argc)
{
Struct sockaddr_in addr_ser;
Int fd_socket, data_socket;
Char buffer[10230];
Int i_count ≤
FILE* fp, *getfp;
Int datafd;
/*opp Addr*/
Bzero (&addr_ser, sizeof (addr_ser));
Addr_ser.sin_family = AF_INET;
Addr_ser.sin_port = htons (21);
Inet_pton (AF_INET, argc[1], & (addr_ser.sin_addr));
/*cmd Sock*/
Fd_socket = socket (AF_INET, SOCK_STREAM, 0);
If (fd_socket "0)
{
Printf ( "socket = %s\n erronea", strerror (errno));
Exit (-1);
}
If (setsockopt (fd_socket, SOL_SOCKET, SO_REUSEADDR, (char*) (&i_count), sizeof (int)) "0)
{
Printf ( "erroneamente = %s\n", strerror (errno));
Exit (0);
}
/*if (Setsockopt (fd_socket, SOL_SOCKET, SO_REUSEPORT, (char*) (&i_count), sizeof (int)) "0)
{
Printf ( "erroneamente = %s\n", strerror (errno));
Exit (0);
}*/
LEAVES OF 13 SPECIES OF LAURACEAE connecting server */
If (connect (fd_socket, (struct sockaddr*) &addr_ser, sizeof (addr_ser)) "0)
{
Printf ( "connect erroneamente = %s\n", strerror (errno));
Exit (-1);
}
I_count = read (fd_socket, buffer, 10240);
If (i_count "0)
{
Printf ( "read = %s\n erronea", strerror (errno));
Exit (-1);
}
LOCAL DATA SOCKET*/ /*BUILD
Build_data_socket (&data_socket);
LEAVES OF 13 SPECIES OF LAURACEAE order */
Ftp_send_cmd (fd_socket "user bill2");
Ftp_send_cmd (fd_socket "pass bill2");
Ftp_send_cmd (fd_socket "type I");
Ftp_send_cmd (fd_socket "CWD /test/test/");
Ftp_send_cmd (fd_socket "PORT 99,99,1,13,4,17");
Ftp_send_cmd (fd_socket "retr /test/test/yy.c");
Datafd= accept (data_socket, NULL, 0);
Getfp = fdopen (datafd, "rb");
Fp = fopen ( "yy.c", "wb");
Do
{
I_count = fread (buffer, sizeof (char), 1024, getfp);
Fwrite (buffer, sizeof (char), i_count, fp);
}while (I_count ====== 1024);
Fclose (getfp);
Fclose (fp);
Close (data_socket);
Close (fd_socket);
Close (datafd);
}
LEAVES OF 13 SPECIES OF LAURACEAE sent ftp order */
Void ftp_send_cmd (fd_cmdsock int, char * cmd)
{
Char ret_buffer[10240];
Int read_len;
LEAVES OF 13 SPECIES OF LAURACEAE sent orders */
Sprintf (ret_buffer "%s\r\n", cmd);
If (strlen (ret_buffer)> write (fd_cmdsock, ret_buffer, strlen (ret_buffer)))
{
Printf ( "write = %s\n erronea", strerror (errno));
Exit (-1);
}
Do
{
LEAVES OF 13 SPECIES OF LAURACEAE take orders to return to duty */
If ((read_len = recv (fd_cmdsock, ret_buffer, 10240,0)) "0)
{
Printf ( "read = %s\n erronea", strerror (errno));
Exit (-1);
}
Ret_buffer[read_len] = '\0';
Printf ( "ret_buffer =%s" ret_buffer);
}while (Ret_buffer[read_len-3]> '. ');
}
LEAVES OF 13 SPECIES OF LAURACEAE for receiving data socket*/
Void build_data_socket (int *data_socket)
{
Struct sockaddr_in addr_local;
Int i_count ≤
Fd_set socketset;
/*local Addr*/
Bzero (&addr_local, sizeof (addr_local));
Addr_local.sin_family = AF_INET;
Addr_local.sin_port = htons (1041);
Addr_local.sin_addr.s_addr = htonl (INADDR_ANY);
/*date Sock*/
*data_socket = Socket (AF_INET, SOCK_STREAM, 0);
If (*data_socket "0)
{
Printf ( "socket = %s\n erronea", strerror (errno));
Exit (-1);
}
If (setsockopt (*data_socket, SOL_SOCKET, SO_REUSEADDR, &i_count, sizeof (int)) "0)
{
Printf ( "erroneamente = %s\n", strerror (errno));
Exit (0);
}
If (bind (*data_socket, (struct sockaddr *) &addr_local, sizeof (addr_local)) "0)
{
Printf ( "bind erroneamente = %s\n", strerror (errno));
Exit (-1);
}
If (listen and (*data_socket, 10) "0)
{
Printf ( "listen and erroneamente = %s\n", strerror (errno));
Exit (-1);
}
} |
TIME_WAIT state of the port problem Sniffers are used for a look at what further analysis bars |
| |