AcessNative - ld-acess - Woking on ELF loading
[tpg/acess2.git] / AcessNative / ld-acess.so_src / request.c
1 /*
2  */
3 #include <stdlib.h>
4 #include <string.h>
5 #include <stdio.h>
6 #ifdef __WIN32__
7 # include <windows.h>
8 # include <winsock.h>
9 #else
10 # include <unistd.h>
11 # include <sys/socket.h>
12 # include <netinet/in.h>
13 #endif
14
15 #define SERVER_PORT     0xACE
16
17 // === GLOBALS ===
18 #ifdef __WIN32__
19 WSADATA gWinsock;
20 SOCKET  gSocket;
21 #else
22  int    gSocket;
23 # define INVALID_SOCKET -1
24 #endif
25
26 // === CODE ===
27 int _InitSyscalls()
28 {
29         struct sockaddr_in      server;
30         struct sockaddr_in      client;
31         
32         #ifdef __WIN32__
33         /* Open windows connection */
34         if (WSAStartup(0x0101, &gWinsock) != 0)
35         {
36                 fprintf(stderr, "Could not open Windows connection.\n");
37                 exit(0);
38         }
39         #endif
40         
41         // Open UDP Connection
42         gSocket = socket(AF_INET, SOCK_DGRAM, 0);
43         if (gSocket == INVALID_SOCKET)
44         {
45                 fprintf(stderr, "Could not create socket.\n");
46                 #if __WIN32__
47                 WSACleanup();
48                 #endif
49                 exit(0);
50         }
51         
52         // Set server address
53         memset((void *)&server, '\0', sizeof(struct sockaddr_in));
54         server.sin_family = AF_INET;
55         server.sin_port = htons(SERVER_PORT);
56         server.sin_addr.s_addr = htonl(0x7F00001);
57         
58         // Set client address
59         memset((void *)&client, '\0', sizeof(struct sockaddr_in));
60         client.sin_family = AF_INET;
61         client.sin_port = htons(0);
62         client.sin_addr.s_addr = htonl(0x7F00001);
63         
64         // Bind
65         if( bind(gSocket, (struct sockaddr *)&client, sizeof(struct sockaddr_in)) == -1 )
66         {
67                 fprintf(stderr, "Cannot bind address to socket.\n");
68                 #if __WIN32__
69                 closesocket(gSocket);
70                 WSACleanup();
71                 #else
72                 close(gSocket);
73                 #endif
74                 exit(0);
75         }
76         return 0;
77 }
78
79 int _Syscall(const char *ArgTypes, ...)
80 {
81         return 0;
82 }

UCC git Repository :: git.ucc.asn.au