Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

setsockopt IPPROTO_IP IP_OPTIONS

1,244 views
Skip to first unread message

Frank...@att.net

unread,
Apr 21, 2005, 3:04:56 PM4/21/05
to
The socket API theoretically supports:

SOCKET sock;
char options[8];
setsockopt(sock, IPPROTO_IP, IP_OPTIONS, options, sizeof(options));

However, having invoked the above setsockopt, no other socket related
function succeeds, all failing with code 10022 (invalid parameter).

If one performs a "bind" before attempting the above "setsockopt", the
"bind" succeeds, and then the "setsockopt" fails with 10022.

The functionality of setting the data to send in the IP packet header
works just fine under Solaris and Linux, but apparently not under any
flavor of Windows.

Any workarounds?

Thanks.

Eugene Gershnik

unread,
Apr 21, 2005, 4:57:43 PM4/21/05
to
Frank...@att.net wrote:
> The socket API theoretically supports:
>
> SOCKET sock;
> char options[8];
> setsockopt(sock, IPPROTO_IP, IP_OPTIONS, options, sizeof(options));

Keep in mind that according to
http://msdn.microsoft.com/library/en-us/winsock/winsock/ipproto_ip_socket_options.asp
support for this is not required.

> However, having invoked the above setsockopt, no other socket related
> function succeeds, all failing with code 10022 (invalid parameter).
>
> If one performs a "bind" before attempting the above "setsockopt", the
> "bind" succeeds, and then the "setsockopt" fails with 10022.

What options do you set there?

> The functionality of setting the data to send in the IP packet header
> works just fine under Solaris and Linux, but apparently not under any
> flavor of Windows.
>
> Any workarounds?

Maybe this will help
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q257460


--
Eugene
www.gershnik.com


Alan J. McFarlane

unread,
Apr 25, 2005, 7:01:16 AM4/25/05
to
In article news:OaP5DTr...@TK2MSFTNGP15.phx.gbl, Eugene Gershnik
wrote:

> Frank...@att.net wrote:
>> The socket API theoretically supports:
>>
>> SOCKET sock;
>> char options[8];
>> setsockopt(sock, IPPROTO_IP, IP_OPTIONS, options, sizeof(options));
>
> Keep in mind that according to
> http://msdn.microsoft.com/library/en-us/winsock/winsock/ipproto_ip_socket_options.asp
> support for this is not required.
>
>> However, having invoked the above setsockopt, no other socket related
>> function succeeds, all failing with code 10022 (invalid parameter).
>>
I've just tested my old IP Options test program, and it works ok in XP
(SP2), and worked previously on Windows 2000.

This code:
struct
{
unsigned char oCode;
unsigned char oLen;
unsigned char oOffset;
unsigned long oAddrs[9];
} xIpOption2;

ZeroMemory ( &xIpOption2, sizeof xIpOption2 );
xIpOption2.oCode = 0x07;
xIpOption2.oLen = 39;
xIpOption2.oOffset = 4;

xRet = setsockopt ( xSock, IPPROTO_IP, IP_OPTIONS,
(char*)&xIpOption2, xIpOption2.oLen );
if ( xRet == SOCKET_ERROR )
{
ReportWSErrorNoExit ( "sso:IP_OPTIONS SOCKET_ERROR" );
}

produced this packet:

Network Monitor trace Mon 04/25/05 11:38:54 Captur 1.txt

Frame Time Src MAC Addr Dst MAC Addr Protocol
Description Src Other Addr Dst Other Addr Type Other
Addr

5 13.624023 LOCAL router UDP Src
Port: Unknown, (1480); Dst Port: Unknown (999 gimlet 192.0.2.99
+ Frame: Base frame properties
+ ETHERNET: ETYPE = 0x0800 : Protocol = IP: DOD Internet Protocol
IP: ID = 0x32BC; Proto = UDP; Len: 128
IP: Version = 4 (0x4)
IP: Header Length = 60 (0x3C)
IP: Precedence = Routine
IP: Type of Service = Normal Service
IP: Total Length = 128 (0x80)
IP: Identification = 12988 (0x32BC)
+ IP: Flags Summary = 0 (0x0)
IP: Fragment Offset = 0 (0x0) bytes
IP: Time to Live = 128 (0x80)
IP: Protocol = UDP - User Datagram
IP: Checksum = 0x6E1A
IP: Source Address = 192.168.1.100
IP: Destination Address = 192.0.2.99
IP: Option Fields
IP: Record Route Option
IP: Option Type = Record Route
IP: Option Length = 39 (0x27)
IP: Next Slot Pointer = 4 (0x4)
IP: Route Traveled
IP: Gateway = 0.0.0.0
IP: Gateway = 0.0.0.0
IP: Gateway = 0.0.0.0
IP: Gateway = 0.0.0.0
IP: Gateway = 0.0.0.0
IP: Gateway = 0.0.0.0
IP: Gateway = 0.0.0.0
IP: Gateway = 0.0.0.0
IP: Gateway = 0.0.0.0
IP: End of Options = 0 (0x0)
IP: Data: Number of data bytes remaining = 68 (0x0044)
+ UDP: Src Port: Unknown, (1480); Dst Port: Unknown (9999); Length =
68 (0x44)

The error-ing behaviour has apparently changed somewhat from 2000 to XP
though. For an apparenly unacceptable Option array, XP gives 10022 on
the setsocktopt, whereas 2000 errored only on the sendto.

>> If one performs a "bind" before attempting the above "setsockopt",
>> the "bind" succeeds, and then the "setsockopt" fails with 10022.
>>
> What options do you set there?
>
>> The functionality of setting the data to send in the IP packet header
>> works just fine under Solaris and Linux, but apparently not under any
>> flavor of Windows.
>>
>> Any workarounds?
>>
> Maybe this will help
> http://support.microsoft.com/default.aspx?scid=kb;en-us;Q257460
>
--

Alan J. McFarlane
http://www.alanjmcf.me.uk/
Please follow-up in the newsgroup for the benefit of all.


Frank...@att.net

unread,
Apr 25, 2005, 4:46:17 PM4/25/05
to
Do I understand you correctly that although the setsockopt is failing
with 10022, the IP Options that you specified actually take effect? So
that a sendto subsequent to the failed setsockopt actually contains the
IP Options specified in the failed setsockopt?

Thanks for your time.

Frank...@att.net

unread,
Apr 25, 2005, 7:34:40 PM4/25/05
to
I reread your message, understood it better, and inserted your test IP
options into my test program. It works just fine, with a packet capture
to prove it. Many, many thanks. I owe you!

0 new messages