MCPcopy Create free account
hub / github.com/antirez/ds4 / dist_bind_connect_interface

Function dist_bind_connect_interface

ds4_distributed.c:1293–1326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1291}
1292
1293static int dist_bind_connect_interface(int fd, int family, const char *ifname, int *bind_errno) {
1294 (void)fd;
1295 if (bind_errno) *bind_errno = 0;
1296 if (!ifname || !ifname[0]) return 0;
1297
1298 unsigned int ifindex = if_nametoindex(ifname);
1299 if (ifindex == 0) {
1300 if (bind_errno) *bind_errno = errno ? errno : ENODEV;
1301 return -1;
1302 }
1303
1304 int rc = 0;
1305 if (family == AF_INET) {
1306#ifdef IP_BOUND_IF
1307 rc = setsockopt(fd, IPPROTO_IP, IP_BOUND_IF, &ifindex, sizeof(ifindex));
1308#else
1309 errno = ENOTSUP;
1310 rc = -1;
1311#endif
1312 } else if (family == AF_INET6) {
1313#ifdef IPV6_BOUND_IF
1314 rc = setsockopt(fd, IPPROTO_IPV6, IPV6_BOUND_IF, &ifindex, sizeof(ifindex));
1315#else
1316 errno = ENOTSUP;
1317 rc = -1;
1318#endif
1319 }
1320
1321 if (rc != 0) {
1322 if (bind_errno) *bind_errno = errno ? errno : EIO;
1323 return -1;
1324 }
1325 return 0;
1326}
1327
1328static int dist_connect_endpoint_once(const char *host, int port, int *last_errno, char *err, size_t errlen) {
1329 char portbuf[16];

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected