int ooSocketGetIpAndPort(OOSOCKET socket, char *ip, int len, int *port, int *family) { int ret=ASN_OK; struct ast_sockaddr addr; const char *host=NULL; ret = ast_getsockname(socket, &addr); if(ret != 0) return ASN_E_INVSOCKET; host = ast_sockaddr_stringify_addr(&addr); if(host && strlen(host) < (unsigned)len) strcpy(ip, host); else{ OOTRACEERR1("Error:Insufficient buffer for ip address - " "ooSocketGetIpAndPort\n"); return -1; } *port = ast_sockaddr_port(&addr); if (family) { if (ast_sockaddr_is_ipv6(&addr) && !ast_sockaddr_is_ipv4_mapped(&addr)) *family = 6; else *family = 4; } return ASN_OK; }
int ast_set_qos(int sockfd, int tos, int cos, const char *desc) { int res = 0; int set_tos; int set_tclass; struct ast_sockaddr addr; /* If the sock address is IPv6, the TCLASS field must be set. */ set_tclass = !ast_getsockname(sockfd, &addr) && ast_sockaddr_is_ipv6(&addr) ? 1 : 0; /* If the the sock address is IPv4 or (IPv6 set to any address [::]) set TOS bits */ set_tos = (!set_tclass || (set_tclass && ast_sockaddr_is_any(&addr))) ? 1 : 0; if (set_tos) { if ((res = setsockopt(sockfd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) { ast_log(LOG_WARNING, "Unable to set %s DSCP TOS value to %d (may be you have no " "root privileges): %s\n", desc, tos, strerror(errno)); } else if (tos) { ast_verb(2, "Using %s TOS bits %d\n", desc, tos); } } #if defined(IPV6_TCLASS) && defined(IPPROTO_IPV6) if (set_tclass) { if (!ast_getsockname(sockfd, &addr) && ast_sockaddr_is_ipv6(&addr)) { if ((res = setsockopt(sockfd, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)))) { ast_log(LOG_WARNING, "Unable to set %s DSCP TCLASS field to %d (may be you have no " "root privileges): %s\n", desc, tos, strerror(errno)); } else if (tos) { ast_verb(2, "Using %s TOS bits %d in TCLASS field.\n", desc, tos); } } } #endif #ifdef linux if (setsockopt(sockfd, SOL_SOCKET, SO_PRIORITY, &cos, sizeof(cos))) { ast_log(LOG_WARNING, "Unable to set %s CoS to %d: %s\n", desc, cos, strerror(errno)); } else if (cos) { ast_verb(2, "Using %s CoS mark %d\n", desc, cos); } #endif return res; }