netbiosns: check question type before generating an answer

This commit is contained in:
goldsimon 2018-04-18 08:17:10 +02:00
parent f65911a84b
commit b1fe8cf4b8

View File

@ -77,6 +77,10 @@
#define NETB_HFLAG_REPLYCODE 0x0008U
#define NETB_HFLAG_REPLYCODE_NOERROR 0x0000U
/* NetBIOS question types */
#define NETB_QTYPE_NB 0x0020U
#define NETB_QTYPE_NBSTAT 0x0021U
/** NetBIOS name flags */
#define NETB_NFLAG_UNIQUE 0x8000U
#define NETB_NFLAG_NODETYPE 0x6000U
@ -348,6 +352,8 @@ netbiosns_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t
(netbios_hdr->questions == PP_NTOHS(1))) {
/* decode the NetBIOS name */
netbiosns_name_decode((char *)(netbios_name_hdr->encname), netbios_name, sizeof(netbios_name));
/* check the request type */
if (netbios_name_hdr->type == PP_HTONS(NETB_QTYPE_NB)) {
/* if the packet is for us */
if (lwip_strnicmp(netbios_name, NETBIOS_LOCAL_NAME, sizeof(NETBIOS_LOCAL_NAME)) == 0) {
struct pbuf *q;
@ -384,8 +390,12 @@ netbiosns_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t
/* free the "reference" pbuf */
pbuf_free(q);
}
}
#if LWIP_NETBIOS_RESPOND_NAME_QUERY
} else if (!lwip_strnicmp(netbios_name, "*", sizeof(NETBIOS_LOCAL_NAME))) {
} else if (netbios_name_hdr->type == PP_HTONS(NETB_QTYPE_NBSTAT)) {
/* if the packet is for us or general query */
if (!lwip_strnicmp(netbios_name, NETBIOS_LOCAL_NAME, sizeof(NETBIOS_LOCAL_NAME)) ||
!lwip_strnicmp(netbios_name, "*", sizeof(NETBIOS_LOCAL_NAME))) {
/* general query - ask for our IP address */
struct pbuf *q;
struct netbios_answer *resp;
@ -433,6 +443,7 @@ netbiosns_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t
udp_sendto(upcb, q, addr, port);
pbuf_free(q);
}
}
#endif /* LWIP_NETBIOS_RESPOND_NAME_QUERY */
}
}