summaryrefslogblamecommitdiffstats
path: root/private/ntos/afd/bind.c
blob: ac799bfde270237d225cc3a0f68314f14f800376 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828



























































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                  
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    bind.c

Abstract:

    Contains AfdBind for binding an endpoint to a transport address.

Author:

    David Treadwell (davidtr)    25-Feb-1992

Revision History:

--*/

#include "afdp.h"

NTSTATUS
AfdRestartGetAddress (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp,
    IN PVOID Context
    );

#ifdef ALLOC_PRAGMA
#pragma alloc_text( PAGE, AfdBind )
#pragma alloc_text( PAGE, AfdGetAddress )
#pragma alloc_text( PAGEAFD, AfdAreTransportAddressesEqual )
#pragma alloc_text( PAGEAFD, AfdRestartGetAddress )
#endif


NTSTATUS
AfdBind (
    IN PIRP Irp,
    IN PIO_STACK_LOCATION IrpSp
    )

/*++

Routine Description:

    Handles the IOCTL_AFD_BIND IOCTL.

Arguments:

    Irp - Pointer to I/O request packet.

    IrpSp - pointer to the IO stack location to use for this request.

Return Value:

    NTSTATUS -- Indicates whether the request was successfully queued.

--*/

{
    NTSTATUS status;
    OBJECT_ATTRIBUTES objectAttributes;
    IO_STATUS_BLOCK iosb;

    PTRANSPORT_ADDRESS transportAddress;
    PTRANSPORT_ADDRESS requestedAddress;
    ULONG requestedAddressLength;
    PAFD_ENDPOINT endpoint;

    PFILE_FULL_EA_INFORMATION ea;
    ULONG eaBufferLength;

    PAGED_CODE( );

    //
    // Set up local pointers.
    //

    requestedAddress = Irp->AssociatedIrp.SystemBuffer;
    requestedAddressLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
    endpoint = IrpSp->FileObject->FsContext;
    ASSERT( IS_AFD_ENDPOINT_TYPE( endpoint ) );

    //
    // Bomb off if this is a helper endpoint.
    //

    if ( endpoint->Type == AfdBlockTypeHelper ) {
        return STATUS_INVALID_PARAMETER;
    }

    //
    // If the client wants a unique address, make sure that there are no
    // other sockets with this address.

    ExAcquireResourceExclusive( AfdResource, TRUE );

    if ( IrpSp->Parameters.DeviceIoControl.OutputBufferLength != 0 ) {

        PLIST_ENTRY listEntry;

        //
        // Walk the global list of endpoints,
        // and compare this address againat the address on each endpoint.
        //

        for ( listEntry = AfdEndpointListHead.Flink;
              listEntry != &AfdEndpointListHead;
              listEntry = listEntry->Flink ) {

            PAFD_ENDPOINT compareEndpoint;

            compareEndpoint = CONTAINING_RECORD(
                                  listEntry,
                                  AFD_ENDPOINT,
                                  GlobalEndpointListEntry
                                  );

            ASSERT( IS_AFD_ENDPOINT_TYPE( compareEndpoint ) );

            //
            // Check whether the endpoint has a local address, whether
            // the endpoint has been disconnected, and whether the
            // endpoint is in the process of closing.  If any of these
            // is true, don't compare addresses with this endpoint.
            //

            if ( compareEndpoint->LocalAddress != NULL &&
                     ( (compareEndpoint->DisconnectMode &
                            (AFD_PARTIAL_DISCONNECT_SEND |
                             AFD_ABORTIVE_DISCONNECT) ) == 0 ) &&
                     (compareEndpoint->State != AfdEndpointStateClosing) ) {

                //
                // Compare the bits in the endpoint's address and the
                // address we're attempting to bind to.  Note that we
                // also compare the transport device names on the
                // endpoints, as it is legal to bind to the same address
                // on different transports (e.g.  bind to same port in
                // TCP and UDP).  We can just compare the transport
                // device name pointers because unique names are stored
                // globally.
                //

                if ( compareEndpoint->LocalAddressLength ==
                         IrpSp->Parameters.DeviceIoControl.InputBufferLength

                     &&

                     AfdAreTransportAddressesEqual(
                         compareEndpoint->LocalAddress,
                         compareEndpoint->LocalAddressLength,
                         requestedAddress,
                         requestedAddressLength,
                         FALSE
                         )

                     &&

                     endpoint->TransportInfo ==
                         compareEndpoint->TransportInfo ) {

                    //
                    // The addresses are equal.  Fail the request.
                    //

                    ExReleaseResource( AfdResource );

                    Irp->IoStatus.Information = 0;
                    Irp->IoStatus.Status = STATUS_SHARING_VIOLATION;

                    return STATUS_SHARING_VIOLATION;
                }
            }
        }
    }

    //
    // Store the address to which the endpoint is bound.
    //

    endpoint->LocalAddress = AFD_ALLOCATE_POOL(
                                 NonPagedPool,
                                 requestedAddressLength,
                                 AFD_LOCAL_ADDRESS_POOL_TAG
                                 );

    if ( endpoint->LocalAddress == NULL ) {

        ExReleaseResource( AfdResource );

        Irp->IoStatus.Information = 0;
        Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;

        return STATUS_INSUFFICIENT_RESOURCES;
    }

    endpoint->LocalAddressLength =
        IrpSp->Parameters.DeviceIoControl.InputBufferLength;

    RtlMoveMemory(
        endpoint->LocalAddress,
        requestedAddress,
        endpoint->LocalAddressLength
        );

    ExReleaseResource( AfdResource );

    //
    // Allocate memory to hold the EA buffer we'll use to specify the
    // transport address to NtCreateFile.
    //

    eaBufferLength = sizeof(FILE_FULL_EA_INFORMATION) - 1 +
                         TDI_TRANSPORT_ADDRESS_LENGTH + 1 +
                         IrpSp->Parameters.DeviceIoControl.InputBufferLength;

#if DBG
    ea = AFD_ALLOCATE_POOL(
             NonPagedPool,
             eaBufferLength,
             AFD_EA_POOL_TAG
             );
#else
    ea = AFD_ALLOCATE_POOL(
             PagedPool,
             eaBufferLength,
             AFD_EA_POOL_TAG
             );
#endif

    if ( ea == NULL ) {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    //
    // Initialize the EA.
    //

    ea->NextEntryOffset = 0;
    ea->Flags = 0;
    ea->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
    ea->EaValueLength = (USHORT)IrpSp->Parameters.DeviceIoControl.InputBufferLength;

    RtlMoveMemory(
        ea->EaName,
        TdiTransportAddress,
        ea->EaNameLength + 1
        );

    transportAddress = (PTRANSPORT_ADDRESS)(&ea->EaName[ea->EaNameLength + 1]);

    RtlMoveMemory(
        transportAddress,
        requestedAddress,
        ea->EaValueLength
        );

    //
    // Prepare for opening the address object.
    //

    InitializeObjectAttributes(
        &objectAttributes,
        &endpoint->TransportInfo->TransportDeviceName,
        OBJ_CASE_INSENSITIVE,       // attributes
        NULL,
        NULL
        );

    //
    // Perform the actual open of the address object.
    //

    KeAttachProcess( AfdSystemProcess );

    status = ZwCreateFile(
                 &endpoint->AddressHandle,
                 GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
                 &objectAttributes,
                 &iosb,                          // returned status information.
                 0,                              // block size (unused).
                 0,                              // file attributes.
                 FILE_SHARE_READ | FILE_SHARE_WRITE,
                 FILE_CREATE,                    // create disposition.
                 0,                              // create options.
                 ea,
                 eaBufferLength
                 );

    AFD_FREE_POOL(
        ea,
        AFD_EA_POOL_TAG
        );

    if ( !NT_SUCCESS(status) ) {

        //
        // We store the local address in a local before freeing it to
        // avoid a timing window.
        //

        PVOID localAddress = endpoint->LocalAddress;

        endpoint->LocalAddress = NULL;
        endpoint->LocalAddressLength = 0;
        AFD_FREE_POOL(
            localAddress,
            AFD_LOCAL_ADDRESS_POOL_TAG
            );

        KeDetachProcess( );

        return status;
    }

    AfdRecordAddrOpened();

    //
    // Get a pointer to the file object of the address.
    //

    status = ObReferenceObjectByHandle(
                 endpoint->AddressHandle,
                 0L,                         // DesiredAccess
                 NULL,
                 KernelMode,
                 (PVOID *)&endpoint->AddressFileObject,
                 NULL
                 );

    ASSERT( NT_SUCCESS(status) );

    AfdRecordAddrRef();

    IF_DEBUG(BIND) {
        KdPrint(( "AfdBind: address file object for endpoint %lx at %lx\n",
                      endpoint, endpoint->AddressFileObject ));
    }

    //
    // Remember the device object to which we need to give requests for
    // this address object.  We can't just use the
    // fileObject->DeviceObject pointer because there may be a device
    // attached to the transport protocol.
    //

    endpoint->AddressDeviceObject =
        IoGetRelatedDeviceObject( endpoint->AddressFileObject );

    //
    // Determine whether the TDI provider supports data bufferring.
    // If the provider doesn't, then we have to do it.
    //

    if ( (endpoint->TransportInfo->ProviderInfo.ServiceFlags &
             TDI_SERVICE_INTERNAL_BUFFERING) != 0 ) {
        endpoint->TdiBufferring = TRUE;
    } else {
        endpoint->TdiBufferring = FALSE;
    }

    //
    // Determine whether the TDI provider is message or stream oriented.
    //

    if ( (endpoint->TransportInfo->ProviderInfo.ServiceFlags &
             TDI_SERVICE_MESSAGE_MODE) != 0 ) {
        endpoint->TdiMessageMode = TRUE;
    } else {
        endpoint->TdiMessageMode = FALSE;
    }

    //
    // Remember that the endpoint has been bound to a transport address.
    //

    endpoint->State = AfdEndpointStateBound;

    //
    // Set up indication handlers on the address object.  Only set up
    // appropriate event handlers--don't set unnecessary event handlers.
    //

    status = AfdSetEventHandler(
                 endpoint->AddressFileObject,
                 TDI_EVENT_ERROR,
                 AfdErrorEventHandler,
                 endpoint
                 );
#if DBG
    if ( !NT_SUCCESS(status) ) {
        DbgPrint( "AFD: Setting TDI_EVENT_ERROR failed: %lx\n", status );
    }
#endif

    if ( IS_DGRAM_ENDPOINT(endpoint) ) {

        endpoint->EventsActive = AFD_POLL_SEND;

        IF_DEBUG(EVENT_SELECT) {
            KdPrint((
                "AfdBind: Endp %08lX, Active %08lX\n",
                endpoint,
                endpoint->EventsActive
                ));
        }

        status = AfdSetEventHandler(
                     endpoint->AddressFileObject,
                     TDI_EVENT_RECEIVE_DATAGRAM,
                     AfdReceiveDatagramEventHandler,
                     endpoint
                     );
#if DBG
        if ( !NT_SUCCESS(status) ) {
            DbgPrint( "AFD: Setting TDI_EVENT_RECEIVE_DATAGRAM failed: %lx\n", status );
        }
#endif

    } else {

        status = AfdSetEventHandler(
                     endpoint->AddressFileObject,
                     TDI_EVENT_DISCONNECT,
                     AfdDisconnectEventHandler,
                     endpoint
                     );
#if DBG
        if ( !NT_SUCCESS(status) ) {
            DbgPrint( "AFD: Setting TDI_EVENT_DISCONNECT failed: %lx\n", status );
        }
#endif

        if ( endpoint->TdiBufferring ) {

            status = AfdSetEventHandler(
                         endpoint->AddressFileObject,
                         TDI_EVENT_RECEIVE,
                         AfdReceiveEventHandler,
                         endpoint
                         );
#if DBG
            if ( !NT_SUCCESS(status) ) {
                DbgPrint( "AFD: Setting TDI_EVENT_RECEIVE failed: %lx\n", status );
            }
#endif

            status = AfdSetEventHandler(
                         endpoint->AddressFileObject,
                         TDI_EVENT_RECEIVE_EXPEDITED,
                         AfdReceiveExpeditedEventHandler,
                         endpoint
                         );
#if DBG
            if ( !NT_SUCCESS(status) ) {
                DbgPrint( "AFD: Setting TDI_EVENT_RECEIVE_EXPEDITED failed: %lx\n", status );
            }
#endif

            status = AfdSetEventHandler(
                         endpoint->AddressFileObject,
                         TDI_EVENT_SEND_POSSIBLE,
                         AfdSendPossibleEventHandler,
                         endpoint
                         );
#if DBG
            if ( !NT_SUCCESS(status) ) {
                DbgPrint( "AFD: Setting TDI_EVENT_SEND_POSSIBLE failed: %lx\n", status );
            }
#endif

        } else {

            status = AfdSetEventHandler(
                         endpoint->AddressFileObject,
                         TDI_EVENT_RECEIVE,
                         AfdBReceiveEventHandler,
                         endpoint
                         );
#if DBG
            if ( !NT_SUCCESS(status) ) {
                DbgPrint( "AFD: Setting TDI_EVENT_RECEIVE failed: %lx\n", status );
            }
#endif

            //
            // Only attempt to set the expedited event handler if the
            // TDI provider supports expedited data.
            //

            if ( (endpoint->TransportInfo->ProviderInfo.ServiceFlags &
                     TDI_SERVICE_EXPEDITED_DATA) != 0 ) {
                status = AfdSetEventHandler(
                             endpoint->AddressFileObject,
                             TDI_EVENT_RECEIVE_EXPEDITED,
                             AfdBReceiveExpeditedEventHandler,
                             endpoint
                             );
#if DBG
                if ( !NT_SUCCESS(status) ) {
                    DbgPrint( "AFD: Setting TDI_EVENT_RECEIVE_EXPEDITED failed: %lx\n", status );
                }
#endif
            }
        }
    }

    KeDetachProcess( );

    Irp->IoStatus.Information = 0;
    return STATUS_SUCCESS;

} // AfdBind


NTSTATUS
AfdGetAddress (
    IN PIRP Irp,
    IN PIO_STACK_LOCATION IrpSp
    )

/*++

Routine Description:

    Handles the IOCTL_AFD_BIND IOCTL.

Arguments:

    Irp - Pointer to I/O request packet.

    IrpSp - pointer to the IO stack location to use for this request.

Return Value:

    NTSTATUS -- Indicates whether the request was successfully queued.

--*/

{
    NTSTATUS status;
    PAFD_ENDPOINT endpoint;
    PFILE_OBJECT fileObject;
    PDEVICE_OBJECT deviceObject;

    PAGED_CODE( );

    Irp->IoStatus.Information = 0;

    //
    // Make sure that the endpoint is in the correct state.
    //

    endpoint = IrpSp->FileObject->FsContext;
    ASSERT( IS_AFD_ENDPOINT_TYPE( endpoint ) );

    if ( endpoint->AddressFileObject == NULL &&
             endpoint->State != AfdEndpointStateConnected ) {
        status = STATUS_INVALID_PARAMETER;
        goto complete;
    }

    //
    // If the endpoint is connected, use the connection's file object.
    // Otherwise, use the address file object.  Don't use the connection
    // file object if this is a Netbios endpoint because NETBT cannot
    // support this TDI feature.
    //

    if ( endpoint->Type == AfdBlockTypeVcConnecting &&
             endpoint->Common.VcConnecting.Connection != NULL &&
             endpoint->LocalAddress->Address[0].AddressType !=
                 TDI_ADDRESS_TYPE_NETBIOS ) {
        ASSERT( endpoint->Common.VcConnecting.Connection->Type == AfdBlockTypeConnection );
        fileObject = endpoint->Common.VcConnecting.Connection->FileObject;
        deviceObject = endpoint->Common.VcConnecting.Connection->DeviceObject;
    } else {
        fileObject = endpoint->AddressFileObject;
        deviceObject = endpoint->AddressDeviceObject;
    }

    //
    // Set up the query info to the TDI provider.
    //

    ASSERT( Irp->MdlAddress != NULL );

    TdiBuildQueryInformation(
        Irp,
        deviceObject,
        fileObject,
        AfdRestartGetAddress,
        endpoint,
        TDI_QUERY_ADDRESS_INFO,
        Irp->MdlAddress
        );

    //
    // Call the TDI provider to get the address.
    //

    return AfdIoCallDriver( endpoint, deviceObject, Irp );

complete:

    Irp->IoStatus.Status = status;
    IoCompleteRequest( Irp, AfdPriorityBoost );

    return status;

} // AfdGetAddress


NTSTATUS
AfdRestartGetAddress (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp,
    IN PVOID Context
    )
{
    NTSTATUS status;
    PAFD_ENDPOINT endpoint = Context;
    KIRQL oldIrql;
    PMDL mdl;
    ULONG addressLength;

    //
    // If the request succeeded, save the address in the endpoint so
    // we can use it to handle address sharing.
    //

    if ( NT_SUCCESS(Irp->IoStatus.Status) ) {

        //
        // First determine the length of the address by walking the MDL
        // chain.
        //

        mdl = Irp->MdlAddress;
        ASSERT( mdl != NULL );

        addressLength = 0;

        do {

            addressLength += MmGetMdlByteCount( mdl );
            mdl = mdl->Next;

        } while ( mdl != NULL  );

        AfdAcquireSpinLock( &AfdSpinLock, &oldIrql );

        //
        // If the new address is longer than the original address, allocate
        // a new local address buffer.  The +4 accounts for the ActivityCount
        // field that is returned by a query address but is not part
        // of a TRANSPORT_ADDRESS.
        //

        if ( addressLength > endpoint->LocalAddressLength + 4 ) {

            PVOID newAddress;

            newAddress = AFD_ALLOCATE_POOL(
                             NonPagedPool,
                             addressLength-4,
                             AFD_LOCAL_ADDRESS_POOL_TAG
                             );

            if ( newAddress == NULL ) {
                AfdReleaseSpinLock( &AfdSpinLock, oldIrql );
                return STATUS_INSUFFICIENT_RESOURCES;
            }

            AFD_FREE_POOL(
                endpoint->LocalAddress,
                AFD_LOCAL_ADDRESS_POOL_TAG
                );

            endpoint->LocalAddress = newAddress;
            endpoint->LocalAddressLength = addressLength-4;
        }

        status = TdiCopyMdlToBuffer(
                     Irp->MdlAddress,
                     4,
                     endpoint->LocalAddress,
                     0,
                     endpoint->LocalAddressLength,
                     &endpoint->LocalAddressLength
                     );
        ASSERT( NT_SUCCESS(status) );

        AfdReleaseSpinLock( &AfdSpinLock, oldIrql );
    }

    AfdCompleteOutstandingIrp( endpoint, Irp );

    //
    // If pending has been returned for this irp then mark the current
    // stack as pending.
    //

    if ( Irp->PendingReturned ) {
        IoMarkIrpPending( Irp );
    }

    return STATUS_SUCCESS;

} // AfdRestartGetAddress

CHAR ZeroNodeAddress[6];


BOOLEAN
AfdAreTransportAddressesEqual (
    IN PTRANSPORT_ADDRESS EndpointAddress,
    IN ULONG EndpointAddressLength,
    IN PTRANSPORT_ADDRESS RequestAddress,
    IN ULONG RequestAddressLength,
    IN BOOLEAN HonorWildcardIpPortInEndpointAddress
    )
{
    if ( EndpointAddress->Address[0].AddressType == TDI_ADDRESS_TYPE_IP &&
         RequestAddress->Address[0].AddressType == TDI_ADDRESS_TYPE_IP ) {

        TDI_ADDRESS_IP UNALIGNED *ipEndpointAddress;
        TDI_ADDRESS_IP UNALIGNED *ipRequestAddress;

        //
        // They are both IP addresses.  If the ports are the same, and
        // the IP addresses are or _could_be_ the same, then the addresses
        // are equal.  The "cound be" part is true if either IP address
        // is 0, the "wildcard" IP address.
        //

        ipEndpointAddress = (TDI_ADDRESS_IP UNALIGNED *)&EndpointAddress->Address[0].Address[0];
        ipRequestAddress = (TDI_ADDRESS_IP UNALIGNED *)&RequestAddress->Address[0].Address[0];

        if ( ( ipEndpointAddress->sin_port == ipRequestAddress->sin_port ||
               ( HonorWildcardIpPortInEndpointAddress &&
                 ipEndpointAddress->sin_port == 0 ) ) &&
             ( ipEndpointAddress->in_addr == ipRequestAddress->in_addr ||
               ipEndpointAddress->in_addr == 0 || ipRequestAddress->in_addr == 0 ) ) {

            return TRUE;
        }

        //
        // The addresses are not equal.
        //

        return FALSE;
    }

    if ( EndpointAddress->Address[0].AddressType == TDI_ADDRESS_TYPE_IPX &&
         RequestAddress->Address[0].AddressType == TDI_ADDRESS_TYPE_IPX ) {

        TDI_ADDRESS_IPX UNALIGNED *ipxEndpointAddress;
        TDI_ADDRESS_IPX UNALIGNED *ipxRequestAddress;

        ipxEndpointAddress = (TDI_ADDRESS_IPX UNALIGNED *)&EndpointAddress->Address[0].Address[0];
        ipxRequestAddress = (TDI_ADDRESS_IPX UNALIGNED *)&RequestAddress->Address[0].Address[0];

        //
        // They are both IPX addresses.  Check the network addresses
        // first--if they don't match and both != 0, the addresses
        // are different.
        //

        if ( ipxEndpointAddress->NetworkAddress != ipxRequestAddress->NetworkAddress &&
             ipxEndpointAddress->NetworkAddress != 0 &&
             ipxRequestAddress->NetworkAddress != 0 ) {
            return FALSE;
        }

        //
        // Now check the node addresses.  Again, if they don't match
        // and neither is 0, the addresses don't match.
        //

        ASSERT( ZeroNodeAddress[0] == 0 );
        ASSERT( ZeroNodeAddress[1] == 0 );
        ASSERT( ZeroNodeAddress[2] == 0 );
        ASSERT( ZeroNodeAddress[3] == 0 );
        ASSERT( ZeroNodeAddress[4] == 0 );
        ASSERT( ZeroNodeAddress[5] == 0 );

        if ( !RtlEqualMemory(
                 ipxEndpointAddress->NodeAddress,
                 ipxRequestAddress->NodeAddress,
                 6 ) &&
             !RtlEqualMemory(
                 ipxEndpointAddress->NodeAddress,
                 ZeroNodeAddress,
                 6 ) &&
             !RtlEqualMemory(
                 ipxRequestAddress->NodeAddress,
                 ZeroNodeAddress,
                 6 ) ) {
            return FALSE;
        }

        //
        // Finally, make sure the socket numbers match.
        //

        if ( ipxEndpointAddress->Socket != ipxRequestAddress->Socket ) {
            return FALSE;
        }

        return TRUE;

    }

    //
    // If either address is not of a known address type, then do a
    // simple memory compare.
    //

    return ( EndpointAddressLength == RtlCompareMemory(
                                   EndpointAddress,
                                   RequestAddress,
                                   RequestAddressLength ) );
} // AfdAreTransportAddressesEqual