Mercurial > projects > hoofbaby
comparison deps/Platinum/ThirdParty/Neptune/Source/System/Xbox/NptXboxNetwork.cpp @ 0:3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
author | fraserofthenight |
---|---|
date | Mon, 06 Jul 2009 08:06:28 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3425707ddbf6 |
---|---|
1 /***************************************************************** | |
2 | | |
3 | Neptune - Network :: Xbox Winsock Implementation | |
4 | | |
5 | (c) 2001-2005 Gilles Boccon-Gibod | |
6 | Author: Gilles Boccon-Gibod (bok@bok.net) | |
7 | | |
8 ****************************************************************/ | |
9 | |
10 /*---------------------------------------------------------------------- | |
11 | includes | |
12 +---------------------------------------------------------------------*/ | |
13 #include <xtl.h> | |
14 #include <winsockx.h> | |
15 | |
16 #include "NptNetwork.h" | |
17 #include "NptXboxNetwork.h" | |
18 | |
19 /*---------------------------------------------------------------------- | |
20 | static initializer | |
21 +---------------------------------------------------------------------*/ | |
22 NPT_WinsockSystem::NPT_WinsockSystem() { | |
23 XNetStartupParams xnsp; | |
24 memset(&xnsp, 0, sizeof(xnsp)); | |
25 xnsp.cfgSizeOfStruct = sizeof(XNetStartupParams); | |
26 xnsp.cfgFlags = XNET_STARTUP_BYPASS_SECURITY; | |
27 | |
28 // create more memory for networking | |
29 xnsp.cfgPrivatePoolSizeInPages = 64; // == 256kb, default = 12 (48kb) | |
30 xnsp.cfgEnetReceiveQueueLength = 16; // == 32kb, default = 8 (16kb) | |
31 xnsp.cfgIpFragMaxSimultaneous = 16; // default = 4 | |
32 xnsp.cfgIpFragMaxPacketDiv256 = 32; // == 8kb, default = 8 (2kb) | |
33 xnsp.cfgSockMaxSockets = 64; // default = 64 | |
34 xnsp.cfgSockDefaultRecvBufsizeInK = 128; // default = 16 | |
35 xnsp.cfgSockDefaultSendBufsizeInK = 128; // default = 16 | |
36 | |
37 INT err = XNetStartup(&xnsp); | |
38 | |
39 WORD wVersionRequested; | |
40 WSADATA wsaData; | |
41 wVersionRequested = MAKEWORD(2, 2); | |
42 WSAStartup( wVersionRequested, &wsaData ); | |
43 } | |
44 NPT_WinsockSystem::~NPT_WinsockSystem() { | |
45 WSACleanup(); | |
46 XNetCleanup(); | |
47 } | |
48 NPT_WinsockSystem NPT_WinsockSystem::Initializer; | |
49 | |
50 /*---------------------------------------------------------------------- | |
51 | NPT_NetworkInterface::GetNetworkInterfaces | |
52 +---------------------------------------------------------------------*/ | |
53 NPT_Result | |
54 NPT_NetworkInterface::GetNetworkInterfaces(NPT_List<NPT_NetworkInterface*>& interfaces) | |
55 { | |
56 XNADDR xna; | |
57 DWORD state; | |
58 do { | |
59 state = XNetGetTitleXnAddr(&xna); | |
60 Sleep(100); | |
61 } while (state == XNET_GET_XNADDR_PENDING); | |
62 | |
63 if (state & XNET_GET_XNADDR_STATIC || state & XNET_GET_XNADDR_DHCP) { | |
64 NPT_IpAddress primary_address(ntohl(xna.ina.s_addr)); | |
65 NPT_IpAddress netmask; /* no support for netmask */ | |
66 NPT_IpAddress broadcast_address(ntohl(xna.ina.s_addr)); | |
67 NPT_Flags flags = NPT_NETWORK_INTERFACE_FLAG_BROADCAST; | |
68 | |
69 NPT_MacAddress mac; | |
70 if (state & XNET_GET_XNADDR_ETHERNET) { | |
71 mac.SetAddress(NPT_MacAddress::TYPE_ETHERNET, xna.abEnet, 6); | |
72 } | |
73 | |
74 // create an interface object | |
75 char iface_name[5]; | |
76 iface_name[0] = 'i'; | |
77 iface_name[1] = 'f'; | |
78 iface_name[2] = '0'; | |
79 iface_name[3] = '0'; | |
80 iface_name[4] = '\0'; | |
81 NPT_NetworkInterface* iface = new NPT_NetworkInterface(iface_name, mac, flags); | |
82 | |
83 // set the interface address | |
84 NPT_NetworkInterfaceAddress iface_address( | |
85 primary_address, | |
86 broadcast_address, | |
87 NPT_IpAddress::Any, | |
88 netmask); | |
89 iface->AddAddress(iface_address); | |
90 | |
91 // add the interface to the list | |
92 interfaces.Add(iface); | |
93 } | |
94 | |
95 return NPT_SUCCESS; | |
96 } | |
97 |