Skip to content

Commit 6b8a762

Browse files
committed
[MSWSOCK]
- Implement WSPSetSockOpt (copied and modified from WSPGetSockOpt) - DHCP works now svn path=/branches/aicom-network-branch/; revision=48496
1 parent 9c5e94e commit 6b8a762

File tree

1 file changed

+134
-19
lines changed

1 file changed

+134
-19
lines changed

dll/win32/mswsock/msafd/sockopt.c

Lines changed: 134 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ WSPSetSockOpt(IN SOCKET Handle,
517517
PSOCKET_INFORMATION Socket;
518518
INT ErrorCode;
519519
PWINSOCK_TEB_DATA ThreadData;
520-
520+
521521
/* Enter prolog */
522522
ErrorCode = SockEnterApiFast(&ThreadData);
523523
if (ErrorCode != NO_ERROR)
@@ -526,7 +526,7 @@ WSPSetSockOpt(IN SOCKET Handle,
526526
*lpErrno = ErrorCode;
527527
return SOCKET_ERROR;
528528
}
529-
529+
530530
/* Get the socket structure */
531531
Socket = SockFindAndReferenceSocket(Handle, TRUE);
532532
if (!Socket)
@@ -535,55 +535,170 @@ WSPSetSockOpt(IN SOCKET Handle,
535535
*lpErrno = WSAENOTSOCK;
536536
return SOCKET_ERROR;
537537
}
538-
538+
539539
/* Lock the socket */
540540
EnterCriticalSection(&Socket->Lock);
541-
541+
542542
/* Make sure we're not closed */
543543
if (Socket->SharedData.State == SocketClosed)
544544
{
545545
/* Fail */
546546
ErrorCode = WSAENOTSOCK;
547547
goto error;
548548
}
549-
549+
550550
/* Validate the pointer */
551551
if (!OptionValue)
552552
{
553553
/* Fail */
554554
ErrorCode = WSAEFAULT;
555555
goto error;
556556
}
557-
557+
558558
/* Validate option */
559559
if (!IsValidOptionForSocket(Socket, Level, OptionName))
560560
{
561561
/* Fail */
562562
ErrorCode = WSAENOPROTOOPT;
563563
goto error;
564564
}
565-
566-
/* FIXME: Write code */
567-
565+
566+
/* Check the Level first */
567+
switch (Level)
568+
{
569+
/* Handle SOL_SOCKET */
570+
case SOL_SOCKET:
571+
572+
/* Now check the Option */
573+
switch (OptionName)
574+
{
575+
case SO_RCVBUF:
576+
577+
/* Validate the size */
578+
if (OptionLength < sizeof(INT))
579+
{
580+
/* Size is too small, fail */
581+
ErrorCode = WSAEFAULT;
582+
goto error;
583+
}
584+
585+
/* Set the data */
586+
Socket->SharedData.SizeOfRecvBuffer = *(PINT)OptionValue;
587+
588+
/* FIXME: Tell AFD */
589+
break;
590+
591+
case SO_SNDBUF:
592+
593+
/* Validate the size */
594+
if (OptionLength < sizeof(INT))
595+
{
596+
/* Size is too small, fail */
597+
ErrorCode = WSAEFAULT;
598+
goto error;
599+
}
600+
601+
/* Set the data */
602+
Socket->SharedData.SizeOfSendBuffer = *(PINT)OptionValue;
603+
604+
/* FIXME: Tell AFD */
605+
break;
606+
607+
case SO_BROADCAST:
608+
609+
/* Validate the size */
610+
if (OptionLength < sizeof(INT))
611+
{
612+
/* Size is too small, fail */
613+
ErrorCode = WSAEFAULT;
614+
goto error;
615+
}
616+
617+
/* Set the data */
618+
Socket->SharedData.Broadcast = *(PINT)OptionValue;
619+
break;
620+
621+
case SO_DEBUG:
622+
623+
/* Validate the size */
624+
if (OptionLength < sizeof(INT))
625+
{
626+
/* Size is too small, fail */
627+
ErrorCode = WSAEFAULT;
628+
goto error;
629+
}
630+
631+
/* Set the data */
632+
Socket->SharedData.Debug = *(PINT)OptionValue;
633+
break;
634+
635+
case SO_CONDITIONAL_ACCEPT:
636+
case SO_DONTLINGER:
637+
case SO_DONTROUTE:
638+
case SO_ERROR:
639+
case SO_GROUP_PRIORITY:
640+
case SO_KEEPALIVE:
641+
case SO_LINGER:
642+
case SO_OOBINLINE:
643+
case SO_REUSEADDR:
644+
645+
/* Unsupported */
646+
647+
default:
648+
649+
/* Unsupported by us, give it to the helper */
650+
ErrorCode = SockGetTdiHandles(Socket);
651+
if (ErrorCode != NO_ERROR) goto error;
652+
653+
/* Call the helper */
654+
ErrorCode = Socket->HelperData->WSHSetSocketInformation(Socket->HelperContext,
655+
Handle,
656+
Socket->TdiAddressHandle,
657+
Socket->TdiConnectionHandle,
658+
Level,
659+
OptionName,
660+
(PCHAR)OptionValue,
661+
OptionLength);
662+
if (ErrorCode != NO_ERROR) goto error;
663+
break;
664+
}
665+
break;
666+
667+
default:
668+
669+
/* Unsupported by us, give it to the helper */
670+
ErrorCode = SockGetTdiHandles(Socket);
671+
if (ErrorCode != NO_ERROR) goto error;
672+
673+
/* Call the helper */
674+
ErrorCode = Socket->HelperData->WSHSetSocketInformation(Socket->HelperContext,
675+
Handle,
676+
Socket->TdiAddressHandle,
677+
Socket->TdiConnectionHandle,
678+
Level,
679+
OptionName,
680+
(PCHAR)OptionValue,
681+
OptionLength);
682+
if (ErrorCode != NO_ERROR) goto error;
683+
break;
684+
}
685+
568686
error:
569-
687+
/* Dereference and unlock the socket */
688+
LeaveCriticalSection(&Socket->Lock);
689+
SockDereferenceSocket(Socket);
690+
570691
/* Check if this is the failure path */
571692
if (ErrorCode != NO_ERROR)
572693
{
573-
/* Dereference and unlock the socket */
574-
LeaveCriticalSection(&Socket->Lock);
575-
SockDereferenceSocket(Socket);
576-
577694
/* Return error */
578695
*lpErrno = ErrorCode;
579696
return SOCKET_ERROR;
580697
}
581-
698+
582699
/* Update the socket's state in AFD */
583700
ErrorCode = SockSetHandleContext(Socket);
584-
if (ErrorCode != NO_ERROR) goto error;
585-
701+
586702
/* Return success */
587-
return NO_ERROR;
703+
return ErrorCode;
588704
}
589-

0 commit comments

Comments
 (0)