/** get protocol name (asciiz). * @param proto - protocol number * @return string with the protocol name or "unknown". */ char* get_proto_name(unsigned int proto) { str sproto; switch(proto){ case PROTO_NONE: return "*"; default: if(get_valid_proto_string(proto, 1, 0, &sproto)<0) return "unknown"; return sproto.s; } }
int pv_get_sndto(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct onsend_info* snd_inf; struct ip_addr ip; str s; snd_inf=get_onsend_info(); if (! likely(snd_inf && snd_inf->send_sock)) return pv_get_null(msg, param, res); switch(param->pvn.u.isname.name.n) { case 1: /* af */ return pv_get_uintval(msg, param, res, (int)snd_inf->send_sock->address.af); case 2: /* port */ return pv_get_uintval(msg, param, res, (int)su_getport(snd_inf->to)); case 3: /* proto */ return pv_get_uintval(msg, param, res, (int)snd_inf->send_sock->proto); case 4: /* buf */ s.s = snd_inf->buf; s.len = snd_inf->len; return pv_get_strval(msg, param, res, &s); case 5: /* len */ return pv_get_uintval(msg, param, res, (int)snd_inf->len); case 6: /* sproto */ if(get_valid_proto_string((int)snd_inf->send_sock->proto, 0, 0, &s)<0) return pv_get_null(msg, param, res); return pv_get_strval(msg, param, res, &s); default: /* 0 - ip */ su2ip_addr(&ip, snd_inf->to); s.s = ip_addr2a(&ip); s.len = strlen(s.s); return pv_get_strval(msg, param, res, &s); } return 0; }
/** * get source ip, port and protocol in SIP URI format * - tmode - 0: short format (transport=udp is not added, being default) */ int get_src_uri(sip_msg_t *m, int tmode, str *uri) { static char buf[MAX_URI_SIZE]; char* p; str ip, port; int len; str proto; if (!uri || !m) { ERR("invalid parameter value\n"); return -1; } if(tmode==0) { switch(m->rcv.proto) { case PROTO_NONE: case PROTO_UDP: proto.s = 0; /* Do not add transport parameter, UDP is default */ proto.len = 0; break; default: if(get_valid_proto_string(m->rcv.proto, 1, 0, &proto)<0) { ERR("unknown transport protocol\n"); return -1; } } } else { if(get_valid_proto_string(m->rcv.proto, 1, 0, &proto)<0) { ERR("unknown transport protocol\n"); return -1; } } ip.s = ip_addr2a(&m->rcv.src_ip); ip.len = strlen(ip.s); port.s = int2str(m->rcv.src_port, &port.len); len = 4 + ip.len + 2*(m->rcv.src_ip.af==AF_INET6)+ 1 + port.len; if (proto.s) { len += TRANSPORT_PARAM_LEN; len += proto.len; } if (len > MAX_URI_SIZE) { ERR("buffer too small\n"); return -1; } p = buf; memcpy(p, "sip:", 4); p += 4; if (m->rcv.src_ip.af==AF_INET6) *p++ = '['; memcpy(p, ip.s, ip.len); p += ip.len; if (m->rcv.src_ip.af==AF_INET6) *p++ = ']'; *p++ = ':'; memcpy(p, port.s, port.len); p += port.len; if (proto.s) { memcpy(p, TRANSPORT_PARAM, TRANSPORT_PARAM_LEN); p += TRANSPORT_PARAM_LEN; memcpy(p, proto.s, proto.len); p += proto.len; } uri->s = buf; uri->len = len; return 0; }