From 0eb8d19e822b2c4dfbe8c5faf4c76a194b6cc4c2 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 8 Aug 2017 11:37:08 +0200 Subject: [PATCH] Move several port number #defines to iana.h --- src/apps/mdns/mdns.c | 10 +++++----- src/apps/netbiosns/netbiosns.c | 6 ++---- src/apps/snmp/snmp_msg.h | 11 ----------- src/apps/snmp/snmp_netconn.c | 5 +++-- src/apps/snmp/snmp_raw.c | 5 +++-- src/apps/snmp/snmp_traps.c | 3 ++- src/include/lwip/apps/httpd_opts.h | 5 +++-- src/include/lwip/apps/mqtt.h | 5 +++-- src/include/lwip/apps/smtp.h | 5 +++-- src/include/lwip/apps/sntp_opts.h | 3 ++- src/include/lwip/apps/tftp_opts.h | 3 ++- src/include/lwip/prot/iana.h | 16 +++++++++++++++- 12 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 7c3f0238..e23ea98d 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -62,6 +62,7 @@ #include "lwip/ip_addr.h" #include "lwip/mem.h" #include "lwip/prot/dns.h" +#include "lwip/prot/iana.h" #include @@ -89,7 +90,6 @@ static const ip_addr_t v4group = DNS_MQUERY_IPV4_GROUP_INIT; static const ip_addr_t v6group = DNS_MQUERY_IPV6_GROUP_INIT; #endif -#define MDNS_PORT 5353 #define MDNS_TTL 255 /* Stored offsets to beginning of domain names @@ -1251,7 +1251,7 @@ mdns_init_outpacket(struct mdns_outpacket *out, struct mdns_packet *in) SMEMCPY(&out->dest_addr, &in->source_addr, sizeof(ip_addr_t)); out->dest_port = in->source_port; - if (in->source_port != MDNS_PORT) { + if (in->source_port != LWIP_IANA_PORT_MDNS) { out->unicast_reply = 1; out->cache_flush = 0; if (in->questions == 1) { @@ -1457,7 +1457,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (outpkt->unicast_reply) { udp_sendto_if(mdns_pcb, outpkt->pbuf, &outpkt->dest_addr, outpkt->dest_port, outpkt->netif); } else { - udp_sendto_if(mdns_pcb, outpkt->pbuf, mcast_destaddr, MDNS_PORT, outpkt->netif); + udp_sendto_if(mdns_pcb, outpkt->pbuf, mcast_destaddr, LWIP_IANA_PORT_MDNS, outpkt->netif); } } @@ -1504,7 +1504,7 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination) } } - announce.dest_port = MDNS_PORT; + announce.dest_port = LWIP_IANA_PORT_MDNS; SMEMCPY(&announce.dest_addr, destination, sizeof(announce.dest_addr)); mdns_send_outpacket(&announce); } @@ -2100,7 +2100,7 @@ mdns_resp_init(void) #else mdns_pcb->ttl = MDNS_TTL; #endif - res = udp_bind(mdns_pcb, IP_ANY_TYPE, MDNS_PORT); + res = udp_bind(mdns_pcb, IP_ANY_TYPE, LWIP_IANA_PORT_MDNS); LWIP_UNUSED_ARG(res); /* in case of LWIP_NOASSERT */ LWIP_ASSERT("Failed to bind pcb", res == ERR_OK); udp_recv(mdns_pcb, mdns_recv, NULL); diff --git a/src/apps/netbiosns/netbiosns.c b/src/apps/netbiosns/netbiosns.c index 2dfbe659..6309726b 100644 --- a/src/apps/netbiosns/netbiosns.c +++ b/src/apps/netbiosns/netbiosns.c @@ -49,12 +49,10 @@ #include "lwip/def.h" #include "lwip/udp.h" #include "lwip/netif.h" +#include "lwip/prot/iana.h" #include -/** default port number for "NetBIOS Name service */ -#define NETBIOS_PORT 137 - /** size of a NetBIOS name */ #define NETBIOS_NAME_LEN 16 @@ -329,7 +327,7 @@ netbiosns_init(void) if (netbiosns_pcb != NULL) { /* we have to be allowed to send broadcast packets! */ ip_set_option(netbiosns_pcb, SOF_BROADCAST); - udp_bind(netbiosns_pcb, IP_ANY_TYPE, NETBIOS_PORT); + udp_bind(netbiosns_pcb, IP_ANY_TYPE, LWIP_IANA_PORT_NETBIOS); udp_recv(netbiosns_pcb, netbiosns_recv, netbiosns_pcb); } } diff --git a/src/apps/snmp/snmp_msg.h b/src/apps/snmp/snmp_msg.h index 60beaafe..06db7be1 100644 --- a/src/apps/snmp/snmp_msg.h +++ b/src/apps/snmp/snmp_msg.h @@ -57,17 +57,6 @@ extern "C" { #endif -/* The listen port of the SNMP agent. Clients have to make their requests to - this port. Most standard clients won't work if you change this! */ -#ifndef SNMP_IN_PORT -#define SNMP_IN_PORT 161 -#endif -/* The remote port the SNMP agent sends traps to. Most standard trap sinks won't - work if you change this! */ -#ifndef SNMP_TRAP_PORT -#define SNMP_TRAP_PORT 162 -#endif - /* version defines used in PDU */ #define SNMP_VERSION_1 0 #define SNMP_VERSION_2c 1 diff --git a/src/apps/snmp/snmp_netconn.c b/src/apps/snmp/snmp_netconn.c index 24c3e265..d1b6147b 100644 --- a/src/apps/snmp/snmp_netconn.c +++ b/src/apps/snmp/snmp_netconn.c @@ -42,6 +42,7 @@ #include "lwip/udp.h" #include "snmp_msg.h" #include "lwip/sys.h" +#include "lwip/prot/iana.h" /** SNMP netconn API worker thread */ static void @@ -55,10 +56,10 @@ snmp_netconn_thread(void *arg) /* Bind to SNMP port with default IP address */ #if LWIP_IPV6 conn = netconn_new(NETCONN_UDP_IPV6); - netconn_bind(conn, IP6_ADDR_ANY, SNMP_IN_PORT); + netconn_bind(conn, IP6_ADDR_ANY, LWIP_IANA_PORT_SNMP); #else /* LWIP_IPV6 */ conn = netconn_new(NETCONN_UDP); - netconn_bind(conn, IP4_ADDR_ANY, SNMP_IN_PORT); + netconn_bind(conn, IP4_ADDR_ANY, LWIP_IANA_PORT_SNMP); #endif /* LWIP_IPV6 */ LWIP_ERROR("snmp_netconn: invalid conn", (conn != NULL), return;); diff --git a/src/apps/snmp/snmp_raw.c b/src/apps/snmp/snmp_raw.c index 4a40864f..525af8de 100644 --- a/src/apps/snmp/snmp_raw.c +++ b/src/apps/snmp/snmp_raw.c @@ -39,6 +39,7 @@ #include "lwip/udp.h" #include "lwip/ip.h" +#include "lwip/prot/iana.h" #include "snmp_msg.h" /* lwIP UDP receive callback function */ @@ -92,8 +93,8 @@ snmp_init(void) snmp_traps_handle = snmp_pcb; - udp_recv(snmp_pcb, snmp_recv, (void *)SNMP_IN_PORT); - err = udp_bind(snmp_pcb, IP_ANY_TYPE, SNMP_IN_PORT); + udp_recv(snmp_pcb, snmp_recv, NULL); + err = udp_bind(snmp_pcb, IP_ANY_TYPE, LWIP_IANA_PORT_SNMP); LWIP_ERROR("snmp_raw: Unable to bind PCB", (err == ERR_OK), return;); } diff --git a/src/apps/snmp/snmp_traps.c b/src/apps/snmp/snmp_traps.c index 60201867..6953b3e6 100644 --- a/src/apps/snmp/snmp_traps.c +++ b/src/apps/snmp/snmp_traps.c @@ -46,6 +46,7 @@ #include "lwip/sys.h" #include "lwip/apps/snmp.h" #include "lwip/apps/snmp_core.h" +#include "lwip/prot/iana.h" #include "snmp_msg.h" #include "snmp_asn1.h" #include "snmp_core_priv.h" @@ -216,7 +217,7 @@ snmp_send_trap(const struct snmp_obj_id* eoid, s32_t generic_trap, s32_t specifi snmp_stats.outpkts++; /** send to the TRAP destination */ - snmp_sendto(snmp_traps_handle, p, &td->dip, SNMP_TRAP_PORT); + snmp_sendto(snmp_traps_handle, p, &td->dip, LWIP_IANA_PORT_SNMP_TRAP); pbuf_free(p); } else { err = ERR_MEM; diff --git a/src/include/lwip/apps/httpd_opts.h b/src/include/lwip/apps/httpd_opts.h index 9bc1a0fc..8802b503 100644 --- a/src/include/lwip/apps/httpd_opts.h +++ b/src/include/lwip/apps/httpd_opts.h @@ -42,6 +42,7 @@ #define LWIP_HDR_APPS_HTTPD_OPTS_H #include "lwip/opt.h" +#include "lwip/prot/iana.h" /** * @defgroup httpd_opts Options @@ -129,12 +130,12 @@ /** The server port for HTTPD to use */ #if !defined HTTPD_SERVER_PORT || defined __DOXYGEN__ -#define HTTPD_SERVER_PORT 80 +#define HTTPD_SERVER_PORT LWIP_IANA_PORT_HTTP #endif /** The https server port for HTTPD to use */ #if !defined HTTPD_SERVER_PORT_HTTPS || defined __DOXYGEN__ -#define HTTPD_SERVER_PORT_HTTPS 443 +#define HTTPD_SERVER_PORT_HTTPS LWIP_IANA_PORT_HTTPS #endif /** Enable https support? */ diff --git a/src/include/lwip/apps/mqtt.h b/src/include/lwip/apps/mqtt.h index c4f1a6dd..f5e0055c 100644 --- a/src/include/lwip/apps/mqtt.h +++ b/src/include/lwip/apps/mqtt.h @@ -40,6 +40,7 @@ #include "lwip/apps/mqtt_opts.h" #include "lwip/err.h" #include "lwip/ip_addr.h" +#include "lwip/prot/iana.h" #ifdef __cplusplus extern "C" { @@ -53,10 +54,10 @@ struct altcp_tls_config; /** @ingroup mqtt * Default MQTT port (non-TLS) */ -#define MQTT_PORT 1883 +#define MQTT_PORT LWIP_IANA_PORT_MQTT /** @ingroup mqtt * Default MQTT TLS port */ -#define MQTT_TLS_PORT 8883 +#define MQTT_TLS_PORT LWIP_IANA_PORT_SEQURE_MQTT /*---------------------------------------------------------------------------------------------- */ /* Connection with server */ diff --git a/src/include/lwip/apps/smtp.h b/src/include/lwip/apps/smtp.h index a7cfeba8..456b226b 100644 --- a/src/include/lwip/apps/smtp.h +++ b/src/include/lwip/apps/smtp.h @@ -3,11 +3,12 @@ #include "lwip/apps/smtp_opts.h" #include "lwip/err.h" +#include "lwip/prot/iana.h" /** The default TCP port used for SMTP */ -#define SMTP_DEFAULT_PORT 25 +#define SMTP_DEFAULT_PORT LWIP_IANA_PORT_SMTP /** The default TCP port used for SMTPS */ -#define SMTPS_DEFAULT_PORT 465 +#define SMTPS_DEFAULT_PORT LWIP_IANA_PORT_SMTPS /** Email successfully sent */ #define SMTP_RESULT_OK 0 diff --git a/src/include/lwip/apps/sntp_opts.h b/src/include/lwip/apps/sntp_opts.h index caf97004..db3101c5 100644 --- a/src/include/lwip/apps/sntp_opts.h +++ b/src/include/lwip/apps/sntp_opts.h @@ -38,6 +38,7 @@ #define LWIP_HDR_APPS_SNTP_OPTS_H #include "lwip/opt.h" +#include "lwip/prot/iana.h" /** * @defgroup sntp_opts Options @@ -83,7 +84,7 @@ /** SNTP server port */ #if !defined SNTP_PORT || defined __DOXYGEN__ -#define SNTP_PORT 123 +#define SNTP_PORT LWIP_IANA_PORT_SNTP #endif /** Sanity check: diff --git a/src/include/lwip/apps/tftp_opts.h b/src/include/lwip/apps/tftp_opts.h index 4d52ea1d..f3f4d17d 100644 --- a/src/include/lwip/apps/tftp_opts.h +++ b/src/include/lwip/apps/tftp_opts.h @@ -42,6 +42,7 @@ #define LWIP_HDR_APPS_TFTP_OPTS_H #include "lwip/opt.h" +#include "lwip/prot/iana.h" /** * @defgroup tftp_opts Options @@ -60,7 +61,7 @@ * TFTP server port */ #if !defined TFTP_PORT || defined __DOXYGEN__ -#define TFTP_PORT 69 +#define TFTP_PORT LWIP_IANA_PORT_TFTP #endif /** diff --git a/src/include/lwip/prot/iana.h b/src/include/lwip/prot/iana.h index 899a445a..a713d4cc 100644 --- a/src/include/lwip/prot/iana.h +++ b/src/include/lwip/prot/iana.h @@ -43,7 +43,21 @@ extern "C" { #endif /** Hardware types */ -#define LWIP_IANA_HWTYPE_ETHERNET 1 +#define LWIP_IANA_HWTYPE_ETHERNET 1 + +/** Port numbers */ +#define LWIP_IANA_PORT_SMTP 25 +#define LWIP_IANA_PORT_TFTP 69 +#define LWIP_IANA_PORT_HTTP 80 +#define LWIP_IANA_PORT_SNTP 123 +#define LWIP_IANA_PORT_NETBIOS 137 +#define LWIP_IANA_PORT_SNMP 161 +#define LWIP_IANA_PORT_SNMP_TRAP 162 +#define LWIP_IANA_PORT_HTTPS 443 +#define LWIP_IANA_PORT_SMTPS 465 +#define LWIP_IANA_PORT_MQTT 1883 +#define LWIP_IANA_PORT_MDNS 5353 +#define LWIP_IANA_PORT_SEQURE_MQTT 8883 #ifdef __cplusplus }