kopia lustrzana https://github.com/espressif/esp-idf
bugfix for add ttl for ping socket
rodzic
cd55014c33
commit
b569f4069a
|
@ -1,16 +1,8 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "esp_ping.h"
|
||||
|
@ -25,6 +17,7 @@ typedef struct _ping_option {
|
|||
size_t ping_data_len;
|
||||
uint16_t ping_id;
|
||||
u8_t ping_tos;
|
||||
u8_t ping_ttl;
|
||||
esp_ping_found_fn ping_res_fn;
|
||||
esp_ping_found ping_res;
|
||||
void *ping_reserve;
|
||||
|
|
|
@ -271,6 +271,9 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
|
|||
/* set tos */
|
||||
setsockopt(ep->sock, IPPROTO_IP, IP_TOS, &config->tos, sizeof(config->tos));
|
||||
|
||||
/* set ttl */
|
||||
setsockopt(ep->sock, IPPROTO_IP, IP_TTL, &config->ttl, sizeof(config->ttl));
|
||||
|
||||
/* set socket address */
|
||||
if (IP_IS_V4(&config->target_addr)) {
|
||||
struct sockaddr_in *to4 = (struct sockaddr_in *)&ep->target_addr;
|
||||
|
|
|
@ -1,16 +1,8 @@
|
|||
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -67,7 +59,8 @@ typedef struct {
|
|||
uint32_t interval_ms; /*!< Milliseconds between each ping procedure */
|
||||
uint32_t timeout_ms; /*!< Timeout value (in milliseconds) of each ping procedure */
|
||||
uint32_t data_size; /*!< Size of the data next to ICMP packet header */
|
||||
uint8_t tos; /*!< Type of Service, a field specified in the IP header */
|
||||
int tos; /*!< Type of Service, a field specified in the IP header */
|
||||
int ttl; /*!< Time to Live,a field specified in the IP header */
|
||||
ip_addr_t target_addr; /*!< Target IP address, either IPv4 or IPv6 */
|
||||
uint32_t task_stack_size; /*!< Stack size of internal ping task */
|
||||
uint32_t task_prio; /*!< Priority of internal ping task */
|
||||
|
@ -85,6 +78,7 @@ typedef struct {
|
|||
.timeout_ms = 1000, \
|
||||
.data_size = 64, \
|
||||
.tos = 0, \
|
||||
.ttl = IP_DEFAULT_TTL, \
|
||||
.target_addr = *(IP_ANY_TYPE), \
|
||||
.task_stack_size = 2048, \
|
||||
.task_prio = 2, \
|
||||
|
|
|
@ -73,6 +73,7 @@ static struct {
|
|||
struct arg_int *data_size;
|
||||
struct arg_int *count;
|
||||
struct arg_int *tos;
|
||||
struct arg_int *ttl;
|
||||
struct arg_str *host;
|
||||
struct arg_end *end;
|
||||
} ping_args;
|
||||
|
@ -107,6 +108,10 @@ static int do_ping_cmd(int argc, char **argv)
|
|||
config.tos = (uint32_t)(ping_args.tos->ival[0]);
|
||||
}
|
||||
|
||||
if (ping_args.ttl->count > 0) {
|
||||
config.ttl = (uint32_t)(ping_args.ttl->ival[0]);
|
||||
}
|
||||
|
||||
// parse IP address
|
||||
struct sockaddr_in6 sock_addr6;
|
||||
ip_addr_t target_addr;
|
||||
|
@ -156,6 +161,7 @@ static void register_ping(void)
|
|||
ping_args.data_size = arg_int0("s", "size", "<n>", "Specify the number of data bytes to be sent");
|
||||
ping_args.count = arg_int0("c", "count", "<n>", "Stop after sending count packets");
|
||||
ping_args.tos = arg_int0("Q", "tos", "<n>", "Set Type of Service related bits in IP datagrams");
|
||||
ping_args.ttl = arg_int0("T", "ttl", "<n>", "Set Time to Live related bits in IP datagrams");
|
||||
ping_args.host = arg_str1(NULL, NULL, "<host>", "Host address");
|
||||
ping_args.end = arg_end(1);
|
||||
const esp_console_cmd_t ping_cmd = {
|
||||
|
|
|
@ -874,13 +874,11 @@ components/linux/include/sys/queue.h
|
|||
components/log/esp_log_private.h
|
||||
components/log/host_test/log_test/main/log_test.cpp
|
||||
components/log/log_linux.c
|
||||
components/lwip/apps/ping/esp_ping.c
|
||||
components/lwip/apps/ping/ping.c
|
||||
components/lwip/apps/sntp/sntp.c
|
||||
components/lwip/include/apps/dhcpserver/dhcpserver_options.h
|
||||
components/lwip/include/apps/esp_ping.h
|
||||
components/lwip/include/apps/ping/ping.h
|
||||
components/lwip/include/apps/ping/ping_sock.h
|
||||
components/lwip/include/apps/sntp/sntp.h
|
||||
components/lwip/port/esp32/debug/lwip_debug.c
|
||||
components/lwip/port/esp32/freertos/sys_arch.c
|
||||
|
|
Ładowanie…
Reference in New Issue