Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenif.c
Go to the documentation of this file.
00001 00002 #include "precomp.h" 00003 00004 #include "lwip/pbuf.h" 00005 #include "lwip/netifapi.h" 00006 #include "lwip/ip.h" 00007 #include "lwip/api.h" 00008 #include "lwip/tcpip.h" 00009 00010 err_t 00011 TCPSendDataCallback(struct netif *netif, struct pbuf *p, struct ip_addr *dest) 00012 { 00013 NDIS_STATUS NdisStatus; 00014 PNEIGHBOR_CACHE_ENTRY NCE; 00015 IP_PACKET Packet; 00016 IP_ADDRESS RemoteAddress, LocalAddress; 00017 PIPv4_HEADER Header; 00018 00019 /* The caller frees the pbuf struct */ 00020 00021 if (((*(u8_t*)p->payload) & 0xF0) == 0x40) 00022 { 00023 Header = p->payload; 00024 00025 LocalAddress.Type = IP_ADDRESS_V4; 00026 LocalAddress.Address.IPv4Address = Header->SrcAddr; 00027 00028 RemoteAddress.Type = IP_ADDRESS_V4; 00029 RemoteAddress.Address.IPv4Address = Header->DstAddr; 00030 } 00031 else 00032 { 00033 return ERR_IF; 00034 } 00035 00036 IPInitializePacket(&Packet, LocalAddress.Type); 00037 00038 if (!(NCE = RouteGetRouteToDestination(&RemoteAddress))) 00039 { 00040 return ERR_RTE; 00041 } 00042 00043 NdisStatus = AllocatePacketWithBuffer(&Packet.NdisPacket, NULL, p->tot_len); 00044 if (NdisStatus != NDIS_STATUS_SUCCESS) 00045 { 00046 return ERR_MEM; 00047 } 00048 00049 GetDataPtr(Packet.NdisPacket, 0, (PCHAR*)&Packet.Header, &Packet.TotalSize); 00050 Packet.MappedHeader = TRUE; 00051 00052 ASSERT(p->tot_len == p->len); 00053 ASSERT(Packet.TotalSize == p->len); 00054 00055 RtlCopyMemory(Packet.Header, p->payload, p->len); 00056 00057 Packet.HeaderSize = sizeof(IPv4_HEADER); 00058 Packet.TotalSize = p->tot_len; 00059 Packet.SrcAddr = LocalAddress; 00060 Packet.DstAddr = RemoteAddress; 00061 00062 NdisStatus = IPSendDatagram(&Packet, NCE); 00063 if (!NT_SUCCESS(NdisStatus)) 00064 return ERR_RTE; 00065 00066 return 0; 00067 } 00068 00069 VOID 00070 TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF) 00071 { 00072 #if 0 00073 ULONG OperationalStatus; 00074 00075 GetInterfaceConnectionStatus(IF, &OperationalStatus); 00076 00077 if (OperationalStatus == MIB_IF_OPER_STATUS_OPERATIONAL) 00078 netif_set_link_up(IF->TCPContext); 00079 else 00080 netif_set_link_down(IF->TCPContext); 00081 #endif 00082 } 00083 00084 err_t 00085 TCPInterfaceInit(struct netif *netif) 00086 { 00087 PIP_INTERFACE IF = netif->state; 00088 00089 netif->hwaddr_len = IF->AddressLength; 00090 RtlCopyMemory(netif->hwaddr, IF->Address, netif->hwaddr_len); 00091 00092 netif->output = TCPSendDataCallback; 00093 netif->mtu = IF->MTU; 00094 00095 netif->name[0] = 'e'; 00096 netif->name[1] = 'n'; 00097 00098 netif->flags |= NETIF_FLAG_BROADCAST; 00099 00100 TCPUpdateInterfaceLinkStatus(IF); 00101 00102 TCPUpdateInterfaceIPInformation(IF); 00103 00104 return 0; 00105 } 00106 00107 VOID 00108 TCPRegisterInterface(PIP_INTERFACE IF) 00109 { 00110 struct ip_addr ipaddr; 00111 struct ip_addr netmask; 00112 struct ip_addr gw; 00113 00114 gw.addr = 0; 00115 ipaddr.addr = 0; 00116 netmask.addr = 0; 00117 00118 IF->TCPContext = netif_add(IF->TCPContext, 00119 &ipaddr, 00120 &netmask, 00121 &gw, 00122 IF, 00123 TCPInterfaceInit, 00124 tcpip_input); 00125 } 00126 00127 VOID 00128 TCPUnregisterInterface(PIP_INTERFACE IF) 00129 { 00130 netif_remove(IF->TCPContext); 00131 } 00132 00133 VOID 00134 TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF) 00135 { 00136 struct ip_addr ipaddr; 00137 struct ip_addr netmask; 00138 struct ip_addr gw; 00139 00140 gw.addr = 0; 00141 00142 GetInterfaceIPv4Address(IF, 00143 ADE_UNICAST, 00144 (PULONG)&ipaddr.addr); 00145 00146 GetInterfaceIPv4Address(IF, 00147 ADE_ADDRMASK, 00148 (PULONG)&netmask.addr); 00149 00150 netif_set_addr(IF->TCPContext, &ipaddr, &netmask, &gw); 00151 00152 if (ipaddr.addr != 0) 00153 { 00154 netif_set_up(IF->TCPContext); 00155 netif_set_default(IF->TCPContext); 00156 } 00157 else 00158 { 00159 netif_set_down(IF->TCPContext); 00160 } 00161 } Generated on Sun May 27 2012 04:18:12 for ReactOS by
1.7.6.1
|