I'm not sure that needed as it seems getpeername/getsockname accept int fd and return -1 for fd=-1 Signed-off-by: Uri Lublin <uril@xxxxxxxxxx> --- server/main-channel.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server/main-channel.c b/server/main-channel.c index bf84694..9ff4dcd 100644 --- a/server/main-channel.c +++ b/server/main-channel.c @@ -281,12 +281,24 @@ MainChannelClient *main_channel_link(MainChannel *channel, RedClient *client, int main_channel_getsockname(MainChannel *main_chan, struct sockaddr *sa, socklen_t *salen) { - return main_chan ? getsockname(red_channel_get_first_socket(&main_chan->base), sa, salen) : -1; + int socketfd; + + if (!main_chan || ((socketfd = red_channel_get_first_socket(&main_chan->base)) < 0)) { + return -1; + } + + return getsockname(socketfd, sa, salen); } int main_channel_getpeername(MainChannel *main_chan, struct sockaddr *sa, socklen_t *salen) { - return main_chan ? getpeername(red_channel_get_first_socket(&main_chan->base), sa, salen) : -1; + int socketfd; + + if (!main_chan || ((socketfd = red_channel_get_first_socket(&main_chan->base)) < 0)) { + return -1; + } + + return getpeername(socketfd, sa, salen); } // TODO: ? shouldn't it disonnect all clients? or shutdown all main_channels? -- 2.7.4 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel