Hi, Just wanted to check on this again. Is this something possible or not supported in grpc c++? Any inputs regarding this is highly appreciated.
Regards, Sachin On Tuesday, 27 September 2022 at 15:03:42 UTC-7 Sachin Bharadwaj S wrote: > Hi All, > > Is there a way to designate a source IP and PORT from grpc c++ *client*? > > Generally, on the client side, we specify the IP and PORT of the server's > listening port to connect to and we don't care about the client's IP and > port. When a client tries to create a channel, it assigns a random unused > port for the outgoing connection and uses the IP which has reachability > towards the server. > > But, generally, in systems that have multiple interfaces and multiple IP > addresses, can the application decide which outgoing interface/IP/port to > be used for the connection? > > I have used SetSocketMutator() > <https://grpc.github.io/grpc/cpp/classgrpc_1_1_channel_arguments.html#a520690f499be85159a20200ddb986a96> > and > during the creation of fd, grpc stack gives a callback to the application > and the application can mutate the fd to perform any add-on setsockopt() on > the fd to change its behavior. > In the same callback, if I try to perform bind() to a source address and > port, it gives an "Invalid argument" error. > > *Code snippet for reference:* > > bool mutate_fd_callback(const grpc_mutate_socket_info* info, > > grpc_socket_mutator* mutator) { > > > int ret = 0; > > struct sockaddr_in addr; > > memset(&addr, '\0', sizeof(addr)); > > > addr.sin_addr.s_addr = inet_addr("20.0.0.1"); > > addr.sin_port = htons(51234); > > addr.sin_family = AF_INET; > > > ret = ::bind(info->fd, (struct sockaddr *)&addr, sizeof(struct > sockaddr)); > > Does the grpc stack itself does a bind() internally and the application > has no control over choosing its own IP/port? Or is there any other way of > specifying src IP/PORT instead of bind()? > > Please correct me if I'm wrong in any of the above understanding. > > Regards, > Sachin > > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/af5ccecd-15e1-4840-ace6-7b086d115638n%40googlegroups.com.
