--- chan_sip.c.dist 2004-05-09 19:40:49.000000000 -0400 +++ chan_sip.c.patched_1 2004-05-11 16:48:39.000000000 -0400 @@ -5108,25 +5108,18 @@ return; } -static int sip_do_debug_ip(int fd, int argc, char *argv[]) +static int sip_do_debug_ip(int fd, const char *hostarg) { struct hostent *hp; struct ast_hostent ahp; int port = 0; - char *p, *arg; - if (argc != 4) + char *p; + p = strstr(hostarg, ":"); + if (p) + port = atoi(++p); + hp = ast_gethostbyname(hostarg, &ahp); + if (hp == NULL) return RESULT_SHOWUSAGE; - arg = argv[3]; - p = strstr(arg, ":"); - if (p) { - *p = '\0'; - p++; - port = atoi(p); - } - hp = ast_gethostbyname(arg, &ahp); - if (hp == NULL) { - return RESULT_SHOWUSAGE; - } debugaddr.sin_family = AF_INET; memcpy(&debugaddr.sin_addr, hp->h_addr, sizeof(debugaddr.sin_addr)); debugaddr.sin_port = htons(port); @@ -5138,19 +5131,17 @@ return RESULT_SUCCESS; } -static int sip_do_debug_peer(int fd, int argc, char *argv[]) +static int sip_do_debug_peer(int fd, const char *peerarg) { struct sip_peer *peer; - if (argc != 4) - return RESULT_SHOWUSAGE; ast_mutex_lock(&peerl.lock); for (peer = peerl.peers;peer;peer = peer->next) - if (!strcmp(peer->name, argv[3])) + if (!strcmp(peer->name, peerarg)) break; ast_mutex_unlock(&peerl.lock); #ifdef MYSQL_FRIENDS if (!peer) - peer = mysql_peer(argv[3], NULL); + peer = mysql_peer(peerarg, NULL); #endif if (peer) { if (peer->addr.sin_addr.s_addr) { @@ -5160,12 +5151,12 @@ ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", inet_ntoa(debugaddr.sin_addr), ntohs(debugaddr.sin_port)); sipdebug = 1; } else - ast_cli(fd, "Unable to get IP address of peer '%s'\n", argv[3]); - if (peer->temponly) - free(peer); + ast_cli(fd, "Unable to get IP address of peer '%s'\n", peerarg); + if (peer->temponly) /* why is this done? */ + free(peer); /*XXX don't we have to unlink this peer first? XXX*/ peer = NULL; } else - ast_cli(fd, "No such peer '%s'\n", argv[3]); + ast_cli(fd, "No such peer '%s'\n", peerarg); return RESULT_SUCCESS; } @@ -5174,10 +5165,10 @@ if (argc != 2) { if (argc != 4) return RESULT_SHOWUSAGE; - else if (strncmp(argv[2], "ip\0", 3) == 0) - return sip_do_debug_ip(fd, argc, argv); - else if (strncmp(argv[2], "peer\0", 5) == 0) - return sip_do_debug_peer(fd, argc, argv); + else if (strcasecmp(argv[2], "ip") == 0) + return sip_do_debug_ip(fd, argv[3]); + else if (strcasecmp(argv[2], "peer") == 0) + return sip_do_debug_peer(fd, argv[3]); else return RESULT_SHOWUSAGE; } sipdebug = 1;