SetSockOpt.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Set the socket options
Copyright (c) 2011, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <Uefi.h>
#include <unistd.h>
#include <Library/DebugLib.h>
typedef enum _DATA_TYPE {
DATA_TYPE_UNKNOWN = 0,
} DATA_TYPE;
typedef struct {
char * pOptionName;
int OptionValue;
int OptionLevel;
} OPTIONS;
};
char * mSocketType[] = {
"SOCK_STREAM",
"SOCK_DGRAM",
"SOCK_RAW",
"SOCK_RDM",
"SOCK_SEQPACKET"
};
void
)
{
char * pString;
union {
} Value;
//
// Display the value length
//
if ( !bDisplayUpdate ) {
}
else {
Print ( L" --> " );
}
//
// Display the value
//
case DATA_TYPE_UNKNOWN:
}
break;
case DATA_TYPE_INT32_DECIMAL:
if ( 4 == LengthInBytes ) {
}
else {
}
break;
case DATA_TYPE_SOCKET_TYPE:
if ( 4 == LengthInBytes ) {
}
else {
}
}
else {
}
break;
case DATA_TYPE_TIMEVAL:
Print ( L"Infinite" );
}
else {
Print ( L"%d.%06d sec",
}
}
else {
}
break;
}
//
// Terminate the line
//
if ( bDisplayCrLf ) {
Print ( L"\r\n" );
}
}
char * pValue
)
{
union {
} Value;
int Values;
//
// Assume failure
//
BytesToWrite = 0;
//
// Determine the type of parameter
//
if ( pOption->bSetAllowed ) {
case DATA_TYPE_INT32_DECIMAL:
if ( 1 == Values ) {
errno = 0;
}
break;
case DATA_TYPE_TIMEVAL:
if (( 2 == Values )
errno = 0;
}
}
}
//
// Display the error
//
if ( 0 == BytesToWrite ) {
Print ( L"ERROR - Invalid value!\r\n" );
}
//
// Return the number of bytes to be written
//
return BytesToWrite;
}
/**
Set the socket options
@param [in] Argc The number of arguments
@param [in] Argv The argument value array
@retval 0 The application exited normally.
@retval Other An error occurred.
**/
int
main (
)
{
int s;
int Status;
DEBUG (( DEBUG_INFO,
"%a starting\r\n",
Argv[0]));
//
// Parse the socket option
//
if ( 2 <= Argc ) {
break;
}
pOption += 1;
}
Argc = 1;
}
}
//
// Display the help if necessary
//
Print ( L"\r\n" );
Print ( L"Option one of:\r\n" );
Print ( L" %a: %a\r\n",
pOption += 1;
}
}
else {
//
// Determine if the value is to be set
//
BytesToWrite = 0;
if (( 3 > Argc )
//
// Get the socket
//
if ( -1 == s ) {
}
else {
//
// Display the option value
//
LengthInBytes = sizeof ( mBuffer );
Status = getsockopt ( s,
&mBuffer,
&LengthInBytes );
if ( -1 == Status ) {
}
else {
(BOOLEAN)( 0 == BytesToWrite ));
//
// Determine if the value is to be set
//
if (( 0 < BytesToWrite )
&& ( BytesToWrite == LengthInBytes )) {
//
// Set the option value
//
Status = setsockopt ( s,
&mValue,
BytesToWrite );
if ( -1 == Status ) {
}
else {
//
// Display the updated option value
//
Status = getsockopt ( s,
&mBuffer,
&LengthInBytes );
if ( -1 == Status ) {
}
else {
TRUE,
TRUE );
}
}
}
}
//
// Done with the socket
//
close ( s );
}
}
}
//
// All done
//
DEBUG (( DEBUG_INFO,
"%a exiting, errno: %d\r\n",
Argv[0],
errno ));
return errno;
}