mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
ping: cleanup code
This commit is contained in:
@@ -179,14 +179,13 @@ int icmp_ping4(main_server_st * s, struct sockaddr_in *addr1)
|
||||
char packet1[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
|
||||
char buf1[64];
|
||||
time_t now;
|
||||
uint16_t id1, id2;
|
||||
uint16_t id1;
|
||||
unsigned gotreply = 0, unreachable = 0;
|
||||
|
||||
if (s->config->ping_leases == 0)
|
||||
return 0;
|
||||
|
||||
gnutls_rnd(GNUTLS_RND_NONCE, &id1, sizeof(id1));
|
||||
gnutls_rnd(GNUTLS_RND_NONCE, &id2, sizeof(id2));
|
||||
|
||||
pingsock = socket(AF_INET, SOCK_RAW, 1);
|
||||
if (pingsock == -1) {
|
||||
@@ -231,7 +230,7 @@ int icmp_ping4(main_server_st * s, struct sockaddr_in *addr1)
|
||||
#else
|
||||
pkt = (struct icmp *) (packet1 + ((packet1[0] & 0x0f) << 2)); /* skip ip hdr */
|
||||
#endif
|
||||
if (pkt->icmp_id == id1 || pkt->icmp_id == id2) {
|
||||
if (pkt->icmp_id == id1) {
|
||||
if (pkt->icmp_type == ICMP_ECHOREPLY)
|
||||
gotreply++;
|
||||
else if (pkt->icmp_type == ICMP_DEST_UNREACH)
|
||||
@@ -268,7 +267,7 @@ int icmp_ping6(main_server_st * s,
|
||||
int pingsock, c, e;
|
||||
int sockopt;
|
||||
char packet1[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
|
||||
uint16_t id1, id2;
|
||||
uint16_t id1;
|
||||
unsigned gotreply = 0, unreachable = 0;
|
||||
time_t now;
|
||||
|
||||
@@ -276,7 +275,6 @@ int icmp_ping6(main_server_st * s,
|
||||
return 0;
|
||||
|
||||
gnutls_rnd(GNUTLS_RND_NONCE, &id1, sizeof(id1));
|
||||
gnutls_rnd(GNUTLS_RND_NONCE, &id2, sizeof(id2));
|
||||
|
||||
pingsock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
|
||||
if (pingsock == -1) {
|
||||
@@ -320,7 +318,7 @@ int icmp_ping6(main_server_st * s,
|
||||
SA_IN_SIZE(sizeof(*addr1))) == 0) {
|
||||
|
||||
pkt = (struct icmp6_hdr *) packet1;
|
||||
if (pkt->icmp6_id == id1 || pkt->icmp6_id == id2) {
|
||||
if (pkt->icmp6_id == id1) {
|
||||
if (pkt->icmp6_type == ICMP6_ECHO_REPLY)
|
||||
gotreply++;
|
||||
else if (pkt->icmp6_type == ICMP_DEST_UNREACH)
|
||||
|
||||
Reference in New Issue
Block a user