MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / netconn_bind

Function netconn_bind

components/net/lwip/lwip-2.1.2/src/api/api_lib.c:306–339  ·  view source on GitHub ↗

* @ingroup netconn_common * Bind a netconn to a specific local IP address and port. * Binding one netconn twice might not always be checked correctly! * * @param conn the netconn to bind * @param addr the local IP address to bind the netconn to * (use IP4_ADDR_ANY/IP6_ADDR_ANY to bind to all addresses) * @param port the local port to bind the netconn to (not used for RAW) * @re

Source from the content-addressed store, hash-verified

304 * @return ERR_OK if bound, any other err_t on failure
305 */
306err_t
307netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port)
308{
309 API_MSG_VAR_DECLARE(msg);
310 err_t err;
311
312 LWIP_ERROR("netconn_bind: invalid conn", (conn != NULL), return ERR_ARG;);
313
314#if LWIP_IPV4
315 /* Don't propagate NULL pointer (IP_ADDR_ANY alias) to subsequent functions */
316 if (addr == NULL) {
317 addr = IP4_ADDR_ANY;
318 }
319#endif /* LWIP_IPV4 */
320
321#if LWIP_IPV4 && LWIP_IPV6
322 /* "Socket API like" dual-stack support: If IP to bind to is IP6_ADDR_ANY,
323 * and NETCONN_FLAG_IPV6_V6ONLY is 0, use IP_ANY_TYPE to bind
324 */
325 if ((netconn_get_ipv6only(conn) == 0) &&
326 ip_addr_cmp(addr, IP6_ADDR_ANY)) {
327 addr = IP_ANY_TYPE;
328 }
329#endif /* LWIP_IPV4 && LWIP_IPV6 */
330
331 API_MSG_VAR_ALLOC(msg);
332 API_MSG_VAR_REF(msg).conn = conn;
333 API_MSG_VAR_REF(msg).msg.bc.ipaddr = API_MSG_VAR_REF(addr);
334 API_MSG_VAR_REF(msg).msg.bc.port = port;
335 err = netconn_apimsg(lwip_netconn_do_bind, &API_MSG_VAR_REF(msg));
336 API_MSG_VAR_FREE(msg);
337
338 return err;
339}
340
341/**
342 * @ingroup netconn_common

Callers 4

lwip_bindFunction · 0.70
snmp_netconn_threadFunction · 0.50
udpecho_entryFunction · 0.50
tcpecho_entryFunction · 0.50

Calls 2

ip_addr_cmpFunction · 0.85
netconn_apimsgFunction · 0.70

Tested by 2

udpecho_entryFunction · 0.40
tcpecho_entryFunction · 0.40