diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2004-09-26 13:08:46 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2004-09-26 13:08:46 +0000 |
commit | 92bbeab96bf61edf9b7caa125ed67e634258383e (patch) | |
tree | a95dd426590c8e6208445290fa8b9b47c1a57bcb /src/net | |
parent | e46b2cdbf205d3d2e17266e3168fdbecd5f53222 (diff) | |
download | mana-92bbeab96bf61edf9b7caa125ed67e634258383e.tar.gz mana-92bbeab96bf61edf9b7caa125ed67e634258383e.tar.bz2 mana-92bbeab96bf61edf9b7caa125ed67e634258383e.tar.xz mana-92bbeab96bf61edf9b7caa125ed67e634258383e.zip |
*** empty log message ***
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/network.cpp | 177 | ||||
-rw-r--r-- | src/net/network.h | 87 | ||||
-rw-r--r-- | src/net/protocol.cpp | 264 | ||||
-rw-r--r-- | src/net/protocol.h | 57 | ||||
-rw-r--r-- | src/net/win2linux.h | 54 | ||||
-rw-r--r-- | src/net/win2mac.cpp | 42 | ||||
-rw-r--r-- | src/net/win2mac.h | 16 |
7 files changed, 697 insertions, 0 deletions
diff --git a/src/net/network.cpp b/src/net/network.cpp new file mode 100644 index 00000000..c8bff09a --- /dev/null +++ b/src/net/network.cpp @@ -0,0 +1,177 @@ +/** + + The Mana World + Copyright 2004 The Mana World Development Team + + This file is part of The Mana World. + + The Mana World is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + The Mana World is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with The Mana World; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include "network.h" +#ifndef WIN32 +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#endif + +/** Warning: buffers and other variables are shared, + so there can be only one connection active at a time */ + +int buffer_size = 65536; +char *in, *out; +int in_size, out_size; + +SOCKET sock; +SOCKADDR_IN addr; +// File descriptors attached to socket +fd_set read_socket; +fd_set write_socket; + +/** Increase size of written data */ +void WFIFOSET(int len) { + if(out_size+len>=buffer_size) + warning("Output buffer full"); + else out_size+=len; +} + +/** Convert an address from int format to string */ +char *iptostring(int address) { + short temp1, temp2; + + char *temp = (char *)malloc(sizeof(char[20])); + temp1 = LOWORD(address); + temp2 = HIWORD(address); + sprintf(temp, "%i.%i.%i.%i", LOBYTE(temp1), HIBYTE(temp1), LOBYTE(temp2), HIBYTE(temp2)); + return temp; +} + +/** Open a session with a server */ +SOCKET open_session(const char* address, short port) { + #ifdef WIN32 + WSADATA wsda; + #endif + struct hostent *server; + int ret; + + // Init WinSock and connect the socket + #ifdef WIN32 + WSAStartup(MAKEWORD(2,0), &wsda); + #endif + + sock = socket(PF_INET, SOCK_STREAM, 0); // Create socket for current session + if(sock==SOCKET_ERROR)return SOCKET_ERROR; + + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + addr.sin_addr.s_addr = inet_addr(address); + if(addr.sin_addr.s_addr == INADDR_NONE){ + server = NULL; + server = gethostbyname(address); + if(server == NULL)return SOCKET_ERROR; + memcpy(&addr.sin_addr, server->h_addr_list[0], server->h_length); + } + + ret = connect(sock, (struct sockaddr *) &addr, sizeof(addr)); + if(ret == SOCKET_ERROR)return SOCKET_ERROR; + + // Init buffers + in = (char *)malloc(buffer_size); + out = (char *)malloc(buffer_size); + memset(in, '\0', buffer_size); + memset(out, '\0', buffer_size); + in_size = 0; + out_size = 0; + FD_CLR(sock, &read_socket); + FD_CLR(sock, &write_socket); + + return sock; +} + +/** Close a session */ +void close_session() { + FD_CLR(sock,&read_socket); + FD_CLR(sock,&write_socket); + closesocket(sock); + if(in!=NULL)free(in); + if(out!=NULL)free(out); + in = NULL; + out = NULL; + in_size = 0; + out_size = 0; + WSACleanup(); +} + +/** Send and receive data waiting in the buffers */ +void flush() { + int ret = 0; + void *buf = out; //-kth5 + timeval time_out; + + // Init the time_out struct to 0s so it won't block + time_out.tv_sec=0; + time_out.tv_usec=0; + + // Clear file descriptors and set them to socket + FD_ZERO(&read_socket); + FD_ZERO(&write_socket); + FD_SET(sock, &read_socket); + FD_SET(sock, &write_socket); + + // Check if socket has available data by evaluating attached file descriptors + select(FD_SETSIZE, &read_socket, &write_socket, NULL, &time_out); + + // Send data if available + if(FD_ISSET(sock, &write_socket)) { + // While there wasn't a error or sent the whole data: handles partial packet send + while((ret!=SOCKET_ERROR)&&(out_size>0)) { + ret = send(sock, (char *)buf, out_size, 0); + /*FILE *file = fopen("log.log","wb"); + + fprintf(file, "%s", out[0]); + fclose(file);*/ + // If not the whole data has been sent, empty the buffer from already sent bytes + if(ret!=SOCKET_ERROR && ret>0) { + buf = (char*)buf+ret; //-kth5 + out_size -= ret; + } + } + if(ret==SOCKET_ERROR) { + error("Socket Error"); +#ifdef WIN32 + log_int("Error", "socket_error", WSAGetLastError()); +#else + log("Error", "socket_error", "Undefined socket error"); +#endif + } + } + + // Read data, if available + if(FD_ISSET(sock, &read_socket)) { + /* There's no check for partial received packets because at this level + the app doesn't know packet length, but it will done when parsing received data */ + ret = recv(sock, in+in_size, RFIFOSPACE, 0); + if(ret==SOCKET_ERROR) { +#ifdef WIN32 + log_int("Error", "socket_error", WSAGetLastError()); +#else + log("Error", "socket_error", "Undefined socket error"); +#endif + } else RFIFOSET(ret); // Set size of available data to read + } +} + + diff --git a/src/net/network.h b/src/net/network.h new file mode 100644 index 00000000..5eca3398 --- /dev/null +++ b/src/net/network.h @@ -0,0 +1,87 @@ +/** + + The Mana World + Copyright 2004 The Mana World Development Team + + This file is part of The Mana World. + + The Mana World is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + The Mana World is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with The Mana World; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifdef WIN32 + #pragma warning (disable:4312) +#endif + +#ifndef _NETWORK_H +#define _NETWORK_H + +#ifdef WIN32 +#include <allegro.h> +#include <winalleg.h> +#else +#include "win2linux.h" +#endif +#include <stdio.h> +#include "../log.h" +#ifdef MACOSX +#include "win2mac.h" +#endif + +/** Macros to write in output buffer, pos is the location where to write data + After you wrote len bytes, you have to use WFIFOSET */ +#define WFIFOSPACE (buffer_size-out_size) // Number of bytes currently written in uotput buffer +#define WFIFOP(pos) (out+(pos+out_size)) // Return a pointer to a specific location in output buffer +#define WFIFOB(pos) (*(unsigned char *)(out+pos+out_size)) // Write a byte (1 byte) +#define WFIFOW(pos) (*(unsigned short *)(out+pos+out_size)) // Write a word (2 byte) +#define WFIFOL(pos) (*(unsigned int *)(out+pos+out_size)) // Write a long (4 byte) +//#define WFIFOSET(len) out_size+=len // Increase size of written data +#ifdef MACOSX +#define net_b_value(id) (id) +#define net_w_value(id) DR_SwapTwoBytes(id) +#define net_l_value(id) DR_SwapFourBytes(id) +#else +#define net_b_value(id) (id) +#define net_w_value(id) (id) +#define net_l_value(id) (id) +#endif + + +/** Macros to read from input buffer, pos is the location of data to be read + After you read len bytes, you should use RFIFOSKIP */ +#define RFIFOP(pos) (in+(pos)) // Get a pointer from a specific location in input buffer +#ifdef MACOSX +#define RFIFOB(pos) ((*(unsigned char*)(in+(pos)))) // Read a byte +#define RFIFOW(pos) DR_SwapTwoBytes((*(unsigned short*)(in+(pos)))) // Read a word +#define RFIFOL(pos) DR_SwapFourBytes((*(unsigned int*)(in+(pos)))) // Read a long +#else +#define RFIFOB(pos) (*(unsigned char*)(in+(pos))) // Read a byte +#define RFIFOW(pos) (*(unsigned short*)(in+(pos))) // Read a word +#define RFIFOL(pos) (*(unsigned int*)(in+(pos))) // Read a long +#endif +#define RFIFOSKIP(len) (memcpy(in,in+len,in_size-len));in_size-=len; // Empty len bytes from input buffer +#define RFIFOSPACE (buffer_size-in_size) // Return input buffer size +#define RFIFOSET(len) in_size+=len; + +void WFIFOSET(int len); +char *iptostring(int address); +SOCKET open_session(const char* address, short port); +void close_session(); +void flush(); + +extern char *in, *out; // Input, output buffer +extern int in_size, out_size; // Input, output buffer size + +#endif diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp new file mode 100644 index 00000000..2c33d092 --- /dev/null +++ b/src/net/protocol.cpp @@ -0,0 +1,264 @@ +/** + + The Mana World + Copyright 2004 The Mana World Development Team + + This file is part of The Mana World. + + The Mana World is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + The Mana World is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with The Mana World; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include "protocol.h" + +short packet_lengths[] = { + + 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// #0x0040 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2, + 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6, +// #0x0080 + 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 23, -1, -1, -1, 0, + 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6, + 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6, + 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3, +// #0x00C0 + 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 6, 2, 27, + 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1, + 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2, + 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10, +// #0x0100 + 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1, + 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16, + 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1, + 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26, +// #0x0140 + 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6, + 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42, + -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182, + 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1, +// #0x0180 + 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6, + 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, 4, 6, 2, 6, + 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4, + 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3, +// #0x01C0 + 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 0, 9, 9, 29, 6, 28, + 8, 14, 10, 35, 6, 8, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6, + 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1, + -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10, +// #0x200 + 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, + +}; + +/** Packet length by id */ +short get_length(short id) { + return packet_lengths[id]; +} + +/** Decodes dest x coord */ +unsigned short get_dest_x(char *data) { + short temp; + temp = MAKEWORD(data[3], data[2] & 0x000f); + temp >>= 2; + return temp; +} + +/** Decodes dest y coord */ +unsigned short get_dest_y(char *data) { + short temp; + temp = MAKEWORD(data[4], data[3] & 0x0003); + return temp; +} + +/** Decodes src x coord */ +unsigned short get_src_x(char *data) { + short temp; + temp = MAKEWORD(data[1], data[0]); + temp >>= 6; + return temp; +} + +/** Decodes src y coord */ +unsigned short get_src_y(char *data) { + short temp; + temp = MAKEWORD(data[2], data[1] & 0x003f); + temp >>= 4; + return temp; +} + +/** Decodes src direction */ +unsigned char get_src_direction(char data) { + data >>= 4; + return data; +} + +/** Decodes dest direction */ +unsigned char get_dest_direction(char data) { + return data & 0x000f; +} + +/** Decodes x coord */ +unsigned short get_x(char *data) { + short temp; + temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff); + temp >>= 6; + return temp; +} + +/** Decodes y coord */ +unsigned short get_y(char *data) { + short temp; + if(!data)error("Corrupted data"); + temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f); + if(!temp)error("Corrupted data"); + temp >>= 4; + return temp; +} + +/** Decodes direction */ +unsigned char get_direction(char *data) { + char temp; + temp = data[2] & 0x000f; + return temp; +} + +/** Encodes coords and direction in 3 bytes data */ +void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction) { + short temp; + temp = x; + temp <<= 6; + data[0] = 0; + data[1] = 1; + data[2] = 2; + data[0] = HIBYTE(temp); + data[1] = LOBYTE(temp); + temp = y; + temp <<= 4; + data[1] |= HIBYTE(temp); + data[2] = LOBYTE(temp); + data[2] |= direction; +} + +/** Initialize connection with map server */ +void map_start() { + // Connect to map server + if(open_session(iptostring(map_address), map_port)==SOCKET_ERROR) { + warning("Unable to connect to map server"); + state = LOGIN; + ok("Error", "Unable to connect to map server"); + return; + } + + // Send login infos + WFIFOW(0) = net_w_value(0x0072); + WFIFOL(2) = net_l_value(account_ID); + WFIFOL(6) = net_l_value(char_ID); + WFIFOL(10) = net_l_value(session_ID1); + WFIFOL(14) = net_l_value(session_ID2); + WFIFOB(18) = net_b_value(sex); + WFIFOSET(19); + + while((in_size<4)||(out_size>0))flush(); + RFIFOSKIP(4); + + while(in_size<2)flush(); + + if(RFIFOW(0)==0x0073) { + while(in_size<11)flush(); + x = get_x(RFIFOP(6)); + y = get_y(RFIFOP(6)); + log_int("Player", "x", x); + log_int("Player", "y", y); + direction = get_direction(RFIFOP(6)); + log_int("Player", "direction", direction); + RFIFOSKIP(11); + } else if(0x0081) { + warning("Map server D/C"); + } else error("Unknown packet: map_start"); + // Send "map loaded" + WFIFOW(0) = net_w_value(0x007d); + WFIFOSET(2); + while(out_size>0)flush(); +} + +/** Requests to walk */ +void walk(unsigned short x, unsigned short y, unsigned char direction) { + char temp[3]; + set_coordinates(temp, x, y, direction); + WFIFOW(0) = net_w_value(0x0085); + memcpy(WFIFOP(2), temp, 3); + WFIFOSET(5); +} + +/** Request to speak */ +void speak(char *speech) { + int len = (int)strlen(speech); + WFIFOW(0) = net_w_value(0x008c); + WFIFOW(2) = net_w_value(len+4); + memcpy(WFIFOP(4), speech, len); + WFIFOSET(len+4); +} + +/** request action */ +void action(short type, int id) { + WFIFOW(0) = net_w_value(0x0089); + WFIFOL(2) = net_l_value(id); + WFIFOB(6) = net_l_value(type); + WFIFOSET(7); +} + + +/** Request to attack */ +void attack(unsigned short x, unsigned short y, unsigned char direction) { + int monster_id = 0; + + if(direction==2) { + for(int j=-1;j<2;j++) + for(int i=-1;i<1;i++) { + monster_id = find_monster(x+i, y+j); + if(monster_id!=0) + action(0x07, monster_id); + } + } else if(direction==6) { + for(int j=-1;j<2;j++) + for(int i=0;i<2;i++) { + monster_id = find_monster(x+i, y+j); + if(monster_id!=0) + action(0x07, monster_id); + } + } else if(direction==4) { + for(int j=-1;j<1;j++) + for(int i=-1;i<2;i++) { + monster_id = find_monster(x+i, y+j); + if(monster_id!=0) + action(0x07, monster_id); + } + } else if(direction==0) { + for(int j=0;j<1;j++) + for(int i=-1;i<2;i++) { + monster_id = find_monster(x+i, y+j); + if(monster_id!=0) + action(0x07, monster_id); + } + } +} + diff --git a/src/net/protocol.h b/src/net/protocol.h new file mode 100644 index 00000000..60293e4a --- /dev/null +++ b/src/net/protocol.h @@ -0,0 +1,57 @@ +/** + + The Mana World + Copyright 2004 The Mana World Development Team + + This file is part of The Mana World. + + The Mana World is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + The Mana World is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with The Mana World; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +#ifdef WIN32 + #pragma warning (disable:4312) +#endif + +#ifndef _PROTOCOL_H +#define _PROTOCOL_H + +#include <allegro.h> +#ifdef WIN32 +#include <winalleg.h> +#include <windows.h> +#else +#include "win2linux.h" +#endif + +#include "../main.h" +#include "../being.h" + +short get_length(short id); +unsigned short get_x(char *data); +unsigned short get_y(char *data); +unsigned char get_direction(char *data); +unsigned short get_src_x(char *data); +unsigned short get_src_y(char *data); +unsigned char get_src_direction(char data); +unsigned short get_dest_x(char *data); +unsigned short get_dest_y(char *data); +unsigned char get_dest_direction(char data); +void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction); +void map_start(); +void walk(unsigned short x, unsigned short y, unsigned char direction); +void speak(char *speech); +void attack(unsigned short x, unsigned short y, unsigned char direction); +void action(short, int); +#endif diff --git a/src/net/win2linux.h b/src/net/win2linux.h new file mode 100644 index 00000000..71737a58 --- /dev/null +++ b/src/net/win2linux.h @@ -0,0 +1,54 @@ +#include <stdio.h> +#include <stdlib.h> +#ifndef MACOSX +#include <malloc.h> +#endif +#include <string.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <stdio.h> +#include <unistd.h> +#include <arpa/inet.h> +#include <netdb.h> + +typedef unsigned char BYTE; +typedef unsigned short WORD; +#define MAKEWORD(low,high) \ + ((WORD)(((BYTE)(low)) | ((WORD)((BYTE)(high))) << 8)) +#define closesocket(a) close(a) +#define SOCKET int +#define SOCKET_ERROR -1 +#define SOCKADDR_IN struct sockaddr_in +typedef struct sockaddr SOCKADDR; +typedef SOCKADDR * LPSOCKADDR; +#define WSACleanup() ; + + + +typedef unsigned short WORD; +typedef unsigned long int LWORD; +typedef unsigned char BYTE; +#define LOBYTE(w) ((BYTE) (w) ) +#define HIBYTE(w) ((BYTE) (((WORD)(w)) >> 8) ) +#define LOWORD(l) ((WORD) (l) ) +#define HIWORD(l) ((WORD) (((LWORD)(l)) >> 16) ) +#define HANDLE int +#define HANDLE int +#define PHANDLE int +#define SMALL_RECT int +//#define WORD int +#define DWORD int +#define PDWORD int +#define BOOL int +#define LPBOOL int +#define LPSTR int +#define LPTSTR int +#define LPCTSTR int +#define LPDWORD int +#define LPVOID int +#define WINAPI + +#define LOBYTE(w) ((BYTE) (w) ) +#define HIBYTE(w) ((BYTE) (((WORD)(w)) >> 8) ) +#define LPTHREAD_START_ROUTINE void *(*)(void *) +#define CloseHandle close diff --git a/src/net/win2mac.cpp b/src/net/win2mac.cpp new file mode 100644 index 00000000..be4bad1d --- /dev/null +++ b/src/net/win2mac.cpp @@ -0,0 +1,42 @@ +#include "win2mac.h" + + +void dummy() +{ + +printf("hej\n"); +} + +UInt32 DR_SwapFourBytes(UInt32 dw) +{ +UInt32 tmp; +tmp = (dw & 0x000000FF); +tmp = ((dw & 0x0000FF00) >> 0x08) | (tmp << 0x08); +tmp = ((dw & 0x00FF0000) >> 0x10) | (tmp << 0x08); +tmp = ((dw & 0xFF000000) >> 0x18) | (tmp << 0x08); +return (tmp); +} + +UInt16 DR_SwapTwoBytes(UInt16 w) +{ +UInt16 tmp; +tmp = (w & 0x00FF); +tmp = ((w & 0xFF00) >> 0x08) | (tmp << 0x08); +return(tmp); +} + +char* SwapChar(char charlist[]) +{ +for(int i =0; i< 24/2; i++) + SWAP(charlist[i],charlist[24-i]); +return charlist; +} + +/* +char* SwapChar(char charlist[]) +{ +for(int i =0; i< sizeof(charlist)*4/2; i++) + SWAP(charlist[i],charlist[sizeof(charlist)*4-i]); +return charlist; +} +*/
\ No newline at end of file diff --git a/src/net/win2mac.h b/src/net/win2mac.h new file mode 100644 index 00000000..72ae9fd9 --- /dev/null +++ b/src/net/win2mac.h @@ -0,0 +1,16 @@ +#include <stdio.h> + +#define UInt16 unsigned short int +#define INT16 short int +#define UInt32 unsigned long int +#define INT32 long int +#define SWAP( a, b ) { char c; c=a; a=b; b=c; } + +#ifndef _MAC_H +#define _MAC_H +void dummy(); +UInt32 DR_SwapFourBytes(UInt32 dw); +UInt16 DR_SwapTwoBytes(UInt16 w); +char* SwapChar(char charlist[]); +#endif + |