- diff --git a/libtirpc/src/bindresvport.c b/libtirpc/src/bindresvport.c
- index 01d1921..fd11dc3 100644
- --- a/libtirpc/src/bindresvport.c
- +++ b/libtirpc/src/bindresvport.c
- @@ -1,5 +1,6 @@
- /*
- * Copyright (c) 2009, Sun Microsystems, Inc.
- + * Copyright (c) 2024, Roland Mainz <roland.mainz@nrubsig.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- @@ -32,20 +33,30 @@
- * Copyright (c) 1987 by Sun Microsystems, Inc.
- *
- * Portions Copyright(C) 1996, Jason Downs. All rights reserved.
- + * Portions Copyright(C) 2024, Roland Mainz <roland.mainz@nrubsig.org>
- */
- #include <wintirpc.h>
- #include <sys/types.h>
- -//#include <sys/socket.h>
- -
- -//#include <netinet/in.h>
- +#ifndef _WIN32
- +#include <sys/socket.h>
- +#include <netinet/in.h>
- +#endif
- #include <errno.h>
- #include <string.h>
- -//#include <unistd.h>
- +#ifndef _WIN32
- +#include <unistd.h>
- +#endif
- #include <rpc/rpc.h>
- +#ifdef _WIN32
- +#include <winsock2.h>
- +#include <mstcpip.h>
- +#include <ws2ipdef.h>
- +#endif
- +
- /*
- * Bind a socket to a privileged IP port
- */
- @@ -139,18 +150,93 @@ bindresvport_sa(sd, sa)
- return (res);
- }
- -#else
- -/*----------------------
- -#if defined(_WIN32)
- +#elif defined(_WIN32)
- +
- +#define STARTPORT 600
- +#define LOWPORT 512
- +#define ENDPORT (IPPORT_RESERVED - 1)
- +#define NPORTS (ENDPORT - STARTPORT + 1)
- int
- bindresvport_sa(int sd, struct sockaddr *sa)
- {
- - fprintf(stderr, "Do-nothing bindresvport_sa!\n");
- + int ioctlres;
- + int lasterr;
- + SOCKET sd_sock;
- + int currport;
- +
- + INET_PORT_RANGE portRange;
- + INET_PORT_RESERVATION_INSTANCE portRes;
- + DWORD bytesReturned;
- +
- + sd_sock = _get_osfhandle(sd);
- +
- + for (currport = 600 ; currport < ENDPORT ; currport++) {
- + (void)memset(&portRange, 0, sizeof(portRange));
- + portRange.StartPort = htons(currport);
- + portRange.NumberOfPorts = 1;
- +
- + (void)memset(&portRes, 0, sizeof(portRes));
- + bytesReturned = 0;
- +
- + (void)fprintf(stderr, "bindresvport_sa(sd=%d,sa=0x%p): "
- + "trying port=%d ...\n",
- + sd, sa, (int)ntohs(portRange.StartPort));
- + ioctlres = WSAIoctl(sd_sock, SIO_ACQUIRE_PORT_RESERVATION,
- + (LPVOID)&portRange, sizeof(INET_PORT_RANGE),
- + (LPVOID)&portRes, sizeof(INET_PORT_RESERVATION_INSTANCE),
- + &bytesReturned, NULL, NULL);
- + lasterr = WSAGetLastError();
- +
- + if ((ioctlres != 0) && (lasterr == WSAEADDRINUSE)) {
- + (void)fprintf(stderr, "bindresvport_sa(sd=%d,sa=0x%p): "
- + "port=%d in use, trying next port...\n",
- + sd, sa, currport);
- + continue;
- + }
- +
- + if (ioctlres != 0) {
- + warnx("bindresvport_sa(sd=%d,sa=0x%p): "
- + "SIO_ACQUIRE_PORT_RESERVATION failed with "
- + "error = %d\n",
- + sd, sa, lasterr);
- + return 1;
- + }
- +
- + /* Success */
- + break;
- + }
- +
- + /* fixme: What if the loop completed ? */
- +
- + (void)fprintf(stderr, "bindresvport_sa(sd=%d,sa=0x%p): "
- + "SIO_ACQUIRE_PORT_RESERVATION succeeded, "
- + "bytesReturned = %u, StartPort=%d, NumberOfPorts=%d, "
- + "Token=%llx\n",
- + sd, sa, bytesReturned, (int)ntohs(portRes.StartPort),
- + portRes.NumberOfPorts, (long long)portRes.Token);
- +
- + bytesReturned = 0;
- + ioctlres = WSAIoctl(sd_sock, SIO_ASSOCIATE_PORT_RESERVATION,
- + (LPVOID)&portRes.Token, sizeof(ULONG64), NULL, 0,
- + &bytesReturned, NULL, NULL);
- + lasterr = WSAGetLastError();
- + if (ioctlres != 0) {
- + (void)fprintf(stderr, "bindresvport_sa(sd=%d,sa=0x%p): "
- + "WSAIoctl(SIO_ASSOCIATE_PORT_RESERVATION) "
- + "failed with error = %d\n",
- + sd, sa, lasterr);
- + return 1;
- + }
- +
- + (void)fprintf(stderr, "bindresvport_sa(sd=%d,sa=0x%p): "
- + "WSAIoctl(SIO_ASSOCIATE_PORT_RESERVATION) succeeded, bytesReturned = %u\n",
- + sd, sa, bytesReturned);
- +
- return 0;
- }
- #else
- --------------------------*/
- +
- #define IP_PORTRANGE 19
- #define IP_PORTRANGE_LOW 2
- diff --git a/libtirpc/src/clnt_dg.c b/libtirpc/src/clnt_dg.c
- index de318e6..801cf20 100644
- --- a/libtirpc/src/clnt_dg.c
- +++ b/libtirpc/src/clnt_dg.c
- @@ -275,7 +275,7 @@ clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz)
- cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
- /* XXX fvdl - do we still want this? */
- -#if 0
- +#if 1
- (void)bindresvport_sa(fd, (struct sockaddr *)svcaddr->buf);
- #endif
- #ifdef IP_RECVERR
Windows |bindresvport_()| prototype
Posted by Anonymous on Tue 26th Mar 2024 11:29
raw | new post
view followups (newest first): Windows |bindresvport_()| prototype by Anonymous
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.