mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-06-12 01:29:28 +00:00
Minor changes: don't presume the netif_default is always initialized in some apps (avoid crashs).
This commit is contained in:
parent
9dff15fa76
commit
bf55cf26f1
|
@ -244,48 +244,51 @@ netbios_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *ad
|
|||
struct netbios_hdr* netbios_hdr = p->payload;
|
||||
struct netbios_name_hdr* netbios_name_hdr = (struct netbios_name_hdr*)(netbios_hdr+1);
|
||||
|
||||
/* @todo: do we need to check answerRRs/authorityRRs/additionalRRs? */
|
||||
/* if the packet is a NetBIOS name query question */
|
||||
if (((ntohs(netbios_hdr->flags) & NETB_HFLAG_OPCODE) == NETB_HFLAG_OPCODE_NAME_QUERY) &&
|
||||
((ntohs(netbios_hdr->flags) & NETB_HFLAG_RESPONSE) == 0) &&
|
||||
(ntohs(netbios_hdr->questions) == 1)) {
|
||||
/* decode the NetBIOS name */
|
||||
netbios_name_decoding( netbios_name_hdr->encname, netbios_name, sizeof(netbios_name));
|
||||
/* if the packet is for us */
|
||||
if (strcmp( netbios_name, NETBIOS_LWIP_NAME)==0) {
|
||||
struct pbuf *q;
|
||||
struct netbios_resp *resp;
|
||||
/* we only answer if we got a default interface */
|
||||
if (netif_default != NULL) {
|
||||
/* @todo: do we need to check answerRRs/authorityRRs/additionalRRs? */
|
||||
/* if the packet is a NetBIOS name query question */
|
||||
if (((ntohs(netbios_hdr->flags) & NETB_HFLAG_OPCODE) == NETB_HFLAG_OPCODE_NAME_QUERY) &&
|
||||
((ntohs(netbios_hdr->flags) & NETB_HFLAG_RESPONSE) == 0) &&
|
||||
(ntohs(netbios_hdr->questions) == 1)) {
|
||||
/* decode the NetBIOS name */
|
||||
netbios_name_decoding( netbios_name_hdr->encname, netbios_name, sizeof(netbios_name));
|
||||
/* if the packet is for us */
|
||||
if (strcmp( netbios_name, NETBIOS_LWIP_NAME)==0) {
|
||||
struct pbuf *q;
|
||||
struct netbios_resp *resp;
|
||||
|
||||
q = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct netbios_resp), PBUF_RAM);
|
||||
if (q != NULL) {
|
||||
resp = (struct netbios_resp*)q->payload;
|
||||
q = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct netbios_resp), PBUF_RAM);
|
||||
if (q != NULL) {
|
||||
resp = (struct netbios_resp*)q->payload;
|
||||
|
||||
/* prepare NetBIOS header response */
|
||||
resp->resp_hdr.trans_id = netbios_hdr->trans_id;
|
||||
resp->resp_hdr.flags = htons(NETB_HFLAG_RESPONSE |
|
||||
NETB_HFLAG_OPCODE_NAME_QUERY |
|
||||
NETB_HFLAG_AUTHORATIVE |
|
||||
NETB_HFLAG_RECURS_DESIRED);
|
||||
resp->resp_hdr.questions = 0;
|
||||
resp->resp_hdr.answerRRs = htons(1);
|
||||
resp->resp_hdr.authorityRRs = 0;
|
||||
resp->resp_hdr.additionalRRs = 0;
|
||||
/* prepare NetBIOS header response */
|
||||
resp->resp_hdr.trans_id = netbios_hdr->trans_id;
|
||||
resp->resp_hdr.flags = htons(NETB_HFLAG_RESPONSE |
|
||||
NETB_HFLAG_OPCODE_NAME_QUERY |
|
||||
NETB_HFLAG_AUTHORATIVE |
|
||||
NETB_HFLAG_RECURS_DESIRED);
|
||||
resp->resp_hdr.questions = 0;
|
||||
resp->resp_hdr.answerRRs = htons(1);
|
||||
resp->resp_hdr.authorityRRs = 0;
|
||||
resp->resp_hdr.additionalRRs = 0;
|
||||
|
||||
/* prepare NetBIOS header datas */
|
||||
memcpy( resp->resp_name.encname, netbios_name_hdr->encname, sizeof(netbios_name_hdr->encname));
|
||||
resp->resp_name.nametype = netbios_name_hdr->nametype;
|
||||
resp->resp_name.type = netbios_name_hdr->type;
|
||||
resp->resp_name.class = netbios_name_hdr->class;
|
||||
resp->resp_name.ttl = htonl(NETBIOS_NAME_TTL);
|
||||
resp->resp_name.datalen = htons(sizeof(resp->resp_name.flags)+sizeof(resp->resp_name.addr));
|
||||
resp->resp_name.flags = htons(NETB_NFLAG_NODETYPE_BNODE);
|
||||
resp->resp_name.addr = netif_default->ip_addr.addr;
|
||||
/* prepare NetBIOS header datas */
|
||||
memcpy( resp->resp_name.encname, netbios_name_hdr->encname, sizeof(netbios_name_hdr->encname));
|
||||
resp->resp_name.nametype = netbios_name_hdr->nametype;
|
||||
resp->resp_name.type = netbios_name_hdr->type;
|
||||
resp->resp_name.class = netbios_name_hdr->class;
|
||||
resp->resp_name.ttl = htonl(NETBIOS_NAME_TTL);
|
||||
resp->resp_name.datalen = htons(sizeof(resp->resp_name.flags)+sizeof(resp->resp_name.addr));
|
||||
resp->resp_name.flags = htons(NETB_NFLAG_NODETYPE_BNODE);
|
||||
resp->resp_name.addr = netif_default->ip_addr.addr;
|
||||
|
||||
/* send the NetBIOS response */
|
||||
udp_sendto(upcb, q, addr, port);
|
||||
|
||||
/* free the "reference" pbuf */
|
||||
pbuf_free(q);
|
||||
/* send the NetBIOS response */
|
||||
udp_sendto(upcb, q, addr, port);
|
||||
|
||||
/* free the "reference" pbuf */
|
||||
pbuf_free(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
|
||||
/** ping target - should be a "struct ip_addr" */
|
||||
#ifndef PING_TARGET
|
||||
#define PING_TARGET (netif_default->gw)
|
||||
#define PING_TARGET (netif_default?netif_default->gw:ip_addr_any)
|
||||
#endif
|
||||
|
||||
/** ping receive timeout - in milliseconds */
|
||||
|
@ -173,7 +173,8 @@ static void
|
|||
ping_thread(void *arg)
|
||||
{
|
||||
int s;
|
||||
int timeout=PING_RCV_TIMEO;
|
||||
int timeout = PING_RCV_TIMEO;
|
||||
struct ip_addr ping_target = PING_TARGET;
|
||||
|
||||
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) {
|
||||
return;
|
||||
|
@ -183,10 +184,10 @@ ping_thread(void *arg)
|
|||
|
||||
while (1) {
|
||||
LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
|
||||
ip_addr_debug_print(PING_DEBUG, &PING_TARGET);
|
||||
ip_addr_debug_print(PING_DEBUG, &ping_target);
|
||||
LWIP_DEBUGF( PING_DEBUG, ("\n"));
|
||||
|
||||
ping_send(s, &PING_TARGET);
|
||||
ping_send(s, &ping_target);
|
||||
ping_time = sys_now();
|
||||
ping_recv(s);
|
||||
sys_msleep(PING_DELAY);
|
||||
|
@ -242,13 +243,15 @@ static void
|
|||
ping_timeout(void *arg)
|
||||
{
|
||||
struct raw_pcb *pcb = (struct raw_pcb*)arg;
|
||||
struct ip_addr ping_target = PING_TARGET;
|
||||
|
||||
LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL);
|
||||
|
||||
LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
|
||||
ip_addr_debug_print(PING_DEBUG, &PING_TARGET);
|
||||
ip_addr_debug_print(PING_DEBUG, &ping_target);
|
||||
LWIP_DEBUGF( PING_DEBUG, ("\n"));
|
||||
|
||||
ping_send(pcb, &PING_TARGET);
|
||||
ping_send(pcb, &ping_target);
|
||||
|
||||
sys_timeout(PING_DELAY, ping_timeout, pcb);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user