diff options
author | Russell Bryant <russell@russellbryant.com> | 2006-07-21 17:31:28 +0000 |
---|---|---|
committer | Russell Bryant <russell@russellbryant.com> | 2006-07-21 17:31:28 +0000 |
commit | ca9ba719b6f4ef598bc3dc71bdee05d11d0c7687 (patch) | |
tree | 9a03027276c525f44c08eb5dc4d7b9035fa697c9 /channels/chan_mgcp.c | |
parent | 1861dcdff5666cbac27288f7bdfdf40104d29d4d (diff) |
Merge a new implementation of ast_inet_ntoa, our thread safe replacement for
inet_ntoa, which uses thread specific data (aka thread local storage) instead
of stack allocatted buffers to store the result.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@38042 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_mgcp.c')
-rw-r--r-- | channels/chan_mgcp.c | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 0d1a857a1..b70e17154 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -498,9 +498,8 @@ static int resend_response(struct mgcp_subchannel *sub, struct mgcp_response *re { struct mgcp_endpoint *p = sub->parent; int res; - char iabuf[INET_ADDRSTRLEN]; if (mgcpdebug) { - ast_verbose("Retransmitting:\n%s\n to %s:%d\n", resp->buf, ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); + ast_verbose("Retransmitting:\n%s\n to %s:%d\n", resp->buf, ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); } res = __mgcp_xmit(p->parent, resp->buf, resp->len); if (res > 0) @@ -512,9 +511,8 @@ static int send_response(struct mgcp_subchannel *sub, struct mgcp_request *req) { struct mgcp_endpoint *p = sub->parent; int res; - char iabuf[INET_ADDRSTRLEN]; if (mgcpdebug) { - ast_verbose("Transmitting:\n%s\n to %s:%d\n", req->data, ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); + ast_verbose("Transmitting:\n%s\n to %s:%d\n", req->data, ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); } res = __mgcp_xmit(p->parent, req->data, req->len); if (res > 0) @@ -736,7 +734,6 @@ static int send_request(struct mgcp_endpoint *p, struct mgcp_subchannel *sub, { int res = 0; struct mgcp_request **queue, *q, *r, *t; - char iabuf[INET_ADDRSTRLEN]; ast_mutex_t *l; ast_log(LOG_DEBUG, "Slow sequence is %d\n", p->slowsequence); @@ -792,14 +789,14 @@ static int send_request(struct mgcp_endpoint *p, struct mgcp_subchannel *sub, if (!(*queue)) { if (mgcpdebug) { ast_verbose("Posting Request:\n%s to %s:%d\n", req->data, - ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); + ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); } res = mgcp_postrequest(p, sub, req->data, req->len, seqno); } else { if (mgcpdebug) { ast_verbose("Queueing Request:\n%s to %s:%d\n", req->data, - ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); + ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); } } @@ -1019,7 +1016,6 @@ static int mgcp_show_endpoints(int fd, int argc, char *argv[]) struct mgcp_gateway *g; struct mgcp_endpoint *e; int hasendpoints = 0; - char iabuf[INET_ADDRSTRLEN]; if (argc != 3) return RESULT_SHOWUSAGE; @@ -1027,7 +1023,7 @@ static int mgcp_show_endpoints(int fd, int argc, char *argv[]) g = gateways; while(g) { e = g->endpoints; - ast_cli(fd, "Gateway '%s' at %s (%s)\n", g->name, g->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), g->addr.sin_addr) : ast_inet_ntoa(iabuf, sizeof(iabuf), g->defaddr.sin_addr), g->dynamic ? "Dynamic" : "Static"); + ast_cli(fd, "Gateway '%s' at %s (%s)\n", g->name, g->addr.sin_addr.s_addr ? ast_inet_ntoa(g->addr.sin_addr) : ast_inet_ntoa(g->defaddr.sin_addr), g->dynamic ? "Dynamic" : "Static"); while(e) { /* Don't show wilcard endpoint */ if (strcmp(e->name, g->wcardep) !=0) @@ -1536,7 +1532,6 @@ static struct mgcp_subchannel *find_subchannel_and_lock(char *name, int msgid, s struct mgcp_endpoint *p = NULL; struct mgcp_subchannel *sub = NULL; struct mgcp_gateway *g; - char iabuf[INET_ADDRSTRLEN]; char tmp[256] = ""; char *at = NULL, *c; int found = 0; @@ -1568,7 +1563,7 @@ static struct mgcp_subchannel *find_subchannel_and_lock(char *name, int msgid, s if (ast_ouraddrfor(&g->addr.sin_addr, &g->ourip)) memcpy(&g->ourip, &__ourip, sizeof(g->ourip)); if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "Registered MGCP gateway '%s' at %s port %d\n", g->name, ast_inet_ntoa(iabuf, sizeof(iabuf), g->addr.sin_addr), ntohs(g->addr.sin_port)); + ast_verbose(VERBOSE_PREFIX_3 "Registered MGCP gateway '%s' at %s port %d\n", g->name, ast_inet_ntoa(g->addr.sin_addr), ntohs(g->addr.sin_port)); } } /* not dynamic, check if the name matches */ @@ -1791,7 +1786,7 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req) sin.sin_port = htons(portno); ast_rtp_set_peer(sub->rtp, &sin); #if 0 - printf("Peer RTP is at port %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port)); + printf("Peer RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); #endif /* Scan through the RTP payload types specified in a "m=" line: */ ast_rtp_pt_clear(sub->rtp); @@ -1972,7 +1967,6 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc char t[256]; char m[256] = ""; char a[1024] = ""; - char iabuf[INET_ADDRSTRLEN]; int x; struct sockaddr_in dest; struct mgcp_endpoint *p = sub->parent; @@ -1998,12 +1992,12 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc } } if (mgcpdebug) { - ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->ourip), ntohs(sin.sin_port)); + ast_verbose("We're at %s port %d\n", ast_inet_ntoa(p->parent->ourip), ntohs(sin.sin_port)); } snprintf(v, sizeof(v), "v=0\r\n"); - snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", getpid(), getpid(), ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr)); + snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", getpid(), getpid(), ast_inet_ntoa(dest.sin_addr)); snprintf(s, sizeof(s), "s=session\r\n"); - snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr)); + snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(dest.sin_addr)); snprintf(t, sizeof(t), "t=0 0\r\n"); snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port)); for (x = 1; x <= AST_FORMAT_MAX_AUDIO; x <<= 1) { @@ -2334,7 +2328,6 @@ static struct mgcp_request *find_command(struct mgcp_endpoint *p, struct mgcp_su struct mgcp_request **queue, ast_mutex_t *l, int ident) { struct mgcp_request *prev, *req; - char iabuf[INET_ADDRSTRLEN]; ast_mutex_lock(l); for (prev = NULL, req = *queue; req; prev = req, req = req->next) { @@ -2349,7 +2342,7 @@ static struct mgcp_request *find_command(struct mgcp_endpoint *p, struct mgcp_su if (*queue) { if (mgcpdebug) { ast_verbose("Posting Queued Request:\n%s to %s:%d\n", (*queue)->data, - ast_inet_ntoa(iabuf, sizeof(iabuf), p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); + ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); } mgcp_postrequest(p, sub, (*queue)->data, (*queue)->len, (*queue)->trid); @@ -2954,7 +2947,6 @@ static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req, struct ast_frame f = { 0, }; struct mgcp_endpoint *p = sub->parent; struct mgcp_gateway *g = NULL; - char iabuf[INET_ADDRSTRLEN]; int res; if (mgcpdebug) { @@ -3204,7 +3196,7 @@ static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req, ast_log(LOG_NOTICE, "Received unknown event '%s' from %s@%s\n", ev, p->name, p->parent->name); } } else { - ast_log(LOG_WARNING, "Unknown verb '%s' received from %s\n", req->verb, ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr)); + ast_log(LOG_WARNING, "Unknown verb '%s' received from %s\n", req->verb, ast_inet_ntoa(sin->sin_addr)); transmit_response(sub, "510", req, "Unknown verb"); } return 0; @@ -3251,7 +3243,6 @@ static int mgcpsock_read(int *id, int fd, short events, void *ignore) socklen_t len; int result; int ident; - char iabuf[INET_ADDRSTRLEN]; len = sizeof(sin); memset(&req, 0, sizeof(req)); res = recvfrom(mgcpsock, req.data, sizeof(req.data) - 1, 0, (struct sockaddr *)&sin, &len); @@ -3263,7 +3254,7 @@ static int mgcpsock_read(int *id, int fd, short events, void *ignore) req.data[res] = '\0'; req.len = res; if (mgcpdebug) { - ast_verbose("MGCP read: \n%s\nfrom %s:%d\n", req.data, ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port)); + ast_verbose("MGCP read: \n%s\nfrom %s:%d\n", req.data, ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); } parse(&req); if (req.headers < 1) { @@ -3271,7 +3262,7 @@ static int mgcpsock_read(int *id, int fd, short events, void *ignore) return 1; } if (ast_strlen_zero(req.identifier)) { - ast_log(LOG_NOTICE, "Message from %s missing identifier\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr)); + ast_log(LOG_NOTICE, "Message from %s missing identifier\n", ast_inet_ntoa(sin.sin_addr)); return 1; } @@ -4049,7 +4040,6 @@ static int reload_config(void) struct ast_variable *v; struct mgcp_gateway *g; struct mgcp_endpoint *e; - char iabuf[INET_ADDRSTRLEN]; char *cat; struct ast_hostent ahp; struct hostent *hp; @@ -4192,14 +4182,14 @@ static int reload_config(void) } else { if (bind(mgcpsock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) { ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n", - ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port), + ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port), strerror(errno)); close(mgcpsock); mgcpsock = -1; } else { if (option_verbose > 1) { ast_verbose(VERBOSE_PREFIX_2 "MGCP Listening on %s:%d\n", - ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port)); + ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port)); ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos); } if (setsockopt(mgcpsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) |