OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gt2.h
1/*
2GameSpy GT2 SDK
3Dan "Mr. Pants" Schoenblum
4dan@gamespy.com
5
6Copyright 2002 GameSpy Industries, Inc
7
8devsupport@gamespy.com
9*/
10
11/****************************
12** GameSpy Transport SDK 2 **
13****************************/
14
15/*
16** see "configurable defines" in gt2Main.h for certain performance settings that can be changed
17*/
18
19#ifndef _GT2_H_
20#define _GT2_H_
21
22#include "../common/gsCommon.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/**********
29** TYPES **
30**********/
31
32// boolean
33typedef int GT2Bool;
34#define GT2False 0
35#define GT2True 1
36
37// a byte
38typedef unsigned char GT2Byte;
39
40// a handle to a socket object (can be used to accept connections and initiate connections)
41typedef struct GTI2Socket * GT2Socket;
42
43// a handle to an object representing a connection to a specific IP and port
44// the local endpoint is a GT2Socket
45typedef struct GTI2Connection * GT2Connection;
46
47// the id of a reliably sent message
48// unreliable messages don't have ids
49typedef unsigned short GT2MessageID;
50
51// the result of a GT2 operation
52// check individual function definitions to see possible results
53// TODO: list possible results wherever this is used
54typedef enum
55{
56 GT2Success, // success
57 // errors:
58 GT2OutOfMemory, // ran out of memory
59 GT2Rejected, // attempt rejected
60 GT2NetworkError, // networking error (could be local or remote)
61 GT2AddressError, // invalid or unreachable address
62 GT2DuplicateAddress, // a connection was attempted to an address that already has a connection on the socket
63 GT2TimedOut, // time out reached
64 GT2NegotiationError, // there was an error negotiating with the remote side
65 GT2InvalidConnection, // the connection didn't exist
66 GT2InvalidMessage, // used for vdp reliable messages containing voice data, no voice data in reliable messages
67 GT2SendFailed // the send failed,
68} GT2Result;
69
70// possible states for any GT2Connection
71typedef enum
72{
73 GT2Connecting, // negotiating the connection
74 GT2Connected, // the connection is active
75 GT2Closing, // the connection is being closed
76 GT2Closed // the connection has been closed and can no longer be used
77} GT2ConnectionState;
78
79// The cause of the connection being closed.
80typedef enum
81{
82 GT2LocalClose, // The connection was closed with gt2CloseConnection.
83 GT2RemoteClose, // The connection was closed remotely.
84 // errors:
85 GT2CommunicationError, // An invalid message was received (it was either unexpected or wrongly formatted).
86 GT2SocketError, // An error with the socket forced the connection to close.
87 GT2NotEnoughMemory // There wasn't enough memory to store an incoming or outgoing message.
88} GT2CloseReason;
89
90/************
91** GLOBALS **
92************/
93
94// The challenge key is a 32 character string
95// that is used in the authentication process.
96// The key can be set before GT2 is used so
97// that the key will be application-specific.
98extern char GT2ChallengeKey[33];
99
100/*********************
101** SOCKET CALLBACKS **
102*********************/
103
104// this callback gets called when there was is an error that forces a socket to close
105// all connections that use this socket are terminated, and their gt2CloseCallback callbacks
106// will be called before this callback is called (with the reason set to GT2SocketError).
107// the socket cannot be used again after this callback returns
108typedef void (* gt2SocketErrorCallback)
109(
110 GT2Socket socket
111);
112
113/*********************
114** SOCKET FUNCTIONS **
115*********************/
116
117// creates a local socket
118// if the IP of the local address is 0, then any/all ips will be bound.
119// if the port of the local address is 0, then a port will be assigned.
120// if either buffer sizes is set to 0, a default value will be used (currently 64K for PC, 4k for Xbox).
121// the buffer needs to be able to hold all messages waiting for confirmation of delivery,
122// and it needs to hold any messages that arrive out of order. if either buffer runs out
123// of space the connection will be dropped.
124GT2Result gt2CreateSocket
125(
126 GT2Socket * socket, // if the result is GT2Success, the socket object handle will be stored at this address
127 const char * localAddress, // the local address to bind to
128 int outgoingBufferSize, // size of per-connection buffer where sent messages waiting to be confirmed are held, use 0 for default
129 int incomingBufferSize, // size of per-connection buffer where out-of-order received messages are held, use 0 for default
130 gt2SocketErrorCallback callback // a callback that is called if there is an error with the socket
131);
132
133// AdHoc Sockets use MAC address instead of IP address.
134GT2Result gt2CreateAdHocSocket
135(
136 GT2Socket * socket, // if the result is GT2Success, the socket object handle will be stored at this address
137 const char * localAddress, // the local address to bind to
138 int outgoingBufferSize, // size of per-connection buffer where sent messages waiting to be confirmed are held, use 0 for default
139 int incomingBufferSize, // size of per-connection buffer where out-of-order received messages are held, use 0 for default
140 gt2SocketErrorCallback callback // a callback that is called if there is an error with the socket
141);
142
143#ifdef _XBOX
144// creates a local VDP socket on the Xbox platform
145// if the IP of the local address is 0, then any/all ips will be bound.
146// if the port of the local address is 0, then a port will be assigned.
147// if either buffer sizes is set to 0, a default value will be used (currently 4K).
148// the buffer needs to be able to hold all messages waiting for confirmation of delivery,
149// and it needs to hold any messages that arrive out of order. if either buffer runs out
150// of space the connection will be dropped.
151GT2Result gt2CreateVDPSocket
152(
153 GT2Socket * socket, // if the result is GT2Success, the socket object handle will be stored at this address
154 const char * localAddress, // the local address to bind to
155 int outgoingBufferSize, // size of per-connection buffer where sent messages waiting to be confirmed are held, use 0 for default
156 int incomingBufferSize, // size of per-connection buffer where out-of-order received messages are held, use 0 for default
157 gt2SocketErrorCallback callback // a callback that is called if there is an error with the socket
158);
159#endif
160
161// closes a local socket.
162// all existing connections will be hard closed, as if gt2CloseAllConnectionsHard was
163// called for this socket. all connections send a close message to the remote side,
164// and any closed callbacks will be called from within this function
165void gt2CloseSocket(GT2Socket socket);
166
167// processes a socket (and all associated connections)
168void gt2Think(GT2Socket socket);
169
170// sends a raw UDP datagram through the socket
171// this function bypasses the normal connection logic
172// note that all messages sent this way will be unreliable
173// to broadcast a datagram, omit the IP from the remoteAddress (e.g., ":12345")
174GT2Result gt2SendRawUDP
175(
176 GT2Socket socket, // the socket through which to send the raw UDP datagram
177 const char * remoteAddress, // the address to which to send the datagram
178 const GT2Byte * message, // the message to send, or NULL for an empty datagram
179 int len // the len of the message (0 for an empty message, ignored if message==NULL)
180);
181
182/*************************
183** CONNECTION CALLBACKS **
184*************************/
185
186// Called when the connect has completed.
187// If the result is GT2Rejected,
188// then message is the message that the
189// listener passed to gt2Reject. If the
190// result is anything else, then message
191// is NULL and len is 0.
192typedef void (* gt2ConnectedCallback)
193(
194 GT2Connection connection, // The connection object.
195 GT2Result result, // Result from connect attempt.
196 GT2Byte * message, // If result==GT2Rejected, the reason. Otherwise, NULL.
197 int len // If result==GT2Rejected, the length of the reason. Otherwise, 0.
198);
199
200// Called when a message is received.
201typedef void (* gt2ReceivedCallback)
202(
203 GT2Connection connection, // The connection the message was received on.
204 GT2Byte * message, // The message that was received. Will be NULL if an empty message.
205 int len, // The length of the message in bytes. Will be 0 if an empty message.
206 GT2Bool reliable // True if this is was sent reliably.
207);
208
209// Called when the connection is closed (remotely or locally).
210// The connection can no longer be used after this callback returns.
211typedef void (* gt2ClosedCallback)
212(
213 GT2Connection connection, // The connection that was closed.
214 GT2CloseReason reason // The reason the connection was closed.
215);
216
217// When a reply is received for a ping that was sent, this callback is called.
218// The latency reported here is the amount of time between when the ping
219// was first sent with gt2Ping and when the pong was received.
220typedef void (* gt2PingCallback)
221(
222 GT2Connection connection, // the connection the ping was sent on
223 int latency // the round-trip time for the ping, in milliseconds
224);
225
226// Callbacks set for each connection.
227// The connected callback is ignored
228// when this is passed to gt2Accept.
229typedef struct
230{
231 gt2ConnectedCallback connected; // Called when gt2Connect is complete.
232 gt2ReceivedCallback received; // Called when a message is received.
233 gt2ClosedCallback closed; // Called when the connection is closed (remotely or locally).
234 gt2PingCallback ping; // Called when a ping reply is received.
236
237/*************************
238** CONNECTION FUNCTIONS **
239*************************/
240
241// initiates a connection between a local socket and a remote socket
242// if blocking is true, the return value signals the connection result:
243// GT2Success means the connect attempt succeeded
244// anything else means it failed
245// if blocking is false, the return value signals the current status of the attempt
246// GT2Success means the connection is being attempted
247// anything else means there was an error and the connection attempt has been aborted
248GT2Result gt2Connect
249(
250 GT2Socket socket, // the local socket to use for the connection
251 GT2Connection * connection, // if the result is GT2Success, and blocking is false, the connection object handle is stored here
252 const char * remoteAddress, // the address to connect to
253 const GT2Byte * message, // an optional initial message (may be NULL)
254 int len, // length of the initial message (may be 0, or -1 for strlen)
255 int timeout, // timeout in milliseconds (may be 0 for infinite retries)
256 GT2ConnectionCallbacks * callbacks, // callbacks for connection related stuff
257 GT2Bool blocking // if true, don't return until complete (successfuly or unsuccessfuly)
258);
259
260// sends data reliably or unreliably
261// reliable messages are guaranteed to arrive, arrive in order, and arrive only once.
262// unreliable messages are not guaranteed to arrive, arrive in order, or arrive only once.
263// because messages may be held in the outgoing buffer (even unreliable messages may need
264// to be put in the buffer), the message size cannot exceed
265GT2Result gt2Send
266(
267 GT2Connection connection, // the connection to send the message on
268 const GT2Byte * message, // the message to send, or NULL for an empty message0
269 int len, // the len of the message (0 for an empty message, ignored if message==NULL)
270 GT2Bool reliable // if true, send the message reliably
271);
272
273// sends a ping on a connection in an attempt to determine latency
274// the ping is unreliable, and either it or the pong sent in reply
275// could be dropped (resulting in the callback never being called),
276// or it could even arrive multiple times (resulting in multiple
277// calls to the callback).
278void gt2Ping(GT2Connection connection);
279
280// starts an attempt to close the connection
281// when the close is completed, the connection's closed callback will be called
282void gt2CloseConnection(GT2Connection connection);
283
284// same as gt2CloseConnection, but doesn't wait for confirmation from the remote side of the connection
285// the closed callback will be called from within this function
286void gt2CloseConnectionHard(GT2Connection connection);
287
288// closes all of a socket's connections (essentially calls gt2CloseConnection on each of them).
289void gt2CloseAllConnections(GT2Socket socket);
290
291// same as gt2CloseAllConnections, but does a hard close
292// any closed callbacks will be called from within this function
293void gt2CloseAllConnectionsHard(GT2Socket socket);
294
295/*********************
296** LISTEN CALLBACKS **
297*********************/
298
299// callback gets called when someone attempts to connect to a socket that is listening for new connections.
300// in response to this callback the application should call gt2Accept or gt2Reject. they do not need
301// to be called from inside the callback, however they should be called in a timely manner so that the
302// remote side does not need to sit around indefinitely waiting for a response.
303// the latency is an estimate of the round trip time between connections.
304typedef void (* gt2ConnectAttemptCallback)
305(
306 GT2Socket socket, // the socket the attempt came in on
307 GT2Connection connection, // a connection object for the incoming connection attempt
308 unsigned int ip, // the IP being used remotely for the connection attempt
309 unsigned short port, // the port being used remotely for the connection attempt
310 int latency, // the approximate latency on the connection
311 GT2Byte * message, // an optional message sent with the attempt. Will be NULL if an empty message.
312 int len // the length of the message, in characters. Will be 0 if an empty message.
313);
314
315/*********************
316** LISTEN FUNCTIONS **
317*********************/
318
319// tells a socket to start listening for incoming connections
320// any connections attempts will cause the callback to be called
321// if the socket is already listening, this callback will replace the exsiting callback being used
322// if the callback is NULL, this will cause the connection to stop listening
323void gt2Listen(GT2Socket socket, gt2ConnectAttemptCallback callback);
324
325// after a socket's gt2ConnectAttemptCallback has been called, this function can be used to accept
326// the incoming connection attempt. it can be called from either within the callback or some later time.
327// as soon as it is called the connection is active, and messages can be sent and received. the remote side
328// of the connection will have it's connected callback called with the result set to GT2Success. the callbacks
329// that are passed in to this function are the same callbacks that get passed to gt2Connect, with the exception
330// that the connected callback can be ignored, as the connection is already established.
331// if this function returns GT2True, then the connection has been successfully accepted. if it returns
332// GT2False, then the remote side has already closed the connection attempt. in that case, the connection
333// is considered closed, and it cannot be referenced again.
334GT2Bool gt2Accept(GT2Connection connection, GT2ConnectionCallbacks * callbacks);
335
336// after a socket's gt2ConnectAttemptCallback has been called, this function can be used to reject
337// the incoming connection attempt. it can be called from either within the callback or some later time.
338// once the function is called the connection is considered closed and cannot be referenced again. the remote
339// side attempting the connection will have its connected callback called with the result set to GT2Rejected.
340// if the message is not NULL and the len is not 0, the message will be sent with the rejection, and passed
341// into the remote side's connected callback.
342void gt2Reject(GT2Connection connection, const GT2Byte * message, int len);
343
344/*************************
345** MESSAGE CONFIRMATION **
346*************************/
347// gets the message id for the last reliably sent message. unreliable messages do not have ids.
348// this should be called immediately after gt2Send. waiting until after a call to gt2Think can result in
349// an invalid message id being returned.
350// note that the use of filters that can either drop or delay messages can complicate the process, because
351// in those cases a call to gt2Send does not guarantee that a message will actually be sent. in those cases,
352// gt2GetLastSentMessageID should be called after gt2FilteredSend, because the actual message will be sent
353// from within that function.
354GT2MessageID gt2GetLastSentMessageID(GT2Connection connection);
355
356// returns true if confirmation was received locally that the reliable message represented by the message id
357// was received by the remote end of the connection. returns false if confirmation was not yet received.
358// this should only be called on message ids that were returned by gt2GetLastSendMessageID, and should be
359// used relatively soon after the message was sent, due to message ids wrapping around after a period of time.
360GT2Bool gt2WasMessageIDConfirmed(GT2Connection connection, GT2MessageID messageID);
361
362/*********************
363** FILTER CALLBACKS **
364*********************/
365
366// Callback for filtering outgoing data.
367// Call gt2FilteredSend with the filtered data, either from within the callback or later.
368// the message points to the same memory location as the message passed to gt2Send (or gt2FilteredSend).
369// so if the call to gt2FilteredSend is delayed, it is the filter's responsibility to make sure the
370// data is still around when and if it is needed.
371typedef void (* gt2SendFilterCallback)
372(
373 GT2Connection connection, // The connection on which the message is being sent.
374 int filterID, // Pass this ID to gt2FilteredSend.
375 const GT2Byte * message, // The message being sent. Will be NULL if an empty message.
376 int len, // The length of the message being sent, in bytes. Will be 0 if an empty message.
377 GT2Bool reliable // If the message is being sent reliably.
378);
379
380// Callback for filtering incoming data.
381// Call gt2FilteredRecieve with the filtered data,
382// either from within the callback or later.
383// the message may point to a memory location supplied to gt2FilteredReceive by a previous filter.
384// so if this filter's call to gt2FilteredReceive is delayed, it is the filter's responsibility
385// to make sure the data is still around when and if it is needed.
386typedef void (* gt2ReceiveFilterCallback)
387(
388 GT2Connection connection, // The connection the message was received on.
389 int filterID, // Pass this ID to gtFilteredReceive.
390 GT2Byte * message, // The message that was received. Will be NULL if an empty message.
391 int len, // The length of the message in bytes. Will be 0 if an empty message.
392 GT2Bool reliable // True if this is a reliable message.
393);
394
395/*********************
396** FILTER FUNCTIONS **
397*********************/
398
399// Adds a filter to the connection's outgoing data.
400// Returns GT2False if there was an error adding the filter (due to no free memory)
401GT2Bool gt2AddSendFilter
402(
403 GT2Connection connection, // The connection on which to add the filter.
404 gt2SendFilterCallback callback // The callback the outgoing data is filtered through.
405);
406
407// Removes a filter from the connection's outgoing data.
408// if callback is NULL, all send filters are removed
409void gt2RemoveSendFilter
410(
411 GT2Connection connection, // The connection on which to remove the filter.
412 gt2SendFilterCallback callback // The callback to remove.
413);
414
415// Called in response to a gt2SendFilterCallback being called.
416// It can be called from within the callback, or at any later time.
417void gt2FilteredSend
418(
419 GT2Connection connection, // The connection on which the message is being sent.
420 int filterID, // The ID passed to the gt2SendFilterCallback.
421 const GT2Byte * message, // The message being sent. May be NULL.
422 int len, // The lengt2h of the message being sent, in bytes. May be 0 or -1.
423 GT2Bool reliable // If the message should be sent reliably.
424);
425
426// Adds a filter to the connection's incoming data.
427// Returns GT2False if there was an error adding the filter (due to no free memory)
428GT2Bool gt2AddReceiveFilter
429(
430 GT2Connection connection, // The connection on which to add the filter.
431 gt2ReceiveFilterCallback callback // The callback the incoming data is filtered through.
432);
433
434// Removes a filter from the connection's incoming data.
435// if callback is NULL, all receive filters are removed
436void gt2RemoveReceiveFilter
437(
438 GT2Connection connection, // The connection on which to remove the filter.
439 gt2ReceiveFilterCallback callback // The callback to remove.
440);
441
442// Called in response to a gt2ReceiveFilterCallback being called.
443// It can be called from within the callback, or at any later time.
444void gt2FilteredReceive
445(
446 GT2Connection connection, // The connection the message was received on.
447 int filterID, // The ID passed to the gt2ReceiveFilterCallback.
448 GT2Byte * message, // The message that was received. May be NULL.
449 int len, // The lengt2h of the message in bytes. May be 0.
450 GT2Bool reliable // True if this is a reliable message.
451);
452
453/*****************************
454** SOCKET SHARING CALLBACKS **
455*****************************/
456
457// this callback gets called when the sock receives a message that it cannot match to an existing
458// connection. if the callback recognizes the message and handles it, it should return GT2True, which
459// will tell the socket to ignore the message. if the callback does not recognize the message, it
460// should return GT2False, which tells the socket to let the other side know there is no connection.
461typedef GT2Bool (* gt2UnrecognizedMessageCallback)
462(
463 GT2Socket socket, // the socket the message was received on
464 unsigned int ip, // the ip of the remote machine the message came from (in network byte order)
465 unsigned short port, // the port on the remote machine (in host byte order)
466 GT2Byte * message, // the message (may be NULL for an empty message)
467 int len // the length of the message (may be 0)
468);
469
470/*****************************
471** SOCKET SHARING FUNCTIONS **
472*****************************/
473
474// this function returns the actual underlying socket for a GT2Socket.
475// this can be used for socket sharing purposes, along with the gt2UnrecognizedMessageCallback.
476SOCKET gt2GetSocketSOCKET(GT2Socket socket);
477
478// sets a callback that all unrecognized messages are passed to. an unrecognized message is one
479// that can't be matched up to a specific connection. if the callback handles the message, it
480// returns true, and the GT2Socket ignores the message. if the callback does not recognize the message,
481// it returns false, and the socket handles the message (by sending a message back indicating the connection
482// is closed). if the callback is NULL, it removes any previously set callback.
483void gt2SetUnrecognizedMessageCallback(GT2Socket socket, gt2UnrecognizedMessageCallback callback);
484
485/*******************
486** INFO FUNCTIONS **
487*******************/
488
489// gets the socket this connection exists on
490GT2Socket gt2GetConnectionSocket(GT2Connection connection);
491
492// gets the connection's connection state
493// GT2Connecting - the connection is still being negotiated
494// GT2Connected - the connection is active (has successfully connected, and not yet closed)
495// GT2Closing - the connection is in the process of closing (i.e., sent a close message and waiting for confirmation).
496// GT2Closed - the connection has already been closed and will soon be freed
497GT2ConnectionState gt2GetConnectionState(GT2Connection connection);
498
499// gets a connection's remote IP (in network byte order)
500unsigned int gt2GetRemoteIP(GT2Connection connection);
501
502// gets a connection's remote port (in host byte order)
503unsigned short gt2GetRemotePort(GT2Connection connection);
504
505// gets a socket's local IP (in network byte order)
506unsigned int gt2GetLocalIP(GT2Socket socket);
507
508// gets a socket's local port (in host byte order)
509unsigned short gt2GetLocalPort(GT2Socket socket);
510
511// gets the total size of the connection's incoming buffer.
512int gt2GetIncomingBufferSize(GT2Connection connection);
513
514// gets the amount of available space in the connection's incoming buffer.
515int gt2GetIncomingBufferFreeSpace(GT2Connection connection);
516
517// gets the total size of the connection's outgoing buffer.
518int gt2GetOutgoingBufferSize(GT2Connection connection);
519
520// gets the amount of available space in the connection's outgoing buffer.
521int gt2GetOutgoingBufferFreeSpace(GT2Connection connection);
522
523/************************
524** USER DATA FUNCTIONS **
525************************/
526
527void gt2SetSocketData(GT2Socket socket, void * data);
528void * gt2GetSocketData(GT2Socket socket);
529void gt2SetConnectionData(GT2Connection connection, void * data);
530void * gt2GetConnectionData(GT2Connection connection);
531
532/*************************
533** BYTE ORDER FUNCTIONS **
534*************************/
535
536unsigned int gt2NetworkToHostInt(unsigned int i);
537unsigned int gt2HostToNetworkInt(unsigned int i);
538unsigned short gt2HostToNetworkShort(unsigned short s);
539unsigned short gt2NetworkToHostShort(unsigned short s);
540
541/**********************
542** ADDRESS FUNCTIONS **
543**********************/
544
545// Converts an IP and a port into a text string. The IP must be in network byte order, and the port
546// in host byte order. The string must be able to hold at least 22 characters (including the NUL).
547// "XXX.XXX.XXX.XXX:XXXXX"
548// If both the IP and port are non-zero, the string will be of the form "1.2.3.4:5" ("<IP>:<port>").
549// If the port is zero, and the IP is non-zero, the string will be of the form "1.2.3.4" ("<IP>").
550// If the IP is zero, and the port is non-zero, the string will be of the form ":5" (":<port>").
551// If both the IP and port are zero, the string will be an empty string ("")
552// The string is returned. If the string paramater is NULL, then an internal static string will be
553// used. There are two internal strings that are alternated between.
554const char * gt2AddressToString
555(
556 unsigned int ip, // IP in network byte order. Can be 0.
557 unsigned short port, // Port in host byte order. Can be 0.
558 char string[22] // String will be placed in here. Can be NULL.
559);
560
561// Converts a string address into an IP and a port. The IP is stored in network byte order, and the port
562// is stored in host byte order. Returns false if there was an error parsing the string, or if a supplied
563// hostname can't be resolved.
564// Possible string forms:
565// NULL => all IPs, any port (localAddress only).
566// "" => all IPs, any port (localAddress only).
567// "1.2.3.4" => 1.2.3.4 IP, any port (localAddress only).
568// "host.com" => host.com's IP, any port (localAddress only).
569// ":2786" => all IPs, 2786 port (localAddress only).
570// "1.2.3.4:0" => 1.2.3.4 IP, any port (localAddress only).
571// "host.com:0" => host.com's IP, any port (localAddress only).
572// "0.0.0.0:2786" => all IPs, 2786 port (localAddress only).
573// "1.2.3.4:2786" => 1.2.3.4 IP, 2786 port (localAddress or remoteAddress).
574// "host.com:2786" => host.com's IP, 2786 port (localAddress or remoteAddress).
575// If this function needs to resolve a hostname ("host.com") it may need to contact a DNS server, which can
576// cause the function to block for an indefinite period of time. Usually it is < 2 seconds, but on certain
577// systems, and under certain circumstances, it can take 30 seconds or longer.
578GT2Bool gt2StringToAddress
579(
580 const char * string, // The string to convert.
581 unsigned int * ip, // The IP is stored here, in network byte order. Can be NULL.
582 unsigned short * port // The port is stored here, in host byte order. Can be NULL.
583);
584
585// Gets the host information for a machine on the Internet. The first version takes an IP in network byte order,
586// and the second version takes a string that is either a dotted ip ("1.2.3.4"), or a hostname ("www.gamespy.com").
587// If the function can successfully lookup the host's info, the host's main hostname will be returned. If it
588// cannot find the host's info, it returns NULL.
589// For the aliases parameter, pass in a pointer to a variable of type (char **). If this parameter is not NULL,
590// and the function succeeds, the variable will point to a NULL-terminated list of alternate names for the host.
591// For the ips parameter, pass in a pointer to a variable of type (int **). If this parameter is not NULL, and
592// the function succeeds, the variable will point to a NULL-terminated list of altername IPs for the host. Each
593// element in the list is actually a pointer to an unsigned int, which is an IP address in network byte order.
594// The return value, aliases, and IPs all point to an internal data structure, and none of these values should
595// be modified directly. Also, the data is only valid until another call needs to use the same data structure
596// (virtually ever internet address function will use this data structure). If the data will be needed in the
597// future, it should be copied off.
598// If this function needs to resolve a hostname ("host.com") it may need to contact a DNS server, which can
599// cause the function to block for an indefinite period of time. Usually it is < 2 seconds, but on certain
600// systems, and under certain circumstances, it can take 30 seconds or longer.
601const char * gt2IPToHostInfo(unsigned int ip, char *** aliases, unsigned int *** ips);
602const char * gt2StringToHostInfo(const char * string, char *** aliases, unsigned int *** ips);
603
604// The following functions are shortcuts for the above two functions (gt2*ToHostInfo()), and each performs a subset
605// of the functionality. They are provided so that code that only needs certain information can be a little simpler.
606// Before using these, read the comments for the gt2*ToHostInfo() functions, as the info also applies to these functions.
607const char * gt2IPToHostname(unsigned int ip);
608const char * gt2StringToHostname(const char * string);
609char ** gt2IPToAliases(unsigned int ip);
610char ** gt2StringToAliases(const char * string);
611unsigned int ** gt2IPToIPs(unsigned int ip);
612unsigned int ** gt2StringToIPs(const char * string);
613
614#ifdef _XBOX
615unsigned int gt2XnAddrToIP(XNADDR theAddr, XNKID theKeyId);
616GT2Bool gt2IPToXnAddr(int ip, XNADDR *theAddr, XNKID *theKeyId);
617#endif
618
619// these are for getting around adhoc which requires a 48 bit address v.s. a 32 bit inet address
620void gt2IpToMac(gsi_u32 ip,char *mac);
621// change IP address to mac ethernet
622gsi_u32 gt2MacToIp(const char *mac);
623// change mac ethernet to IP address
624
625/*******************
626** DUMP CALLBACKS **
627*******************/
628
629// called with either sent or received data
630// trying to send a message from within the send dump callback, or letting the socket think from within the receive
631// dump callback can cause serious problems, and should not be done.
632typedef void (* gt2DumpCallback)
633(
634 GT2Socket socket, // the socket the message was on
635 GT2Connection connection, // the connection the message was on, or NULL if there is no connection for this message
636 unsigned int ip, // the remote ip, in network byte order
637 unsigned short port, // the remote port, in host byte order
638 GT2Bool reset, // if true, the connection has been reset (only used by the receive callback)
639 const GT2Byte * message, // the message (should not be modified)
640 int len // the length of the message
641);
642
643/*******************
644** DUMP FUNCTIONS **
645*******************/
646
647// sets a callback to be called whenever a UDP datagram is sent or received, and when a connection reset is received.
648// pass in a callback of NULL to remove the callback. the dumps sit at a lower level than the filters, and allow an
649// app to keep an eye on exactly what datagrams are being sent and received, allowing for close monitoring. however
650// the dumps cannot be used to modify data, only monitor it. the dumps are useful for debugging purposes, and
651// to keep track of data send and receive rates (e.g., the Quake 3 engine's netgraph).
652// note that these are the actual UDP datagrams being sent and received - datagrams may be dropped, repeated, or
653// out-of-order. control datagrams (those used internally by the protocol) will be passed to the dump callbacks,
654// and certain application messages will have a header at the beginning.
655void gt2SetSendDump(GT2Socket socket, gt2DumpCallback callback);
656void gt2SetReceiveDump(GT2Socket socket, gt2DumpCallback callback);
657
658
659
660#ifdef __cplusplus
661}
662#endif
663
664#endif
Definition gt2.h:230
Definition gt2Main.h:194
Definition gt2Main.h:163