- fixed freebsd version : instead on local on stack sockaddr_in structures use ...
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Thu, 6 Sep 2001 03:58:35 +0000 (03:58 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Thu, 6 Sep 2001 03:58:35 +0000 (03:58 +0000)
forward.c
sip_router.cfg
udp_server.c

index 64dc6bb..036ba33 100644 (file)
--- a/forward.c
+++ b/forward.c
@@ -69,9 +69,16 @@ int forward_request(char * orig, char* buf,
        char received_buf[MAX_RECEIVED_SIZE];
        char* new_buf;
        int offset, s_offset, size;
-       struct sockaddr_in to;
+       struct sockaddr_in* to;
 
        received_len=0;
+       new_buf=0;
+       to=0;
+       to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
+       if (to==0){
+               DPrint("ERROR: forward_reply: out of memory\n");
+               goto error;
+       }
 
        via_len=snprintf(line_buf, MAX_VIA_LINE_SIZE, "Via: SIP/2.0/UDP %s:%d\r\n",
                                                names[0], port_no);
@@ -86,7 +93,7 @@ int forward_request(char * orig, char* buf,
        new_buf=(char*)malloc(new_len+1);
        if (new_buf==0){
                DPrint("ERROR: forward_request: out of memory\n");
-               goto error1;
+               goto error;
        }
 /* copy msg till first via */
        offset=s_offset=0;
@@ -123,8 +130,8 @@ int forward_request(char * orig, char* buf,
        printf("orig. len=%d, new_len=%d, via_len=%d, received_len=%d\n",
                        len, new_len, via_len, received_len);
 
-       to.sin_family = AF_INET;
-       to.sin_port = (re->port)?htons(re->port):htons(SIP_PORT);
+       to->sin_family = AF_INET;
+       to->sin_port = (re->port)?htons(re->port):htons(SIP_PORT);
        /* if error try next ip address if possible */
        if (re->ok==0){
                if (re->host.h_addr_list[re->current_addr_idx+1])
@@ -132,21 +139,22 @@ int forward_request(char * orig, char* buf,
                re->ok=1;
        }
        /* ? not 64bit clean?*/
-       to.sin_addr.s_addr=*((long*)re->host.h_addr_list[re->current_addr_idx]);
+       to->sin_addr.s_addr=*((long*)re->host.h_addr_list[re->current_addr_idx]);
 
        re->tx++;
        re->tx_bytes+=new_len;
-       if (udp_send(new_buf, new_len, &to, sizeof(to))==-1){
+       if (udp_send(new_buf, new_len, to, sizeof(struct sockaddr))==-1){
                        re->errors++;
                        re->ok=0;
                        goto error;
        }
 
        free(new_buf);
+       free(to);
        return 0;
 error:
-       free(new_buf);
-error1:
+       if (new_buf) free(new_buf);
+       if (to) free(to);
        return -1;
 
 }
@@ -164,9 +172,15 @@ int forward_reply(char * orig, char* buf,
        char* new_buf;
        int offset, s_offset, size;
        struct hostent* he;
-       struct sockaddr_in to;
+       struct sockaddr_in* to;
 
        new_buf=0;
+       to=0;
+       to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
+       if (to==0){
+               DPrint("ERROR: forward_reply: out of memory\n");
+               goto error;
+       }
 
        /*check if first via host = us */
        if (check_via){
@@ -209,17 +223,19 @@ int forward_reply(char * orig, char* buf,
                DPrint("ERROR:forward_reply:gethostbyname failure\n");
                goto error;
        }
-       to.sin_family = AF_INET;
-       to.sin_port = (msg->via2.port)?htons(msg->via2.port):htons(SIP_PORT);
-       to.sin_addr.s_addr=*((long*)he->h_addr_list[0]);
+       to->sin_family = AF_INET;
+       to->sin_port = (msg->via2.port)?htons(msg->via2.port):htons(SIP_PORT);
+       to->sin_addr.s_addr=*((long*)he->h_addr_list[0]);
        
        if (udp_send(new_buf,new_len, &to, sizeof(to))==-1)
                goto error;
        
        free(new_buf);
+       free(to);
        return 0;
 
 error:
        if (new_buf) free(new_buf);
+       if (to) free(to);
        return -1;
 }
index c12d898..3f63060 100644 (file)
@@ -4,7 +4,7 @@
 #  method_re   sip_uri_re      dest_host
 # (warning: re cannot contain space)
 
-#.*                    .*                                 centauri.fokus.gmd.de 
+.*                     .*                                 mobile50 
 .                      .                                  fox.iptel.org
 ^R.*        ^sip:.*@dorian.*   ekina.fokus.gmd.de        
 ^INVITE     .*                 ape:5061             # my laptop
index fdde4f0..6532225 100644 (file)
@@ -19,12 +19,17 @@ int udp_sock;
 
 int udp_init(unsigned long ip, unsigned short port)
 {
-       struct sockaddr_in addr;
+       struct sockaddr_in* addr;
        int optval;
 
-       addr.sin_family=AF_INET;
-       addr.sin_port=htons(port);
-       addr.sin_addr.s_addr=ip;
+       addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
+       if (addr==0){
+               DPrint("ERROR: udp_init: out of memory\n");
+               goto error;
+       }
+       addr->sin_family=AF_INET;
+       addr->sin_port=htons(port);
+       addr->sin_addr.s_addr=ip;
 
        udp_sock = socket(PF_INET, SOCK_DGRAM, 0);
        if (udp_sock==-1){
@@ -40,15 +45,16 @@ int udp_init(unsigned long ip, unsigned short port)
                goto error;
        }
 
-       if (bind(udp_sock, (struct sockaddr*) &addr, sizeof(addr))==-1){
+       if (bind(udp_sock, (struct sockaddr*) addr, sizeof(struct sockaddr))==-1){
                DPrint("ERROR: udp_init: bind: %s\n", strerror());
                goto error;
        }
 
-
+       free(addr);
        return 0;
 
 error:
+       if (addr) free(addr);
        return -1;
 }