FB_init

Showing posts with label networking. Show all posts
Showing posts with label networking. Show all posts

Thursday, August 30, 2012

Linksys SPA2102-R and TP-Link problem

All of a sudden my VoIP phone stopped working. The SPA2102-R and the TP-Link TD-8816 stopped working. In summary, I had to call my ISP. They had to do something on their side. The TP-Link modem then started to work and I had Internet connection. But the SPA2102-R would not work. It had the gree power light flashing. The patter was 3 flashes: the 1st one longer followed by 2 short ones. And I couldn't figure out why on earth it would not connect to the modem. The main indication of the problem was that the LAN light of the modem was off, indicating that the modem and the VoIP adapter were not connected. I called my ISP/VoIP support. They thought that because the LAN light was not turning on that there was some sort of hardware problem with the network card of the VoIP adapter. And they shipped another adapter to me (4 more days without a phone!) The new adapter arrived today. I plugged it in and I got the exact same problem.
  I tried different things. I noticed that when I set a fixed IP on the modem and on the VoIP adapter, the light patter on the VoIP adapter changed to almost all lights red flashing. I'm so glad that Cisco doesn't have detailed explanation of what the flashing patterns really mean! So it appeared that the adapter was taking the network settings. I then configured my notebook to be a DHCP server. And I noticed that the light pattern changed (for better): the power green light was solid and the Internet light was flashing (or solid? I can't remember). That was a hint that the problem was not with the adapter, but some detail of the network driver/controller of the modem.
  So I left the option that should not have worked but worked at the end: I put the VoIP adapter behind my wireless router. And it worked! It didn't work months ago, because the firewall of the wireless router would block certain (SIP ?) ports. But it worked today (with some changes to the firewall).

Wednesday, July 11, 2012

Domain, subdomain and deleting cookies

I was trying to delete with server-side code (C#) a mix of cookies types: some had the domain as the sub-domain, others had just the base domain without the sub-domain prefix. I wasn't able to delete the cookies of the base domain, since the running domain was the sub-domain. (Also, in C#, the cookie domain was null, so I had to use the request domain)
  This is what I did: I set pairs of expired cookies:



Func getBaseDomain = (someDomain) =>  System.Text.RegularExpressions.Regex.Replace(someDomain, @"(.+)((:?\..+){2,4})", "$2");

                    var responseCookie = new HttpCookie(cookieName);
                    responseCookie.Domain = Request.Url.Host;                  
                    responseCookie.Expires = DateTime.Now.AddYears(-1);
                    this.Response.Cookies.Add(responseCookie);

                    // try also to issue an expired cookie - to 'remove it'
                    // like - the one before but
                    // with the base domain. That is, without the sub-domain prefix.
                    // The cookie can only be deleted
                    // if the domain in the response matches exactly that
                    // assumed by the browser.

                    var responseCookie2 = new HttpCookie(cookieName);
                    responseCookie2.Domain = getBaseDomain(Request.Url.Host);
                    responseCookie2.Expires = DateTime.Now.AddYears(-1);
                    this.Response.Cookies.Add(responseCookie2);


 

Monday, June 18, 2012

VoIP problems with Linksys SPA2102

The application: a home setup with the Linksys SPA2102 connected to my TP-Link ADSL2+ modem. A VoIP service by Teksavvy. I bought the Linksys SPA2102 by myself, but  I didn't know only VoIP devices sold by Teksavvy are supported. I setup the SIP server, username and password in the PSA2102. 

The problem: When dialing out (outbound), there was no ring tone on the phone. The call was established but for the first 40 seconds the call quality was terrible. And the call was only half-duplex (out from the Linksys device, but extremely poor quality). After the first 40 seconds the call quality was fine (duplex).

What I tried: I tried different audio codecs. I tried to enable NAT. I tried disabling the firewall in the modem. I tried to enable streaming on the Linksys device. I set to establish/accept unregistered calls. These settings didn't work.

No solution. I'll buy the phone adapter from Teksavvy so that I can get support.

(Note after the post: the solution was to put the SPA2102 in the DMZ and to change some firewall settings - can't get into the details of this last one... )

Thursday, October 01, 2009

How to use the DnsQuery function (Windows Server 2008 R2)

There's a nice article on Microsoft's Support web site titled "How to use the DnsQuery function to resolve host names and host addresses with Visual C++ .NET" ( here ). The problem is that the signature of the DnsQuery Function has changed. The first argument takes a PCTSTR instead of a char * type.
I decided to rewrite the application using PCTSTR. Here's the new version:


#include //winsock
#include //DNS api's
#include //standard i/o
#include

//Usage of the program
void Usage(char *progname) {
fprintf(stderr,"Usage\n%s -n [HostName|IP Address] -t [Type] -s [DnsServerIp]\n",progname);
fprintf(stderr,"Where:\n\t\"HostName|IP Address\" is the name or IP address of the computer ");
fprintf(stderr,"of the record set being queried\n");
fprintf(stderr,"\t\"Type\" is the type of record set to be queried A or PTR\n");
fprintf(stderr,"\t\"DnsServerIp\"is the IP address of DNS server (in dotted decimal notation) ");
fprintf(stderr,"to which the query should be sent\n");
exit(1);
}


char* WChar2char(wchar_t * src, char * ppDest) {
size_t convertedChars = 0;
size_t origsize = wcslen(src) + 1;
wcstombs_s(&convertedChars, ppDest, origsize, src, _TRUNCATE);
return (char*)ppDest;
}

void Char2Wchar(char* src, wchar_t * ppDest) {
size_t convertedChars = 0;
size_t origsize = strlen(src) + 1;
mbstowcs_s(&convertedChars, ppDest, origsize, src, _TRUNCATE);
}

void ReverseIP(wchar_t* pIP)
{
wchar_t seps[1]; seps[0] = (wchar_t)'.';
wchar_t *token;
char pIPSec[4][4];
int i=0;
token = wcstok( pIP, seps);
while( token != NULL )
{
/* While there are "." characters in "string" */
sprintf(pIPSec[i],"%s", token);
/* Get next "." character: */
token = wcstok( NULL, seps );
i++;
}
swprintf(pIP,L"%s.%s.%s.%s.%s", pIPSec[3],pIPSec[2],pIPSec[1],pIPSec[0],"IN-ADDR.ARPA");
}


// the main function
void __cdecl main(int argc, char *argv[])
{
DNS_STATUS status; //Return value of DnsQuery_A() function.
PDNS_RECORD pDnsRecord; //Pointer to DNS_RECORD structure.
PIP4_ARRAY pSrvList = NULL; //Pointer to IP4_ARRAY structure.
WORD wType; //Type of the record to be queried.
wchar_t pOwnerName[255]; //Owner name to be queried.
wchar_t pReversedIP[255]; //Reversed IP address.
wchar_t DnsServIp[255]; //DNS server ip address.
DNS_FREE_TYPE freetype ;
freetype = DnsFreeRecordListDeep;
IN_ADDR ipaddr;
char * chOwnerName = NULL;

if(argc > 4) {
for(int i = 1; i < argc ; i++) {
if ( (argv[i][0] == '-') || (argv[i][0] == '/') ) {
switch(tolower(argv[i][1])) {
case 'n':
//pOwnername=
chOwnerName = argv[++i];
Char2Wchar(chOwnerName, (wchar_t *) pOwnerName);
break;
case 't':
if (!stricmp(argv[i+1], "A") )
wType = DNS_TYPE_A; //Query host records to resolve a name.
else if (!stricmp(argv[i+1], "PTR") )
{
//pOwnerName should be in "xxx.xxx.xxx.xxx" format
if(wcslen(pOwnerName)<=15)
{
//You must reverse the IP address to request a Reverse Lookup
//of a host name.
swprintf(pReversedIP,L"%s",pOwnerName);
ReverseIP(pReversedIP);
size_t sizeRev = wcslen(pReversedIP) + 1;
wcsncpy_s(pOwnerName, sizeRev, pOwnerName, 255);
//pOwnerName=pReversedIP;
wType = DNS_TYPE_PTR; //Query PTR records to resolve an IP address
}
else
{
Usage(argv[0]);
}
}
else
Usage(argv[0]);
i++;
break;

case 's':
// Allocate memory for IP4_ARRAY structure.
pSrvList = (PIP4_ARRAY) LocalAlloc(LPTR,sizeof(IP4_ARRAY));
if(!pSrvList){
printf("Memory allocation failed \n");
exit(1);
}
if(argv[++i]) {
wchar_t aarray[300];
Char2Wchar(argv[i], (wchar_t*)aarray);
wcscpy(DnsServIp,aarray);
char tmp[500];

pSrvList->AddrCount = 1;
pSrvList->AddrArray[0] = inet_addr(WChar2char(DnsServIp, (char*) tmp)); //DNS server IP address
break;
}

default:
Usage(argv[0]);
break;
}
}
else
Usage(argv[0]);
}
}
else
Usage(argv[0]);

// Calling function DnsQuery to query Host or PTR records
status = DnsQuery(pOwnerName, //Pointer to OwnerName.
wType, //Type of the record to be queried.
DNS_QUERY_BYPASS_CACHE, // Bypasses the resolver cache on the lookup.
pSrvList, //Contains DNS server IP address.
&pDnsRecord, //Resource record that contains the response.
NULL); //Reserved for future use.

if (status){
if(wType == DNS_TYPE_A)
printf("Failed to query the host record for %s and the error is %d \n", pOwnerName, status);
else
printf("Failed to query the PTR record and the error is %d \n", status);
} else {
if(wType == DNS_TYPE_A) {
//convert the Internet network address into a string
//in Internet standard dotted format.
ipaddr.S_un.S_addr = (pDnsRecord->Data.A.IpAddress);
printf("The IP address of the host %s is %s \n", pOwnerName,inet_ntoa(ipaddr));

// Free memory allocated for DNS records.
DnsRecordListFree(pDnsRecord, freetype);
}
else {
printf("The host name is %s \n",(pDnsRecord->Data.PTR.pNameHost));

// Free memory allocated for DNS records.
DnsRecordListFree(pDnsRecord, freetype);
}
}
LocalFree(pSrvList);
}




(keywords: DNS, DnsQuery, Windows Server 2008 R2 )

Friday, July 03, 2009

VoIP - Configuração caseira

Eu cheguei em Brasília com meu aparelho de VoIP debaixo do braço. Sabia que o provedor de acesso à Internet - BR Turbo - na casa onde ia ficar tinha um 'programinha' que pedia usuário e senha para conectar, mas não sabia ao certo que autenticação era essa.

Como diria Jack, vamos por partes.

No Canadá, a coisa funcionava de forma mais ou menos simples.


No Canadá eu tive que habilitar umas portas UDP no firewall pro SIP.

No Brasil, descobri que a chave da coisa era o PPPoE. O PPPoE é o protocolo padrão de autenticação do meu ISP - no caso a BR Turbo. Como o PAP2 não 'fala' PPPoE, tive que pôr um outro roteador como cliente do roteador 'principal' que falava PPPoE. Minha primeira tentativa, no entanto, não funcionou:
Não precisei abrir portas UDP no Brasil.

O problema do esquema acima é que o servidor do outro lado do modem não conseguia estabelecer várias sessões de PPPoE com os vários clientes. Alguns clientes conseguiam estabelecer a sessão, mas o servidor 'bloqueava' ou 'desconsiderava' novas sessões.

Portanto, simplifiquei a coisa na segunda configuração, que é a configuração final. Como um dos roteadores já falava PPPoE, deixei só esse roteador, que é também um roteador wireless. A configuração final ficou assim: