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).

This commit is contained in:
fbernon 2007-05-22 09:54:00 +00:00
parent 2106f491d0
commit 499f4689be
5 changed files with 82 additions and 66 deletions

View File

@ -166,6 +166,11 @@ HISTORY
++ Bug fixes: ++ 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 2007-05-22 Simon Goldschmidt
* api_lib.c, api_msg.c, raw.c, api.h, api_msg.h, raw.h: Included patch #5938: * 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 changed raw_pcb.protocol from u16_t to u8_t since for IPv4 and IPv6, proto

View File

@ -218,7 +218,7 @@ netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
#endif /* LWIP_SO_RCVTIMEO */ #endif /* LWIP_SO_RCVTIMEO */
msg.function = do_newconn; msg.function = do_newconn;
msg.msg.msg.raw_proto = proto; msg.msg.msg.n.proto = proto;
msg.msg.conn = conn; msg.msg.conn = conn;
tcpip_apimsg(&msg); tcpip_apimsg(&msg);
@ -520,9 +520,9 @@ netconn_recv(struct netconn *conn)
msg.function = do_recv; msg.function = do_recv;
msg.msg.conn = conn; msg.msg.conn = conn;
if (buf != NULL) { if (buf != NULL) {
msg.msg.msg.len = buf->p->tot_len; msg.msg.msg.r.len = buf->p->tot_len;
} else { } else {
msg.msg.msg.len = 1; msg.msg.msg.r.len = 1;
} }
tcpip_apimsg(&msg); tcpip_apimsg(&msg);
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
@ -663,10 +663,9 @@ err_t
netconn_join_leave_group (struct netconn *conn, netconn_join_leave_group (struct netconn *conn,
struct ip_addr *multiaddr, struct ip_addr *multiaddr,
struct ip_addr *interface, struct ip_addr *interface,
u16_t join_or_leave) enum netconn_igmp join_or_leave)
{ {
struct api_msg msg; struct api_msg msg;
struct ip_addr *ipaddr[2];
if (conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
@ -676,13 +675,11 @@ netconn_join_leave_group (struct netconn *conn,
return conn->err; return conn->err;
} }
ipaddr[0] = multiaddr;
ipaddr[1] = interface;
msg.function = do_join_leave_group; msg.function = do_join_leave_group;
msg.msg.conn = conn; msg.msg.conn = conn;
msg.msg.msg.bc.ipaddr = (struct ip_addr *)ipaddr; msg.msg.msg.jl.multiaddr = multiaddr;
msg.msg.msg.bc.port = join_or_leave; /* misusing the port field */ msg.msg.msg.jl.interface = interface;
msg.msg.msg.jl.join_or_leave = join_or_leave;
tcpip_apimsg(&msg); tcpip_apimsg(&msg);
return conn->err; return conn->err;
} }

View File

@ -293,7 +293,7 @@ pcb_new(struct api_msg_msg *msg)
switch(msg->conn->type) { switch(msg->conn->type) {
#if LWIP_RAW #if LWIP_RAW
case NETCONN_RAW: case NETCONN_RAW:
msg->conn->pcb.raw = raw_new(msg->msg.raw_proto); msg->conn->pcb.raw = raw_new(msg->msg.n.proto);
if(msg->conn->pcb.raw == NULL) { if(msg->conn->pcb.raw == NULL) {
msg->conn->err = ERR_MEM; msg->conn->err = ERR_MEM;
break; break;
@ -339,6 +339,8 @@ pcb_new(struct api_msg_msg *msg)
setup_tcp(msg->conn); setup_tcp(msg->conn);
break; break;
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
default:
break;
} }
return msg->conn->err; return msg->conn->err;
@ -391,6 +393,7 @@ do_delconn(struct api_msg_msg *msg)
tcp_abort(msg->conn->pcb.tcp); tcp_abort(msg->conn->pcb.tcp);
} }
} }
break;
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
default: default:
break; break;
@ -432,6 +435,7 @@ do_bind(struct api_msg_msg *msg)
#if LWIP_TCP #if LWIP_TCP
case NETCONN_TCP: case NETCONN_TCP:
msg->conn->err = tcp_bind(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port); msg->conn->err = tcp_bind(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port);
break;
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
default: default:
break; break;
@ -496,8 +500,8 @@ do_connect(struct api_msg_msg *msg)
setup_tcp(msg->conn); setup_tcp(msg->conn);
msg->conn->err = tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port, msg->conn->err = tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port,
do_connected); do_connected);
break;
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
default: default:
break; break;
} }
@ -576,8 +580,7 @@ do_send(struct api_msg_msg *msg)
} }
break; break;
#endif /* LWIP_UDP */ #endif /* LWIP_UDP */
case NETCONN_TCP: default:
/* nothing to do */
break; break;
} }
} }
@ -592,7 +595,7 @@ do_recv(struct api_msg_msg *msg)
if (msg->conn->err == ERR_OK) { if (msg->conn->err == ERR_OK) {
if (msg->conn->pcb.tcp != NULL) { if (msg->conn->pcb.tcp != NULL) {
if (msg->conn->type == NETCONN_TCP) { 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);
} }
} }
} }
@ -666,9 +669,10 @@ do_join_leave_group(struct api_msg_msg *msg)
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM: case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP: case NETCONN_UDP:
switch(msg->msg.bc.port){ /* misusing the port field */ if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
case NETCONN_JOIN: msg->conn->err = igmp_joingroup (netif_default, ((struct ip_addr**)(msg->msg.bc.ipaddr))[0]); break; msg->conn->err = igmp_joingroup ( netif_default, msg->msg.jl.multiaddr);
case NETCONN_LEAVE: msg->conn->err = igmp_leavegroup(netif_default, ((struct ip_addr**)(msg->msg.bc.ipaddr))[0]); break; } else {
msg->conn->err = igmp_leavegroup( netif_default, msg->msg.jl.multiaddr);
} }
break; break;
#endif /* LWIP_UDP */ #endif /* LWIP_UDP */

View File

@ -176,7 +176,7 @@ err_t netconn_close (struct netconn *conn);
err_t netconn_join_leave_group (struct netconn *conn, err_t netconn_join_leave_group (struct netconn *conn,
struct ip_addr *multiaddr, struct ip_addr *multiaddr,
struct ip_addr *interface, struct ip_addr *interface,
u16_t join_or_leave); enum netconn_igmp join_or_leave);
#endif /* LWIP_IGMP */ #endif /* LWIP_IGMP */
err_t netconn_err (struct netconn *conn); err_t netconn_err (struct netconn *conn);

View File

@ -54,19 +54,29 @@ struct api_msg_msg {
struct netconn *conn; struct netconn *conn;
enum netconn_type conntype; enum netconn_type conntype;
union { union {
struct pbuf *p; struct netbuf *b; /* do_send */
struct netbuf *b; struct {
u8_t proto;
} n; /* do_newconn */
struct { struct {
struct ip_addr *ipaddr; struct ip_addr *ipaddr;
u16_t port; u16_t port;
} bc; /* do_newconn, do_bind, do_connect, do_join_leave_group*/ } bc; /* do_bind, do_connect */
struct { struct {
const void *dataptr; const void *dataptr;
u16_t len; u16_t len;
u8_t copy; u8_t copy;
} w; /* do_write */ } w; /* do_write */
u16_t len; /* do_recv */ struct {
u8_t raw_proto; /* do_newconn */ 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; } msg;
}; };