Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion mcmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ int mcmc_check_nonblock_connect(void *c, int *err) {
// connect_bind_tcp()
// ^ fill an internal struct from the stack and call into this central
// connect?
int mcmc_connect(void *c, char *host, char *port, int options) {
int mcmc_connect(void *c, char* source, char *host, char *port, int options) {
mcmc_ctx_t *ctx = (mcmc_ctx_t *)c;

int s;
Expand Down Expand Up @@ -854,6 +854,31 @@ int mcmc_connect(void *c, char *host, char *port, int options) {
}
}

if(source != NULL ){
struct addrinfo source_hints;
struct addrinfo *sai = NULL;

memset(&source_hints, 0, sizeof(source_hints));
source_hints.ai_family = next->ai_family;
source_hints.ai_socktype = SOCK_STREAM;
source_hints.ai_flags = AI_NUMERICHOST;

if( getaddrinfo(source, NULL, &source_hints, &sai) != 0){
res = MCMC_ERR;
close(sock);
goto end;
}

if( bind(sock, sai->ai_addr, sai->ai_addrlen) < 0 ){
freeaddrinfo(sai);
res = MCMC_ERR;
close(sock);
goto end;
}
freeaddrinfo(sai);
}


if (options & MCMC_OPTION_NONBLOCK) {
int flags = fcntl(sock, F_GETFL);
if (flags < 0) {
Expand Down
2 changes: 1 addition & 1 deletion mcmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ int mcmc_fd(void *c);
size_t mcmc_size(int options);
size_t mcmc_min_buffer_size(int options);
int mcmc_parse_buf(const char *buf, size_t read, mcmc_resp_t *r);
int mcmc_connect(void *c, char *host, char *port, int options);
int mcmc_connect(void *c, char *source, char *host, char *port, int options);
int mcmc_check_nonblock_connect(void *c, int *err);
int mcmc_send_request(void *c, const char *request, int len, int count);
int mcmc_request_writev(void *c, const struct iovec *iov, int iovcnt, ssize_t *sent, int count);
Expand Down