diff --git a/CHANGELOG b/CHANGELOG index bd310580..4f4cc643 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -166,6 +166,11 @@ HISTORY ++ Bug fixes: + 2007-05-22 Frédéric Bernon + * api.h, api_lib.c, api_msg.h, api_msg.c: change the struct api_msg_msg to see + which parameters are used by which do_xxx function, and to avoid "misusing" + parameters (patch #5938). + 2007-05-22 Simon Goldschmidt * api_lib.c, api_msg.c, raw.c, api.h, api_msg.h, raw.h: Included patch #5938: changed raw_pcb.protocol from u16_t to u8_t since for IPv4 and IPv6, proto diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 2735b95f..06bcc8df 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -218,9 +218,9 @@ netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, #endif /* LWIP_SO_RCVTIMEO */ msg.function = do_newconn; - msg.msg.msg.raw_proto = proto; + msg.msg.msg.n.proto = proto; msg.msg.conn = conn; - tcpip_apimsg(&msg); + tcpip_apimsg(&msg); if ( conn->err != ERR_OK ) { sys_sem_free(conn->sem); @@ -520,9 +520,9 @@ netconn_recv(struct netconn *conn) msg.function = do_recv; msg.msg.conn = conn; if (buf != NULL) { - msg.msg.msg.len = buf->p->tot_len; + msg.msg.msg.r.len = buf->p->tot_len; } else { - msg.msg.msg.len = 1; + msg.msg.msg.r.len = 1; } tcpip_apimsg(&msg); #endif /* LWIP_TCP */ @@ -663,10 +663,9 @@ err_t netconn_join_leave_group (struct netconn *conn, struct ip_addr *multiaddr, struct ip_addr *interface, - u16_t join_or_leave) + enum netconn_igmp join_or_leave) { struct api_msg msg; - struct ip_addr *ipaddr[2]; if (conn == NULL) { return ERR_VAL; @@ -676,13 +675,11 @@ netconn_join_leave_group (struct netconn *conn, return conn->err; } - ipaddr[0] = multiaddr; - ipaddr[1] = interface; - msg.function = do_join_leave_group; msg.msg.conn = conn; - msg.msg.msg.bc.ipaddr = (struct ip_addr *)ipaddr; - msg.msg.msg.bc.port = join_or_leave; /* misusing the port field */ + msg.msg.msg.jl.multiaddr = multiaddr; + msg.msg.msg.jl.interface = interface; + msg.msg.msg.jl.join_or_leave = join_or_leave; tcpip_apimsg(&msg); return conn->err; } diff --git a/src/api/api_msg.c b/src/api/api_msg.c index c50c7972..e1e08922 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -293,52 +293,54 @@ pcb_new(struct api_msg_msg *msg) switch(msg->conn->type) { #if LWIP_RAW case NETCONN_RAW: - msg->conn->pcb.raw = raw_new(msg->msg.raw_proto); - if(msg->conn->pcb.raw == NULL) { - msg->conn->err = ERR_MEM; - break; - } - raw_recv(msg->conn->pcb.raw, recv_raw, msg->conn); - break; + msg->conn->pcb.raw = raw_new(msg->msg.n.proto); + if(msg->conn->pcb.raw == NULL) { + msg->conn->err = ERR_MEM; + break; + } + raw_recv(msg->conn->pcb.raw, recv_raw, msg->conn); + break; #endif /* LWIP_RAW */ #if LWIP_UDP case NETCONN_UDPLITE: - msg->conn->pcb.udp = udp_new(); - if(msg->conn->pcb.udp == NULL) { - msg->conn->err = ERR_MEM; - break; - } - udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE); - udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); - break; + msg->conn->pcb.udp = udp_new(); + if(msg->conn->pcb.udp == NULL) { + msg->conn->err = ERR_MEM; + break; + } + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; case NETCONN_UDPNOCHKSUM: - msg->conn->pcb.udp = udp_new(); - if(msg->conn->pcb.udp == NULL) { - msg->conn->err = ERR_MEM; - break; - } - udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM); - udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); - break; + msg->conn->pcb.udp = udp_new(); + if(msg->conn->pcb.udp == NULL) { + msg->conn->err = ERR_MEM; + break; + } + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; case NETCONN_UDP: - msg->conn->pcb.udp = udp_new(); - if(msg->conn->pcb.udp == NULL) { - msg->conn->err = ERR_MEM; - break; - } - udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); - break; + msg->conn->pcb.udp = udp_new(); + if(msg->conn->pcb.udp == NULL) { + msg->conn->err = ERR_MEM; + break; + } + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; #endif /* LWIP_UDP */ #if LWIP_TCP case NETCONN_TCP: - msg->conn->pcb.tcp = tcp_new(); - if(msg->conn->pcb.tcp == NULL) { - msg->conn->err = ERR_MEM; - break; - } - setup_tcp(msg->conn); - break; + msg->conn->pcb.tcp = tcp_new(); + if(msg->conn->pcb.tcp == NULL) { + msg->conn->err = ERR_MEM; + break; + } + setup_tcp(msg->conn); + break; #endif /* LWIP_TCP */ + default: + break; } return msg->conn->err; @@ -391,9 +393,10 @@ do_delconn(struct api_msg_msg *msg) tcp_abort(msg->conn->pcb.tcp); } } + break; #endif /* LWIP_TCP */ default: - break; + break; } } /* Trigger select() in socket layer */ @@ -432,6 +435,7 @@ do_bind(struct api_msg_msg *msg) #if LWIP_TCP case NETCONN_TCP: msg->conn->err = tcp_bind(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port); + break; #endif /* LWIP_TCP */ default: break; @@ -496,8 +500,8 @@ do_connect(struct api_msg_msg *msg) setup_tcp(msg->conn); msg->conn->err = tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port, do_connected); + break; #endif /* LWIP_TCP */ - default: break; } @@ -558,7 +562,7 @@ do_send(struct api_msg_msg *msg) switch (msg->conn->type) { #if LWIP_RAW case NETCONN_RAW: - if (msg->msg.b->addr==NULL) { + if (msg->msg.b->addr == NULL) { msg->conn->err = raw_send(msg->conn->pcb.raw, msg->msg.b->p); } else { msg->conn->err = raw_sendto(msg->conn->pcb.raw, msg->msg.b->p, msg->msg.b->addr); @@ -569,15 +573,14 @@ do_send(struct api_msg_msg *msg) case NETCONN_UDPLITE: case NETCONN_UDPNOCHKSUM: case NETCONN_UDP: - if (msg->msg.b->addr==NULL) { + if (msg->msg.b->addr == NULL) { msg->conn->err = udp_send(msg->conn->pcb.udp, msg->msg.b->p); } else { msg->conn->err = udp_sendto(msg->conn->pcb.udp, msg->msg.b->p, msg->msg.b->addr, msg->msg.b->port); } break; #endif /* LWIP_UDP */ - case NETCONN_TCP: - /* nothing to do */ + default: break; } } @@ -592,7 +595,7 @@ do_recv(struct api_msg_msg *msg) if (msg->conn->err == ERR_OK) { if (msg->conn->pcb.tcp != NULL) { if (msg->conn->type == NETCONN_TCP) { - tcp_recved(msg->conn->pcb.tcp, msg->msg.len); + tcp_recved(msg->conn->pcb.tcp, msg->msg.r.len); } } } @@ -609,7 +612,7 @@ do_write(struct api_msg_msg *msg) if (msg->conn->err == ERR_OK) { if (msg->conn->pcb.tcp != NULL) { if (msg->conn->type == NETCONN_TCP) { -#if LWIP_TCP +#if LWIP_TCP err = tcp_write(msg->conn->pcb.tcp, msg->msg.w.dataptr, msg->msg.w.len, msg->msg.w.copy); /* This is the Nagle algorithm: inhibit the sending of new TCP @@ -666,9 +669,10 @@ do_join_leave_group(struct api_msg_msg *msg) case NETCONN_UDPLITE: case NETCONN_UDPNOCHKSUM: case NETCONN_UDP: - switch(msg->msg.bc.port){ /* misusing the port field */ - case NETCONN_JOIN: msg->conn->err = igmp_joingroup (netif_default, ((struct ip_addr**)(msg->msg.bc.ipaddr))[0]); break; - case NETCONN_LEAVE: msg->conn->err = igmp_leavegroup(netif_default, ((struct ip_addr**)(msg->msg.bc.ipaddr))[0]); break; + if (msg->msg.jl.join_or_leave == NETCONN_JOIN) { + msg->conn->err = igmp_joingroup ( netif_default, msg->msg.jl.multiaddr); + } else { + msg->conn->err = igmp_leavegroup( netif_default, msg->msg.jl.multiaddr); } break; #endif /* LWIP_UDP */ diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h index aa0d4b00..03685027 100644 --- a/src/include/lwip/api.h +++ b/src/include/lwip/api.h @@ -176,7 +176,7 @@ err_t netconn_close (struct netconn *conn); err_t netconn_join_leave_group (struct netconn *conn, struct ip_addr *multiaddr, struct ip_addr *interface, - u16_t join_or_leave); + enum netconn_igmp join_or_leave); #endif /* LWIP_IGMP */ err_t netconn_err (struct netconn *conn); diff --git a/src/include/lwip/api_msg.h b/src/include/lwip/api_msg.h index 999f457b..dc9bc55b 100644 --- a/src/include/lwip/api_msg.h +++ b/src/include/lwip/api_msg.h @@ -54,19 +54,29 @@ struct api_msg_msg { struct netconn *conn; enum netconn_type conntype; union { - struct pbuf *p; - struct netbuf *b; - struct { + struct netbuf *b; /* do_send */ + struct { + u8_t proto; + } n; /* do_newconn */ + struct { struct ip_addr *ipaddr; u16_t port; - } bc; /* do_newconn, do_bind, do_connect, do_join_leave_group*/ + } bc; /* do_bind, do_connect */ struct { const void *dataptr; u16_t len; u8_t copy; } w; /* do_write */ - u16_t len; /* do_recv */ - u8_t raw_proto; /* do_newconn */ + struct { + u16_t len; + } r; /* do_recv */ +#if LWIP_IGMP + struct { + struct ip_addr *multiaddr; + struct ip_addr *interface; + enum netconn_igmp join_or_leave; + } jl; /* do_join_leave_group */ +#endif /* LWIP_IGMP */ } msg; };