MCPcopy Create free account
hub / github.com/acl-dev/acl / bind_addr

Function bind_addr

lib_acl/samples/udp/udp.cpp:65–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65static int bind_addr(struct addrinfo *res0, struct addrinfo **res)
66{
67 struct addrinfo *it;
68 int on, fd;
69
70 for (it = res0; it != NULL ; it = it->ai_next) {
71 fd = socket(it->ai_family, it->ai_socktype, it->ai_protocol);
72 if (fd == ACL_SOCKET_INVALID) {
73 acl_msg_error("%s(%d): create socket %s",
74 __FILE__, __LINE__, acl_last_serror());
75 return ACL_SOCKET_INVALID;
76 }
77
78 on = 1;
79 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
80 (const void *) &on, sizeof(on)) < 0)
81 {
82 acl_msg_warn("%s(%d): setsockopt(SO_REUSEADDR): %s",
83 __FILE__, __LINE__, acl_last_serror());
84 }
85
86#if defined(SO_REUSEPORT)
87 on = 1;
88 if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT,
89 (const void *) &on, sizeof(on)) < 0)
90 {
91 acl_msg_warn("%s(%d): setsocket(SO_REUSEPORT): %s",
92 __FILE__, __LINE__, acl_last_serror());
93 }
94#endif
95
96#ifdef ACL_WINDOWS
97 if (bind(fd, it->ai_addr, (int) it->ai_addrlen) == 0)
98#else
99 if (bind(fd, it->ai_addr, it->ai_addrlen) == 0)
100#endif
101 {
102 *res = it;
103 return fd;
104 }
105
106 acl_msg_error("%s(%d): bind error %s",
107 __FILE__, __LINE__, acl_last_serror());
108 acl_socket_close(fd);
109 }
110
111 return ACL_SOCKET_INVALID;
112}
113
114static SOCK_UDP *sock_open(const char *addr)
115{

Callers 1

sock_openFunction · 0.70

Calls 7

acl_msg_errorFunction · 0.85
acl_last_serrorFunction · 0.85
setsockoptFunction · 0.85
acl_msg_warnFunction · 0.85
bindFunction · 0.85
acl_socket_closeFunction · 0.85
socketFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…