From 31687892611f425def29a22fc68160aeb9e80a0e Mon Sep 17 00:00:00 2001 From: gardners Date: Wed, 30 Mar 2011 15:07:31 +1030 Subject: [PATCH] DNA now appends IP to location records on receipt, instead of keeping them in the HLR. This allows IP address of phones to change without invalidating HLR. Does introduce issues for verification of records. Will deal with that in due course. --- client.c | 40 ++++++++++++++++++++++++++++++++++++++++ packetformats.c | 2 ++ 2 files changed, 42 insertions(+) diff --git a/client.c b/client.c index afcb8088..56309a06 100755 --- a/client.c +++ b/client.c @@ -244,6 +244,46 @@ int requestNewHLR(char *did,char *pin,char *sid) return setReason("Request creation of new HLR not implemented"); } +/* Some data types can end in @ if they require the address of the sender to be appended for correct local interpretation */ +int fixResponses(struct response_set *responses) +{ + struct response *rr; + + if (debug>1) fprintf(stderr,"Fixing response set\n"); + + if (!responses) return -1; + + rr=responses->responses; + while(rr) + { + if (debug>1) fprintf(stderr," len=%d, rr->code=%02x, rr->var_id=%02x\n", + rr->value_bytes,rr->code,rr->var_id); + if (rr->value_bytes>0&&rr->code==ACTION_DATA&&rr->var_id==VAR_LOCATIONS) + { + if (debug>1) fprintf(stderr," response='%s'\n",rr->response); + if (rr->response[rr->value_bytes-1]=='@') + { + /* Append response with IP address of sender */ + char *addr=inet_ntoa(rr->sender); + int alen=strlen(addr); + char *new = malloc(rr->value_bytes+alen+1); + if (debug>1) fprintf(stderr,"Fixing LOCATIONS response '%s' received from '%s'\n", + rr->response,addr); + if (!new) return -1; + bcopy(rr->response,new,rr->value_bytes); + bcopy(addr,&new[rr->value_bytes],alen+1); + free(rr->response); rr->response=NULL; + rr->response=new; + rr->value_len+=alen; + rr->value_bytes+=alen; + if (debug>1) fprintf(stderr,"Response string now '%s'\n",rr->response); + } + } + rr=rr->next; + } + return 0; +} + int getReplyPackets(int method,int peer,int batchP, struct response_set *responses, unsigned char *transaction_id,int timeout) diff --git a/packetformats.c b/packetformats.c index 2f7808ac..ddd53499 100755 --- a/packetformats.c +++ b/packetformats.c @@ -407,6 +407,7 @@ int extractResponses(struct in_addr sender,unsigned char *buffer,int len,struct default: free(r); if (debug>1) fprintf(stderr,"Encountered unimplemented response code 0x%02x @ 0x%x\n",buffer[ofs],ofs); + fixResponses(responses); return setReason("Encountered unimplemented response type"); } ofs++; @@ -443,6 +444,7 @@ int extractResponses(struct in_addr sender,unsigned char *buffer,int len,struct if (debug>2) dumpResponses(responses); } + fixResponses(responses); return 0; }