Re: sscanf question



Hi,

The following is the piece of code I'm using, and it's output.

Thanks,

Andre


#include <stdio.h>

char buf1[] = "c0a80174.13e1;received=207.81.158.209\r\nVia:
SIP/2.0/UDP\r\n192.168.1.116:5089;branch=z9hG4bK20445d6f-8279-db11-9cdf-00112f2f2fed;rport\r\nFrom:
<sip:102@xxxxxxxxxxxxx>;tag=fa375d6f-8279-db11-9cdf-00112f2f2fed\r\nTo:
<sip:102@xxxxxxxxxxxxx>\r\nCall-ID:
f6ff5c6f-8279-db11-9cdf-00112f2f2fed@dilbert\r\nCSeq: 2363
REGISTER\r\nUser-Agent: Asterisk PBX\r\nAllow: INVITE, ACK, CANCEL,
OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY\r\nContact:
<sip:102@xxxxxxxxxxxxxx\r\nContent-Length: 0\r\n";

char buf2[] = "z9hG4bK3c36655c;rport\r\nFrom: \"asterisk\"
<sip:asterisk@xxxxxxxxxxxxxx>;tag=as41da1dfe\r\nTo:
<sip:102@xxxxxxxxxxxxx:5089;transport=udp>\r\nContact:
<sip:asterisk@xxxxxxxxxxxxxx>\r\nCall-ID:
3d1983143939d5141ccd181f2db26e19@xxxxxxxxxxxxxx\r\nCSeq: 102
OPTIONS\r\nUser-Agent: Asterisk PBX\r\nMax-Forwards: 70\r\nDate: Thu,
23 Nov 2006 17:02:40 GMT\r\nAllow: INVITE, ACK, CANCEL, OPTIONS, BYE,
REFER, SUBSCRIBE, NOTIFY\r\nContent-Length: 0\r\n";

int main()
{
int ip = 0;
int port = 0;

sscanf(buf1, "%x.%x", &ip, &port);
printf("buf1: ip=%d port=%d\n", ip, port);

ip = 0;
port = 0;

sscanf(buf2, "%x.%x", &ip, &port);
printf("buf2: ip=%d port=%d\n", ip, port);

return 0;
}

Output:

buf1: ip=-1062731404 port=5089
buf2: ip=0 port=0

.



Relevant Pages

  • Re: sscanf question
    ... int main ... Use unsigned int for the "%x" conversion specifier, ...
    (comp.lang.c)
  • Improving read/write/close system call reliability when used with pthreads
    ... Whether or not close may cancel I/O operations appears to be implementation-defined if I interpret the following section correctly, unless anyone knows more specific details? ... When there is an outstanding cancelable asynchronous I/O operation against fildes when closeis called, that I/O operation may be canceled. ... int main ... struct files_struct *files; ...
    (Linux-Kernel)
  • [PATCH 21/47] New version of CRISv32 I2C driver.
    ... generate ACK clock pulse ... int error, cntr = 3; ... int i2c_writereg(unsigned char theSlave, unsigned char theReg, unsigned char theValue); ...
    (Linux-Kernel)
  • Re: [PATCH] elf loader support for auxvec base platform string
    ... Should I seek somebody's ack before merging a patch like the one below? ... example, on a Power6 system in Power5+ compatibility mode, AT_PLATFORM ... static int ...
    (Linux-Kernel)
  • Re: What do you do in the real world?
    ... Putting in your expected nordo procedure (if it deviates from FARs) int he comments section is a good idea. ... They cancel and stop all flights while you fly wherever you want? ... Flights are neither cancelled nor stopped. ...
    (rec.aviation.ifr)