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

Function dist_bind_connect_source

ds4_distributed.c:1261–1291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1259}
1260
1261static int dist_bind_connect_source(int fd, int family, const char *host, int *bind_errno) {
1262 if (bind_errno) *bind_errno = 0;
1263 if (!host || !host[0]) return 0;
1264
1265 struct addrinfo hints;
1266 memset(&hints, 0, sizeof(hints));
1267 hints.ai_socktype = SOCK_STREAM;
1268 hints.ai_family = family;
1269
1270 struct addrinfo *res = NULL;
1271 int gai = getaddrinfo(host, "0", &hints, &res);
1272 if (gai != 0) {
1273 if (bind_errno) *bind_errno = EINVAL;
1274 return -1;
1275 }
1276
1277 int rc = -1;
1278 int saved_errno = EADDRNOTAVAIL;
1279 for (struct addrinfo *ai = res; ai; ai = ai->ai_next) {
1280 if (bind(fd, ai->ai_addr, ai->ai_addrlen) == 0) {
1281 rc = 0;
1282 saved_errno = 0;
1283 break;
1284 }
1285 saved_errno = errno;
1286 }
1287 freeaddrinfo(res);
1288
1289 if (bind_errno) *bind_errno = saved_errno;
1290 return rc;
1291}
1292
1293static int dist_bind_connect_interface(int fd, int family, const char *ifname, int *bind_errno) {
1294 (void)fd;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected