a4cfc4a2c2677ba5e9cdd953565bf969f91bed87
[sip-router] / parser / parse_hostport.c
1 /*
2  * $Id$
3  */
4
5 #include "parse_hostport.h"
6 #include <string.h>    /* strlen */
7 #include "../dprint.h"
8 #include "../ut.h"     /* str2s */
9
10 char* parse_hostport(char* buf, str* host, short int* port)
11 {
12         char *tmp;
13         int err;
14
15         host->s=buf;
16         for(tmp=buf;(*tmp)&&(*tmp!=':');tmp++);
17         host->len=tmp-buf;
18         if (*tmp==0) {
19                 *port=0;
20         } else {
21                 *tmp=0;
22                 *port=str2s((unsigned char*)(tmp+1), strlen(tmp+1), &err);
23                 if (err ){
24                         LOG(L_INFO, 
25                             "ERROR: hostport: trailing chars in port number: %s\n",
26                             tmp+1);
27                              /* report error? */
28                 }
29         }
30
31         return host->s;
32 }