restart work on ipv4/ipv6 unification

pull/89/merge
David Schweikert 8 years ago
parent 8481d7432a
commit e71164de22

@ -1574,7 +1574,7 @@ int send_ping( int s, HOST_ENTRY *h )
return(ret); return(ret);
} }
int wait_on_socket(int socket, struct timeval *timeout) int socket_can_read(int socket, struct timeval *timeout)
{ {
int nfound; int nfound;
fd_set readset, writeset; fd_set readset, writeset;
@ -1601,8 +1601,7 @@ select_again:
return 1; return 1;
} }
int receive_reply(int socket, int receive_packet(int socket,
struct timeval *timeout,
struct timeval *reply_timestamp, struct timeval *reply_timestamp,
struct sockaddr *reply_src_addr, struct sockaddr *reply_src_addr,
size_t reply_src_addr_len, size_t reply_src_addr_len,
@ -1610,14 +1609,6 @@ int receive_reply(int socket,
size_t reply_buf_len) size_t reply_buf_len)
{ {
int recv_len; int recv_len;
// Wait for input on the socket
if(timeout && !wait_on_socket(socket, timeout)) {
return 0; /* timeout */
}
// Receive data
{
static unsigned char msg_control[40]; static unsigned char msg_control[40];
struct iovec msg_iov = { struct iovec msg_iov = {
reply_buf, reply_buf,
@ -1658,7 +1649,14 @@ int receive_reply(int socket,
if(! timestamp_set) { if(! timestamp_set) {
gettimeofday(reply_timestamp, NULL); gettimeofday(reply_timestamp, NULL);
} }
#if defined( DEBUG ) || defined( _DEBUG )
if( randomly_lose_flag )
{
if( ( random() & 0x07 ) <= lose_factor )
return 0;
} }
#endif
return recv_len; return recv_len;
} }
@ -1681,10 +1679,9 @@ int wait_for_reply(long wait_time)
struct ip *ip; struct ip *ip;
#endif #endif
// receive packet // Wait for the socket to become ready
{
struct timeval to;
if(wait_time) { if(wait_time) {
struct timeval to;
if(wait_time < 100000) { if(wait_time < 100000) {
to.tv_sec = 0; to.tv_sec = 0;
to.tv_usec = wait_time * 10; to.tv_usec = wait_time * 10;
@ -1693,10 +1690,14 @@ int wait_for_reply(long wait_time)
to.tv_sec = wait_time / 100000 ; to.tv_sec = wait_time / 100000 ;
to.tv_usec = (wait_time % 100000) * 10 ; to.tv_usec = (wait_time % 100000) * 10 ;
} }
if(!socket_can_read(s, &to)) {
return 0; /* timeout */
}
} }
result = receive_reply(s, // socket // Receive packet
wait_time ? &to : NULL, // timeout result = receive_packet(s, // socket
&recv_time, // reply_timestamp &recv_time, // reply_timestamp
(struct sockaddr *) &response_addr, // reply_src_addr (struct sockaddr *) &response_addr, // reply_src_addr
sizeof(response_addr), // reply_src_addr_len sizeof(response_addr), // reply_src_addr_len
@ -1707,16 +1708,20 @@ int wait_for_reply(long wait_time)
if(result <= 0) { if(result <= 0) {
return 0; return 0;
} }
}
#if defined( DEBUG ) || defined( _DEBUG ) // Process ICMP packet and retrieve id/seq
if( randomly_lose_flag ) // unsigned short icmp_id;
{ // unsigned short icmp_seq
if( ( random() & 0x07 ) <= lose_factor ) //#ifndef IPV6
return 0; // if(!process_icmp_ipv4(response_addr, sizeof(response_addr), buffer, sizeof(buffer),
// &icmp_id, &icmp_seq))
} //#else
#endif // if(!process_icmp_ipv6(response_addr, sizeof(response_addr), buffer, sizeof(buffer)
// &icmp_id, &icmp_seq))
//#endif
// {
// return(1);
// }
#ifndef IPV6 #ifndef IPV6
ip = ( struct ip* )buffer; ip = ( struct ip* )buffer;

Loading…
Cancel
Save