1*4b169a6bSchristos /* bind.c --- wrappers for Windows bind function
2*4b169a6bSchristos
3*4b169a6bSchristos Copyright (C) 2008-2022 Free Software Foundation, Inc.
4*4b169a6bSchristos
5*4b169a6bSchristos This file is free software: you can redistribute it and/or modify
6*4b169a6bSchristos it under the terms of the GNU Lesser General Public License as
7*4b169a6bSchristos published by the Free Software Foundation; either version 2.1 of the
8*4b169a6bSchristos License, or (at your option) any later version.
9*4b169a6bSchristos
10*4b169a6bSchristos This file is distributed in the hope that it will be useful,
11*4b169a6bSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
12*4b169a6bSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*4b169a6bSchristos GNU Lesser General Public License for more details.
14*4b169a6bSchristos
15*4b169a6bSchristos You should have received a copy of the GNU Lesser General Public License
16*4b169a6bSchristos along with this program. If not, see <https://www.gnu.org/licenses/>. */
17*4b169a6bSchristos
18*4b169a6bSchristos /* Written by Paolo Bonzini */
19*4b169a6bSchristos
20*4b169a6bSchristos #include <config.h>
21*4b169a6bSchristos
22*4b169a6bSchristos #define WIN32_LEAN_AND_MEAN
23*4b169a6bSchristos /* Get winsock2.h. */
24*4b169a6bSchristos #include <sys/socket.h>
25*4b169a6bSchristos
26*4b169a6bSchristos /* Get set_winsock_errno, FD_TO_SOCKET etc. */
27*4b169a6bSchristos #include "w32sock.h"
28*4b169a6bSchristos
29*4b169a6bSchristos #undef bind
30*4b169a6bSchristos
31*4b169a6bSchristos int
rpl_bind(int fd,const struct sockaddr * sockaddr,socklen_t len)32*4b169a6bSchristos rpl_bind (int fd, const struct sockaddr *sockaddr, socklen_t len)
33*4b169a6bSchristos {
34*4b169a6bSchristos SOCKET sock = FD_TO_SOCKET (fd);
35*4b169a6bSchristos
36*4b169a6bSchristos if (sock == INVALID_SOCKET)
37*4b169a6bSchristos {
38*4b169a6bSchristos errno = EBADF;
39*4b169a6bSchristos return -1;
40*4b169a6bSchristos }
41*4b169a6bSchristos else
42*4b169a6bSchristos {
43*4b169a6bSchristos int r = bind (sock, sockaddr, len);
44*4b169a6bSchristos if (r < 0)
45*4b169a6bSchristos set_winsock_errno ();
46*4b169a6bSchristos
47*4b169a6bSchristos return r;
48*4b169a6bSchristos }
49*4b169a6bSchristos }
50