mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-19 21:27:57 +00:00
Build a win32 console exe with VS2008 express
This commit is contained in:
parent
3168789261
commit
59a0a4a2a0
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/win32/Debug
|
||||
/win32/Release
|
||||
*.user
|
||||
*.ncb
|
||||
*.suo
|
16
batman.c
16
batman.c
@ -29,14 +29,16 @@ int readBatmanPeerFile(char *file_path,in_addr_t peers[],int *peer_count,int pee
|
||||
{
|
||||
/* Shiny new code to read the flat file containing peer list */
|
||||
FILE *f;
|
||||
unsigned int offset=0;
|
||||
unsigned int timestamp=0;
|
||||
struct reachable_peer p;
|
||||
|
||||
f=fopen(file_path,"r");
|
||||
if (!f) {
|
||||
fprintf(stderr,"Failed to open peer list file `%s'\n",file_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned int offset=0;
|
||||
|
||||
if (fread(&offset,sizeof(offset),1,f)!=1) {
|
||||
fprintf(stderr,"Failed to read peer list offset from `%s'\n",file_path);
|
||||
fclose(f); return -1; }
|
||||
@ -46,8 +48,6 @@ int readBatmanPeerFile(char *file_path,in_addr_t peers[],int *peer_count,int pee
|
||||
fprintf(stderr,"Failed to seek to peer list offset 0x%x in `%s'\n",offset,file_path);
|
||||
fclose(f); return -1; }
|
||||
|
||||
unsigned int timestamp=0;
|
||||
|
||||
if (fread(×tamp,sizeof(timestamp),1,f)!=1) {
|
||||
fprintf(stderr,"Failed to read peer list timestamp from `%s'\n",file_path);
|
||||
fclose(f); return -1; }
|
||||
@ -59,14 +59,12 @@ int readBatmanPeerFile(char *file_path,in_addr_t peers[],int *peer_count,int pee
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct reachable_peer p;
|
||||
|
||||
while(fread(&p,sizeof(p),1,f)==1)
|
||||
{
|
||||
struct in_addr i;
|
||||
if (!p.addr_len) break;
|
||||
i.s_addr=*(unsigned int *)&p.addr[0];
|
||||
if (*peer_count<peer_max) peers[(*peer_count)++]=i.s_addr;
|
||||
if (*peer_count<peer_max) peers[(*peer_count)++]=i;
|
||||
if (debug>1) fprintf(stderr,"Found BATMAN peer '%s'\n",inet_ntoa(i));
|
||||
}
|
||||
|
||||
@ -76,6 +74,9 @@ int readBatmanPeerFile(char *file_path,in_addr_t peers[],int *peer_count,int pee
|
||||
|
||||
int getBatmanPeerList(char *socket_path,in_addr_t peers[],int *peer_count,int peer_max)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return -1;
|
||||
#else
|
||||
int sock;
|
||||
struct sockaddr_un socket_address;
|
||||
unsigned char buf[16384]; /* big enough for a gigabit jumbo frame or loopback godzilla-gram */
|
||||
@ -192,4 +193,5 @@ int getBatmanPeerList(char *socket_path,in_addr_t peers[],int *peer_count,int pe
|
||||
bytes=0;
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
28
client.c
28
client.c
@ -23,6 +23,8 @@ int packetSendFollowup(struct in_addr destination,
|
||||
unsigned char *packet,int packet_len)
|
||||
{
|
||||
struct sockaddr_in peer_addr;
|
||||
int r;
|
||||
|
||||
peer_addr.sin_family=AF_INET;
|
||||
peer_addr.sin_port = htons(4110);
|
||||
peer_addr.sin_addr.s_addr=destination.s_addr;
|
||||
@ -35,7 +37,7 @@ int packetSendFollowup(struct in_addr destination,
|
||||
}
|
||||
}
|
||||
|
||||
int r=sendto(sock,packet,packet_len,0,(struct sockaddr *)&peer_addr,sizeof(peer_addr));
|
||||
r=sendto(sock,packet,packet_len,0,(struct sockaddr *)&peer_addr,sizeof(peer_addr));
|
||||
if (r<packet_len) {
|
||||
if (debug) fprintf(stderr,"Could not send to %s (r=%d, packet_len=%d)\n",inet_ntoa(destination),r,packet_len);
|
||||
perror("sendto");
|
||||
@ -52,6 +54,7 @@ int packetSendRequest(int method,unsigned char *packet,int packet_len,int batchP
|
||||
int cumulative_timeout=0; /* ms */
|
||||
int this_timeout=125; /* ms */
|
||||
int peer_low,peer_high;
|
||||
int timeout_remaining;
|
||||
|
||||
struct timeval time_in,now;
|
||||
|
||||
@ -115,7 +118,7 @@ int packetSendRequest(int method,unsigned char *packet,int packet_len,int batchP
|
||||
We adjust this_timeout if there are many peers to allow 3 sends to each peer where possible.
|
||||
*/
|
||||
cumulative_timeout+=this_timeout;
|
||||
int timeout_remaining=this_timeout;
|
||||
timeout_remaining=this_timeout;
|
||||
|
||||
while(1)
|
||||
{
|
||||
@ -298,6 +301,7 @@ int getReplyPackets(int method,int peer,int batchP,
|
||||
int timeout_secs;
|
||||
int timeout_usecs;
|
||||
int to=timeout;
|
||||
int len;
|
||||
|
||||
if (debug>1) printf("getReplyPackets(policy=%d)\n",method);
|
||||
|
||||
@ -310,7 +314,7 @@ int getReplyPackets(int method,int peer,int batchP,
|
||||
while(1) {
|
||||
unsigned char buffer[16384];
|
||||
socklen_t recvaddrlen=sizeof(recvaddr);
|
||||
struct pollfd fds;
|
||||
pollfd fds;
|
||||
client_port=((struct sockaddr_in*)&recvaddr)->sin_port;
|
||||
bzero((void *)&recvaddr,sizeof(recvaddr));
|
||||
fds.fd=sock; fds.events=POLLIN;
|
||||
@ -321,7 +325,7 @@ int getReplyPackets(int method,int peer,int batchP,
|
||||
if (t.tv_sec==timeout_secs&&t.tv_usec>=timeout_usecs) return 1;
|
||||
}
|
||||
client_port=((struct sockaddr_in*)&recvaddr)->sin_port;
|
||||
int len=recvfrom(sock,buffer,sizeof(buffer),0,&recvaddr,&recvaddrlen);
|
||||
len=recvfrom(sock,buffer,sizeof(buffer),0,&recvaddr,&recvaddrlen);
|
||||
client_addr=((struct sockaddr_in*)&recvaddr)->sin_addr;
|
||||
if (debug) fprintf(stderr,"Received reply from %s (len=%d).\n",inet_ntoa(client_addr),len);
|
||||
if (debug>1) dump("recvaddr",(unsigned char *)&recvaddr,recvaddrlen);
|
||||
@ -449,7 +453,7 @@ int writeItem(char *sid,int var_id,int instance,unsigned char *value,
|
||||
|
||||
int peerAddress(char *did,char *sid,int flags)
|
||||
{
|
||||
unsigned char transaction_id[8];
|
||||
unsigned char transaction_id[TRANSID_SIZE];
|
||||
unsigned char packet[8000];
|
||||
int packet_len=0;
|
||||
struct response *r;
|
||||
@ -458,9 +462,12 @@ int peerAddress(char *did,char *sid,int flags)
|
||||
int i;
|
||||
int pc;
|
||||
in_addr_t mypeers[256];
|
||||
int method;
|
||||
|
||||
bzero(&responses,sizeof(responses));
|
||||
|
||||
for(i=0;i<TRANSID_SIZE;i++) transaction_id[i]=random()&0xff;
|
||||
|
||||
/* Prepare the request packet */
|
||||
if (packetMakeHeader(packet,8000,&packet_len,transaction_id))
|
||||
{
|
||||
@ -494,7 +501,7 @@ int peerAddress(char *did,char *sid,int flags)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int method=REQ_PARALLEL;
|
||||
method=REQ_PARALLEL;
|
||||
if (sid) method=REQ_FIRSTREPLY;
|
||||
if (packetSendRequest(method,packet,packet_len,NONBATCH,transaction_id,&responses)) {
|
||||
if (debug) fprintf(stderr,"peerAddress() failed because packetSendRequest() failed.\n");
|
||||
@ -511,7 +518,7 @@ int peerAddress(char *did,char *sid,int flags)
|
||||
{
|
||||
if (flags&1) printf("%s\n",inet_ntoa(r->sender));
|
||||
if (flags&2) {
|
||||
if (pc<256) mypeers[pc++]=r->sender.s_addr;
|
||||
if (pc<256) mypeers[pc++]=r->sender;
|
||||
}
|
||||
break;
|
||||
r=r->next;
|
||||
@ -538,6 +545,7 @@ int requestItem(char *did,char *sid,char *item,int instance,unsigned char *buffe
|
||||
|
||||
int successes=0;
|
||||
int errors=0;
|
||||
int method;
|
||||
|
||||
bzero(&responses,sizeof(responses));
|
||||
|
||||
@ -574,7 +582,7 @@ int requestItem(char *did,char *sid,char *item,int instance,unsigned char *buffe
|
||||
return -1;
|
||||
}
|
||||
|
||||
int method=REQ_PARALLEL;
|
||||
method=REQ_PARALLEL;
|
||||
if (sid) method=REQ_FIRSTREPLY;
|
||||
if (packetSendRequest(method,packet,packet_len,(instance==-1)?BATCH:NONBATCH,transaction_id,&responses)) {
|
||||
if (debug) fprintf(stderr,"requestItem() failed because packetSendRequest() failed.\n");
|
||||
@ -643,10 +651,12 @@ int requestItem(char *did,char *sid,char *item,int instance,unsigned char *buffe
|
||||
struct response *rr;
|
||||
struct response_set responses;
|
||||
int offset,max_bytes;
|
||||
int recv_map[1+(r->value_len/MAX_DATA_BYTES)];
|
||||
int *recv_map;
|
||||
int recv_map_size=1+(r->value_len/MAX_DATA_BYTES);
|
||||
int needMoreData;
|
||||
int tries=0;
|
||||
|
||||
recv_map=alloca(recv_map_size);
|
||||
|
||||
/* work out EXACTLY how many installments we need */
|
||||
while (((recv_map_size-1)*MAX_DATA_BYTES)>=r->value_len) recv_map_size--;
|
||||
|
9
dna.c
9
dna.c
@ -250,6 +250,11 @@ int main(int argc,char **argv)
|
||||
int instance=-1;
|
||||
int foregroundMode=0;
|
||||
|
||||
#if defined WIN32
|
||||
WSADATA wsa_data;
|
||||
WSAStartup(MAKEWORD(1,1), &wsa_data);
|
||||
#endif
|
||||
|
||||
srandomdev();
|
||||
|
||||
while((c=getopt(argc,argv,"Ab:B:S:f:d:i:l:np:P:s:t:vR:W:U:D:CO:")) != -1 )
|
||||
@ -356,6 +361,10 @@ int main(int argc,char **argv)
|
||||
if (serverMode) return server(hlr_file,hlr_size,foregroundMode);
|
||||
if (!clientMode) usage("Mesh Potato Home Location Register (HLR) Tool.");
|
||||
|
||||
#if defined WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
/* Client mode: */
|
||||
return 0;
|
||||
}
|
||||
|
10
hlrdata.c
10
hlrdata.c
@ -254,6 +254,8 @@ struct hlrentry_handle *openhlrentry(unsigned char *hlr,int hofs)
|
||||
|
||||
struct hlrentry_handle *hlrentrygetent(struct hlrentry_handle *h)
|
||||
{
|
||||
int ptr;
|
||||
|
||||
if (!h) return NULL;
|
||||
|
||||
if (h->entry_offset==0)
|
||||
@ -276,7 +278,7 @@ struct hlrentry_handle *hlrentrygetent(struct hlrentry_handle *h)
|
||||
}
|
||||
|
||||
/* XXX Extract variable */
|
||||
int ptr=h->hlr_offset+h->entry_offset;
|
||||
ptr=h->hlr_offset+h->entry_offset;
|
||||
if (debug>2) fprintf(stderr,"Extracting HLR variable @ 0x%x\n",ptr);
|
||||
h->var_id=hlr[ptr];
|
||||
h->value_len=(hlr[ptr+1]<<8)+hlr[ptr+2];
|
||||
@ -361,9 +363,10 @@ int hlrSetVariable(unsigned char *hlr,int hofs,int varid,int varinstance,
|
||||
if (debug>2) printf("hlr_offset=%d\n",hlr_offset);
|
||||
if (h&&h->var_id==varid&&h->var_instance==varinstance)
|
||||
{
|
||||
int existing_size;
|
||||
/* Replace existing value */
|
||||
if (debug) fprintf(stderr,"Replacing value in HLR\n");
|
||||
int existing_size=1+2+(h->var_id&0x80?1:0)+h->value_len;
|
||||
existing_size=1+2+(h->var_id&0x80?1:0)+h->value_len;
|
||||
hlrMakeSpace(hlr,hofs,hlr_offset,1+2+len+(varid&0x80?1:0)-existing_size);
|
||||
}
|
||||
else
|
||||
@ -402,6 +405,7 @@ int hlrStowValue(unsigned char *hlr,int hofs,int hlr_offset,
|
||||
|
||||
int hlrMakeSpace(unsigned char *hlr,int hofs,int hlr_offset,int bytes)
|
||||
{
|
||||
int length;
|
||||
/* Deal with easy case first */
|
||||
if (!bytes) return 0;
|
||||
|
||||
@ -412,7 +416,7 @@ int hlrMakeSpace(unsigned char *hlr,int hofs,int hlr_offset,int bytes)
|
||||
if (bytes<0) bzero(&hlr[hlr_size-bytes],0-bytes);
|
||||
|
||||
/* Update record length */
|
||||
int length=hlrGetRecordLength(hlr,hofs);
|
||||
length=hlrGetRecordLength(hlr,hofs);
|
||||
length+=bytes;
|
||||
hlrSetRecordLength(hlr,hofs,length);
|
||||
if (debug>1) fprintf(stderr,"hlrMakeSpace: HLR entry now %d bytes long.\n",length);
|
||||
|
19
mphlr.h
19
mphlr.h
@ -20,12 +20,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#ifndef FORASTERISK
|
||||
|
||||
#ifdef WIN32
|
||||
#include "win32/win32.h"
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if !defined(FORASTERISK) && !defined(s_addr)
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
@ -35,6 +41,7 @@ struct in_addr {
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
@ -53,12 +60,15 @@ struct in_addr {
|
||||
#ifdef HAVE_CTYPE_H
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
//FIXME #include <getopt.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
@ -320,6 +330,7 @@ int clearResponses(struct response_set *responses);
|
||||
int responseFromPeerP(struct response_set *responses,int peerId);
|
||||
int responseFromPeer(struct response_set *responses,int peerId);
|
||||
int additionalPeer(char *peer);
|
||||
int readBatmanPeerFile(char *file_path,in_addr_t peers[],int *peer_count,int peer_max);
|
||||
int getBatmanPeerList(char *socket_path,in_addr_t peers[],int *peer_count,int peer_max);
|
||||
int hlrDump(unsigned char *hlr,int hofs);
|
||||
int peerAddress(char *did,char *sid,int flags);
|
||||
|
@ -75,13 +75,17 @@ int packetOk(unsigned char *packet,int len,unsigned char *transaction_id)
|
||||
if (cipher!=0) return setReason("Unknown packet cipher");
|
||||
if (length!=len) return setReason("Packet length incorrect");
|
||||
|
||||
if (cipher) if (packetDecipher(packet,len,cipher)) return setReason("Could not decipher packet");
|
||||
if (cipher)
|
||||
if (packetDecipher(packet,len,cipher))
|
||||
return setReason("Could not decipher packet");
|
||||
|
||||
/* Make sure the transaction ID matches */
|
||||
if (transaction_id)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<8;i++) if (packet[OFS_TRANSIDFIELD+i]!=transaction_id[i]) return setReason("transaction ID mismatch");
|
||||
for(i=0;i<TRANSID_SIZE;i++)
|
||||
if (packet[OFS_TRANSIDFIELD+i]!=transaction_id[i])
|
||||
return setReason("transaction ID mismatch");
|
||||
}
|
||||
|
||||
/* Unrotate the payload */
|
||||
@ -126,10 +130,10 @@ int packetMakeHeader(unsigned char *packet,int packet_maxlen,int *packet_len,
|
||||
/* Add 64bit transaction id */
|
||||
if (transaction_id)
|
||||
/* Use supplied transaction ID */
|
||||
for(i=0;i<8;i++) packet[OFS_TRANSIDFIELD+i]=transaction_id[i];
|
||||
for(i=0;i<TRANSID_SIZE;i++) packet[OFS_TRANSIDFIELD+i]=transaction_id[i];
|
||||
else
|
||||
/* No transaction ID supplied, so create random transaction ID */
|
||||
for(i=0;i<8;i++) packet[OFS_TRANSIDFIELD+i]=random()&0xff;
|
||||
for(i=0;i<TRANSID_SIZE;i++) packet[OFS_TRANSIDFIELD+i]=random()&0xff;
|
||||
|
||||
/* payload rotation (not yet applied) */
|
||||
packet[14]=0x00;
|
||||
@ -179,6 +183,7 @@ int packetFinalise(unsigned char *packet,int packet_maxlen,int *packet_len)
|
||||
{
|
||||
/* Add any padding bytes and EOT to packet */
|
||||
int paddingBytes=rand()&0xf;
|
||||
int payloadRotation;
|
||||
|
||||
if (paddingBytes)
|
||||
{
|
||||
@ -199,7 +204,7 @@ int packetFinalise(unsigned char *packet,int packet_maxlen,int *packet_len)
|
||||
conduct a known-plaintext attack against any ciphers that we
|
||||
may later support.
|
||||
*/
|
||||
int payloadRotation=(*packet_len)-HEADERFIELDS_LEN;
|
||||
payloadRotation=(*packet_len)-HEADERFIELDS_LEN;
|
||||
if (payloadRotation>0xff) payloadRotation=0xff;
|
||||
payloadRotation=random()%payloadRotation;
|
||||
if (debug>2)
|
||||
@ -425,7 +430,7 @@ int extractResponses(struct in_addr sender,unsigned char *buffer,int len,struct
|
||||
r->sender=sender;
|
||||
for(r->peer_id=0;r->peer_id<peer_count;r->peer_id++)
|
||||
{
|
||||
if (sender.s_addr==peers[r->peer_id]) break;
|
||||
if (sender.s_addr==peers[r->peer_id].s_addr) break;
|
||||
}
|
||||
if (r->peer_id>peer_count) r->peer_id=-1;
|
||||
|
||||
|
13
peers.c
13
peers.c
@ -35,8 +35,8 @@ int additionalPeer(char *peer)
|
||||
|
||||
if (nom_peer_count>255) return setReason("Too many peers. You can only nominate 255 peers in this version.");
|
||||
|
||||
pa=inet_addr(peer);
|
||||
if (pa==INADDR_NONE) return setReason("Invalid peer address specified.");
|
||||
pa.s_addr=inet_addr(peer);
|
||||
if (pa.s_addr==INADDR_NONE) return setReason("Invalid peer address specified.");
|
||||
nominated_peers[nom_peer_count++]=pa;
|
||||
|
||||
return 0;
|
||||
@ -67,7 +67,7 @@ int getPeerList()
|
||||
for(i=0;i<nom_peer_count;i++) peers[peer_count++]=nominated_peers[i];
|
||||
|
||||
/* Add ourselves as a peer */
|
||||
peers[peer_count]=inet_addr("127.0.0.1");
|
||||
peers[peer_count].s_addr=inet_addr("127.0.0.1");
|
||||
peer_replied[peer_count++]=0;
|
||||
|
||||
/* XXX Add broadcast address of every running interface */
|
||||
@ -91,6 +91,7 @@ int sendToPeers(unsigned char *packet,int packet_len,int method,int peerId,struc
|
||||
int i;
|
||||
int maxPeer=peer_count-1;
|
||||
int n=0;
|
||||
int ret;
|
||||
struct sockaddr_in peer_addr;
|
||||
peer_addr.sin_family=AF_INET;
|
||||
peer_addr.sin_port = htons(4110);
|
||||
@ -99,12 +100,12 @@ int sendToPeers(unsigned char *packet,int packet_len,int method,int peerId,struc
|
||||
for(;i<=maxPeer;i++)
|
||||
if (!responseFromPeerP(r,i))
|
||||
{
|
||||
peer_addr.sin_addr.s_addr=peers[i];
|
||||
peer_addr.sin_addr=peers[i];
|
||||
|
||||
if (debug>1) fprintf(stderr,"Sending packet to peer #%d\n",i);
|
||||
|
||||
int r=sendto(sock,packet,packet_len,0,(struct sockaddr *)&peer_addr,sizeof(peer_addr));
|
||||
if (r<packet_len)
|
||||
ret=sendto(sock,packet,packet_len,0,(struct sockaddr *)&peer_addr,sizeof(peer_addr));
|
||||
if (ret<packet_len)
|
||||
{
|
||||
/* XXX something bad happened */
|
||||
if (debug) fprintf(stderr,"Could not send to peer %s\n",inet_ntoa(peer_addr.sin_addr));
|
||||
|
14
responses.c
14
responses.c
@ -50,6 +50,9 @@ int eraseLastResponse(struct response_set *responses)
|
||||
|
||||
int responseFromPeer(struct response_set *responses,int peerId)
|
||||
{
|
||||
int byte;
|
||||
int bit;
|
||||
|
||||
if (peerId<0||peerId>peer_count) return -1;
|
||||
if (!responses) return -1;
|
||||
if (!responses->reply_bitmask)
|
||||
@ -58,8 +61,8 @@ int responseFromPeer(struct response_set *responses,int peerId)
|
||||
if (!responses->reply_bitmask) return -1;
|
||||
}
|
||||
|
||||
int byte=peerId>>3;
|
||||
int bit=peerId&7;
|
||||
byte=peerId>>3;
|
||||
bit=peerId&7;
|
||||
|
||||
responses->reply_bitmask[byte]|=1<<bit;
|
||||
|
||||
@ -69,13 +72,16 @@ int responseFromPeer(struct response_set *responses,int peerId)
|
||||
|
||||
int responseFromPeerP(struct response_set *responses,int peerId)
|
||||
{
|
||||
int byte;
|
||||
int bit;
|
||||
|
||||
if (!responses) return 0;
|
||||
if (!responses->reply_bitmask) return 0;
|
||||
|
||||
if (peerId<0||peerId>peer_count) return 0;
|
||||
|
||||
int byte=peerId>>3;
|
||||
int bit=peerId&7;
|
||||
byte=peerId>>3;
|
||||
bit=peerId&7;
|
||||
|
||||
return responses->reply_bitmask[byte]&(1<<bit);
|
||||
}
|
||||
|
32
server.c
32
server.c
@ -99,7 +99,9 @@ int server(char *backing_file,int size,int foregroundMode)
|
||||
while(1) {
|
||||
unsigned char buffer[16384];
|
||||
socklen_t recvaddrlen=sizeof(recvaddr);
|
||||
struct pollfd fds;
|
||||
pollfd fds;
|
||||
int len;
|
||||
|
||||
client_port=((struct sockaddr_in*)&recvaddr)->sin_port;
|
||||
bzero((void *)&recvaddr,sizeof(recvaddr));
|
||||
fds.fd=sock; fds.events=POLLIN;
|
||||
@ -107,7 +109,7 @@ int server(char *backing_file,int size,int foregroundMode)
|
||||
/* Wait patiently for packets to arrive */
|
||||
while (poll(&fds,1,1000)<1) sleep(0);
|
||||
|
||||
int len=recvfrom(sock,buffer,sizeof(buffer),0,&recvaddr,&recvaddrlen);
|
||||
len=recvfrom(sock,buffer,sizeof(buffer),0,&recvaddr,&recvaddrlen);
|
||||
client_addr=((struct sockaddr_in*)&recvaddr)->sin_addr;
|
||||
if (debug) fprintf(stderr,"Received packet from %s (len=%d).\n",inet_ntoa(client_addr),len);
|
||||
if (debug>1) dump("recvaddr",(unsigned char *)&recvaddr,recvaddrlen);
|
||||
@ -183,11 +185,13 @@ int processRequest(unsigned char *packet,int len,
|
||||
3. Make sure there is space to deliver it .
|
||||
4. Deliver it to the next free message slot
|
||||
*/
|
||||
|
||||
{
|
||||
// extractSMS(...); -- don't forget to check maximum message length
|
||||
int instance=-1; /* use first free slot */
|
||||
unsigned char oldvalue[65536];
|
||||
{ int oldl=65536; int oldr=hlrGetVariable(hlr,ofs,VAR_SMESSAGES,instance,oldvalue,&oldl);
|
||||
int oldl=65536;
|
||||
int oldr=hlrGetVariable(hlr,ofs,VAR_SMESSAGES,instance,oldvalue,&oldl);
|
||||
|
||||
if (oldr) {
|
||||
/* Already exists, so no need to deliver it again */
|
||||
respondSimple(sid,ACTION_SMSRECEIVED,NULL,0,transaction_id);
|
||||
@ -214,16 +218,16 @@ int processRequest(unsigned char *packet,int len,
|
||||
if (debug>1) fprintf(stderr,"Looking for hlr entries with sid='%s' / did='%s'\n",sid,did);
|
||||
while(findHlr(hlr,&ofs,sid,did))
|
||||
{
|
||||
int itemId,instance,start_offset,bytes,flags;
|
||||
unsigned char value[9000],oldvalue[65536];
|
||||
int oldr,oldl;
|
||||
|
||||
if (debug>1) fprintf(stderr,"findHlr found a match for writing at 0x%x\n",ofs);
|
||||
if (debug>2) hlrDump(hlr,ofs);
|
||||
|
||||
/* XXX consider taking action on this HLR
|
||||
(check PIN first depending on the action requested) */
|
||||
|
||||
int itemId,instance,start_offset,bytes,flags;
|
||||
unsigned char value[9000],oldvalue[65536];
|
||||
int oldr,oldl;
|
||||
|
||||
/* XXX Doesn't verify PIN authentication */
|
||||
|
||||
/* Get write request */
|
||||
@ -294,6 +298,12 @@ int processRequest(unsigned char *packet,int len,
|
||||
if (debug>1) fprintf(stderr,"Looking for hlr entries with sid='%s' / did='%s'\n",sid,did);
|
||||
while(findHlr(hlr,&ofs,sid,did))
|
||||
{
|
||||
int var_id=packet[pofs+1];
|
||||
int instance=packet[pofs+2];
|
||||
int offset=(packet[pofs+3]<<8)+packet[pofs+4];
|
||||
int sendDone=0;
|
||||
struct hlrentry_handle *h;
|
||||
|
||||
if (debug>1) fprintf(stderr,"findHlr found a match at 0x%x\n",ofs);
|
||||
if (debug>2) hlrDump(hlr,ofs);
|
||||
|
||||
@ -301,12 +311,6 @@ int processRequest(unsigned char *packet,int len,
|
||||
(check PIN first depending on the action requested) */
|
||||
|
||||
/* Form a reply packet containing the requested data */
|
||||
int var_id=packet[pofs+1];
|
||||
int instance=packet[pofs+2];
|
||||
int offset=(packet[pofs+3]<<8)+packet[pofs+4];
|
||||
int sendDone=0;
|
||||
|
||||
struct hlrentry_handle *h;
|
||||
|
||||
if (instance==0xff) instance=-1;
|
||||
|
||||
|
19
srandomdev.c
19
srandomdev.c
@ -50,24 +50,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#ifndef HAVE_SRANDOMDEV
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "mphlr.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void
|
||||
srandomdev(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
unsigned int seed;
|
||||
int fd;
|
||||
FILE *fd;
|
||||
|
||||
#ifndef WIN32
|
||||
if ((fd = fopen("/dev/urandom", O_RDONLY)) >= 0) {
|
||||
fread(&seed, sizeof seed, 1, fd);
|
||||
fclose(fd);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
|
||||
if ((fd = open("/dev/urandom", O_RDONLY)) >= 0) {
|
||||
read(fd, &seed, sizeof seed);
|
||||
close(fd);
|
||||
} else {
|
||||
gettimeofday(&tv, NULL);
|
||||
/* NOTE: intentional use of uninitialized variable */
|
||||
seed ^= (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec;
|
||||
|
20
win32/dna.sln
Normal file
20
win32/dna.sln
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual C++ Express 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dna", "dna.vcproj", "{8ED67A94-A0A1-4D36-B6F1-179D70412EB0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{8ED67A94-A0A1-4D36-B6F1-179D70412EB0}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{8ED67A94-A0A1-4D36-B6F1-179D70412EB0}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{8ED67A94-A0A1-4D36-B6F1-179D70412EB0}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{8ED67A94-A0A1-4D36-B6F1-179D70412EB0}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
251
win32/dna.vcproj
Normal file
251
win32/dna.vcproj
Normal file
@ -0,0 +1,251 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="dna"
|
||||
ProjectGUID="{8ED67A94-A0A1-4D36-B6F1-179D70412EB0}"
|
||||
RootNamespace="dna"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\asterisk_include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="ws2_32.lib Shlwapi.lib"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\batman.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ciphers.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\client.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\dataformats.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\dna.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\hlrdata.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\packetformats.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\peers.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\responses.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\server.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\simulate.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\srandomdev.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="win32.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\mphlr.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="win32.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
108
win32/win32.c
Normal file
108
win32/win32.c
Normal file
@ -0,0 +1,108 @@
|
||||
#include "../mphlr.h"
|
||||
|
||||
char *optarg; // global argument pointer
|
||||
int optind = 0; // global argv index
|
||||
|
||||
int strncasecmp(char *a,char *b,int len){
|
||||
return CompareStringA(LOCALE_INVARIANT, NORM_IGNORECASE, a, -1, b, len) -2;
|
||||
}
|
||||
|
||||
int getopt(int argc, char *argv[], char *optstring)
|
||||
{
|
||||
char c;
|
||||
char *cp;
|
||||
static char *next = NULL;
|
||||
|
||||
|
||||
if (optind == 0)
|
||||
next = NULL;
|
||||
|
||||
optarg = NULL;
|
||||
|
||||
if (next == NULL || *next == '\0')
|
||||
{
|
||||
if (optind == 0)
|
||||
optind++;
|
||||
|
||||
if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
|
||||
{
|
||||
optarg = NULL;
|
||||
if (optind < argc)
|
||||
optarg = argv[optind];
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (strcmp(argv[optind], "--") == 0)
|
||||
{
|
||||
optind++;
|
||||
optarg = NULL;
|
||||
if (optind < argc)
|
||||
optarg = argv[optind];
|
||||
return EOF;
|
||||
}
|
||||
|
||||
next = argv[optind];
|
||||
next++; // skip past -
|
||||
optind++;
|
||||
}
|
||||
|
||||
c = *next++;
|
||||
cp = strchr(optstring, c);
|
||||
|
||||
if (cp == NULL || c == ':')
|
||||
return '?';
|
||||
|
||||
cp++;
|
||||
if (*cp == ':')
|
||||
{
|
||||
if (*next != '\0')
|
||||
{
|
||||
optarg = next;
|
||||
next = NULL;
|
||||
}
|
||||
else if (optind < argc)
|
||||
{
|
||||
optarg = argv[optind];
|
||||
optind++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int gettimeofday(struct timeval *tv, void *tz)
|
||||
{
|
||||
FILETIME ft;
|
||||
unsigned __int64 tmpres = 0;
|
||||
static int tzflag;
|
||||
|
||||
if (NULL != tv)
|
||||
{
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
|
||||
tmpres |= ft.dwHighDateTime;
|
||||
tmpres <<= 32;
|
||||
tmpres |= ft.dwLowDateTime;
|
||||
|
||||
/*converting file time to unix epoch*/
|
||||
tmpres -= DELTA_EPOCH_IN_MICROSECS;
|
||||
tmpres /= 10; /*convert into microseconds*/
|
||||
tv->tv_sec = (long)(tmpres / 1000000UL);
|
||||
tv->tv_usec = (long)(tmpres % 1000000UL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void * mmap(void *i1, size_t len, int i2, int i3, int fd, int offset){
|
||||
HANDLE fm;
|
||||
HANDLE h = (HANDLE) _get_osfhandle (fd);
|
||||
|
||||
fm = CreateFileMapping(h, NULL, PAGE_READWRITE, 0, len+offset, NULL);
|
||||
return MapViewOfFile(fm, FILE_MAP_WRITE, 0, offset, len);
|
||||
}
|
||||
|
40
win32/win32.h
Normal file
40
win32/win32.h
Normal file
@ -0,0 +1,40 @@
|
||||
#include <io.h>
|
||||
#include <time.h>
|
||||
#include <winsock2.h>
|
||||
#include <Shlwapi.h>
|
||||
#include <malloc.h>
|
||||
|
||||
typedef struct in_addr in_addr_t;
|
||||
typedef int socklen_t;
|
||||
#define snprintf _snprintf
|
||||
#define strdup StrDupA
|
||||
#define bzero ZeroMemory
|
||||
#define HAVE_BZERO
|
||||
#define pollfd WSAPOLLFD
|
||||
#define poll WSAPoll
|
||||
#define random rand
|
||||
#define srandom srand
|
||||
#define sleep Sleep
|
||||
#define getpid GetCurrentProcessId
|
||||
#define daemon(a,b) FreeConsole()
|
||||
|
||||
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
|
||||
#else
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
||||
#endif
|
||||
|
||||
extern int optind, opterr;
|
||||
extern char *optarg;
|
||||
|
||||
int getopt(int argc, char *argv[], char *optstring);
|
||||
int gettimeofday(struct timeval *tv, void *tz);
|
||||
void * mmap(void *i1, size_t len, int i2, int i3, int fd, int offset);
|
||||
int strncasecmp(char *a,char *b,int len);
|
||||
|
||||
#define MAP_FAILED NULL
|
||||
#define PROT_READ 0
|
||||
#define PROT_WRITE 0
|
||||
#define MAP_SHARED 0
|
||||
#define MAP_NORESERVE 0
|
||||
|
Loading…
Reference in New Issue
Block a user