- msg_send(), udp_send() and tcp_send() parameter list changed
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Wed, 12 Apr 2006 18:04:23 +0000 (18:04 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Wed, 12 Apr 2006 18:04:23 +0000 (18:04 +0000)
 (now they use a struct dest_info to pack several of the old params)

16 files changed:
Makefile.defs
action.c
forward.c
forward.h
ip_addr.h
modules/tm/t_funcs.c
modules/tm/t_fwd.c
modules/tm/t_lookup.c
modules/tm/t_reply.c
modules/tm/uac.c
onsend.h
tcp_main.c
tcp_server.h
udp_server.c
udp_server.h
utils/sercmd/sercmd.c

index 5851174..473d026 100644 (file)
@@ -66,7 +66,7 @@ MAIN_NAME=ser
 VERSION = 0
 PATCHLEVEL = 10
 SUBLEVEL =   99
-EXTRAVERSION = -dev37
+EXTRAVERSION = -dev38
 
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
                        $(SUBLEVEL) )
index a1d0498..5c9b3b9 100644 (file)
--- a/action.c
+++ b/action.c
@@ -40,6 +40,7 @@
  *  2004-11-30  added FORCE_SEND_SOCKET_T (andrei)
  *  2005-12-12  return & drop/exit differentiation (andrei)
  *  2005-12-19  select framework (mma)
+ *  2006-04-12  updated *_send() calls to use a struct dest_info (andrei)
  */
 
 
@@ -95,8 +96,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 {
        int ret;
        int v;
-       union sockaddr_union* to;
-       struct socket_info* send_sock;
+       struct dest_info dst;
        struct proxy_l* p;
        char* tmp;
        char *new_uri, *end, *crt;
@@ -222,7 +222,8 @@ int do_action(struct action* a, struct sip_msg* msg)
                        }else if ((a->val[0].type==PROXY_ST) && (a->val[1].type==NUMBER_ST)){
                                if (proto==PROTO_NONE)
                                        proto=msg->rcv.proto;
-                               ret=forward_request(msg,(struct proxy_l*)a->val[0].u.data, proto);
+                               ret=forward_request(msg, (struct proxy_l*)a->val[0].u.data,
+                                                                               proto);
                                if (ret>=0) ret=1;
                        }else{
                                LOG(L_CRIT, "BUG: do_action: bad forward() types %d, %d\n",
@@ -238,17 +239,7 @@ int do_action(struct action* a, struct sip_msg* msg)
                                ret=E_BUG;
                                break;
                        }
-                       to=(union sockaddr_union*)
-                                       pkg_malloc(sizeof(union sockaddr_union));
-                       if (to==0){
-                               LOG(L_ERR, "ERROR: do_action: "
-                                                       "memory allocation failure\n");
-                               ret=E_OUT_OF_MEM;
-                               break;
-                       }
-
                        p=(struct proxy_l*)a->val[0].u.data;
-
                        if (p->ok==0){
                                if (p->host.h_addr_list[p->addr_idx+1])
                                        p->addr_idx++;
@@ -256,7 +247,7 @@ int do_action(struct action* a, struct sip_msg* msg)
                                        p->addr_idx=0;
                                p->ok=1;
                        }
-                       ret=hostent2su( to, &p->host, p->addr_idx,
+                       ret=hostent2su(&dst.to, &p->host, p->addr_idx,
                                                (p->port)?p->port:SIP_PORT );
                        if (ret==0){
                                if (p_onsend){
@@ -270,9 +261,10 @@ int do_action(struct action* a, struct sip_msg* msg)
                                p->tx_bytes+=len;
                                if (a->type==SEND_T){
                                        /*udp*/
-                                       send_sock=get_send_socket(msg, to, PROTO_UDP);
-                                       if (send_sock!=0){
-                                               ret=udp_send(send_sock, tmp, len, to);
+                                       dst.proto=PROTO_UDP; /* not really needed for udp_send */
+                                       dst.send_sock=get_send_socket(msg, &dst.to, PROTO_UDP);
+                                       if (dst.send_sock!=0){
+                                               ret=udp_send(&dst, tmp, len);
                                        }else{
                                                ret=-1;
                                        }
@@ -280,11 +272,12 @@ int do_action(struct action* a, struct sip_msg* msg)
 #ifdef USE_TCP
                                        else{
                                        /*tcp*/
-                                       ret=tcp_send(PROTO_TCP, tmp, len, to, 0);
+                                       dst.proto=PROTO_TCP;
+                                       dst.id=0;
+                                       ret=tcp_send(&dst, tmp, len);
                                }
 #endif
                        }
-                       pkg_free(to);
                        if (ret<0){
                                p->errors++;
                                p->ok=0;
index 4ba8d7d..bd38a1c 100644 (file)
--- a/forward.c
+++ b/forward.c
@@ -48,6 +48,7 @@
  *  2004-11-08  added force_send_socket support in get_send_socket (andrei)
  *  2005-12-11  onsend_router support; forward_request to no longer
  *              pkg_malloc'ed (andrei)
+ *  2006-04-12  forward_{request,reply} use now struct dest_info (andrei)
  */
 
 
@@ -260,17 +261,19 @@ found:
 
 
 
-int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
+/* parameters:
+ *   msg - sip msg
+ *   p   - proxy structure to forward to
+ *   proto - protocol used
+ */
+int forward_request(struct sip_msg* msg, struct proxy_l * p, int proto)
 {
        unsigned int len;
        char* buf;
-       union sockaddr_union to;
-       struct socket_info* send_sock;
        char md5[MD5_LEN];
-       int id; /* used as branch for tcp! */
+       struct dest_info send_info;
        
        buf=0;
-       id=0;
        
        /* if error try next ip address if possible */
        if (p->ok==0){
@@ -280,16 +283,20 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
                p->ok=1;
        }
        
-       hostent2su(&to, &p->host, p->addr_idx, 
+       hostent2su(&send_info.to, &p->host, p->addr_idx, 
                                (p->port)?p->port:SIP_PORT);
        p->tx++;
        p->tx_bytes+=len;
        
-
-       send_sock=get_send_socket(msg, &to, proto);
-       if (send_sock==0){
+       
+       send_info.proto=proto;
+       send_info.id=0;
+       send_info.send_sock=get_send_socket(msg, &send_info.to,
+                                                                                       send_info.proto);
+       if (send_info.send_sock==0){
                LOG(L_ERR, "forward_req: ERROR: cannot forward to af %d, proto %d "
-                               "no corresponding listening socket\n", to.s.sa_family, proto);
+                               "no corresponding listening socket\n",
+                               send_info.to.s.sa_family, send_info.proto);
                ser_error=E_NO_SOCKET;
                goto error;
        }
@@ -312,28 +319,30 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
                        goto error;
                }
                msg->hash_index=hash( msg->callid->body, get_cseq(msg)->number);
-               if (!branch_builder( msg->hash_index, 0, md5, id /* 0-th branch */,
+               if (!branch_builder( msg->hash_index, 0, md5, 0 /* 0-th branch */,
                                        msg->add_to_branch_s, &msg->add_to_branch_len )) {
                        LOG(L_ERR, "ERROR: forward_request: branch_builder failed\n");
                        goto error;
                }
        }
 
-       buf = build_req_buf_from_sip_req( msg, &len, send_sock,  proto);
+       buf = build_req_buf_from_sip_req(msg, &len, send_info.send_sock,
+                                                                                       send_info.proto);
        if (!buf){
                LOG(L_ERR, "ERROR: forward_request: building failed\n");
                goto error;
        }
         /* send it! */
        DBG("Sending:\n%.*s.\n", (int)len, buf);
-       DBG("orig. len=%d, new_len=%d, proto=%d\n", msg->len, len, proto );
+       DBG("orig. len=%d, new_len=%d, proto=%d\n",
+                       msg->len, len, send_info.proto );
        
-       if (run_onsend(msg, send_sock, proto, &to, buf, len)==0){
+       if (run_onsend(msg, &send_info, buf, len)==0){
                LOG(L_INFO, "forward_request: request dropped (onsend_route)\n");
                STATS_TX_DROPS;
                goto error; /* error ? */
        }
-       if (msg_send(send_sock, proto, &to, 0, buf, len)<0){
+       if (msg_send(&send_info, buf, len)<0){
                ser_error=E_SEND;
                p->errors++;
                p->ok=0;
@@ -424,18 +433,15 @@ int update_sock_struct_from_via( union sockaddr_union* to,
 int forward_reply(struct sip_msg* msg)
 {
        char* new_buf;
-       union sockaddr_union* to;
+       struct dest_info dst;
        unsigned int new_len;
        struct sr_module *mod;
-       int proto;
-       unsigned int id; /* used only by tcp*/
 #ifdef USE_TCP
        char* s;
        int len;
 #endif
        
-       to=0;
-       id=0;
+       dst.id=0;
        new_buf=0;
        /*check if first via host = us */
        if (check_via){
@@ -467,44 +473,37 @@ int forward_reply(struct sip_msg* msg)
                goto error;
        }
 
-       to=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
-       if (to==0){
-               LOG(L_ERR, "ERROR: forward_reply: out of memory\n");
-               goto error;
-       }
-
        new_buf = build_res_buf_from_sip_res( msg, &new_len);
        if (!new_buf){
                LOG(L_ERR, "ERROR: forward_reply: building failed\n");
                goto error;
        }
 
-       proto=msg->via2->proto;
-       if (update_sock_struct_from_via( to, msg, msg->via2 )==-1) goto error;
+       dst.proto=msg->via2->proto;
+       if (update_sock_struct_from_via( &dst.to, msg, msg->via2 )==-1) goto error;
 
 
 #ifdef USE_TCP
-       if (proto==PROTO_TCP
+       if (dst.proto==PROTO_TCP
 #ifdef USE_TLS
-                       || proto==PROTO_TLS
+                       || dst.proto==PROTO_TLS
 #endif
                        ){
                /* find id in i param if it exists */
-               if (msg->via1->i&&msg->via1->i->value.s){
+               if (msg->via1->i && msg->via1->i->value.s){
                        s=msg->via1->i->value.s;
                        len=msg->via1->i->value.len;
                        DBG("forward_reply: i=%.*s\n",len, ZSW(s));
-                       if (reverse_hex2int(s, len, &id)<0){
+                       if (reverse_hex2int(s, len, (unsigned int*)&dst.id)<0){
                                LOG(L_ERR, "ERROR: forward_reply: bad via i param \"%.*s\"\n",
                                                len, ZSW(s));
-                                       id=0;
+                                       dst.id=0;
                        }
-                       DBG("forward_reply: id= %x\n", id);
                }               
                                
        } 
 #endif
-       if (msg_send(0, proto, to, (int)id, new_buf, new_len)<0) goto error;
+       if (msg_send(&dst, new_buf, new_len)<0) goto error;
 #ifdef STATS
        STATS_TX_RESPONSE(  (msg->first_line.u.reply.statuscode/100) );
 #endif
@@ -514,11 +513,9 @@ int forward_reply(struct sip_msg* msg)
                        (unsigned short) msg->via2->port);
 
        pkg_free(new_buf);
-       pkg_free(to);
 skip:
        return 0;
 error:
        if (new_buf) pkg_free(new_buf);
-       if (to) pkg_free(to);
        return -1;
 }
index 41bf2d8..c605729 100644 (file)
--- a/forward.h
+++ b/forward.h
@@ -33,6 +33,8 @@
  *  2003-04-07 changed all ports to host byte order (andrei)
  *  2003-04-12  FORCE_RPORT_T added (andrei)
  *  2003-04-15  added tcp_disable support (andrei)
+ *  2006-04-12  reduced msg_send() parameter list: it uses now a struct 
+ *               dest_info param. (andrei)
  */
 
 
@@ -75,40 +77,41 @@ int forward_reply( struct sip_msg* msg);
 
 
 /* params:
- *  send_sock= 0 if already known (e.g. for udp in some cases), non-0 otherwise
- *  proto=TCP|UDP
- *  to = destination,
- *  id - only used on tcp, it will force sending on connection "id" if id!=0 
- *       and the connection exists, else it will send to "to" 
- *       (useful for sending replies on  the same connection as the request
- *       that generated them; use 0 if you don't want this)
+ * dst = struct dest_info containing:
+ *    send_sock = 0 if not known (e.g. for udp in some cases), non-0 otherwise
+ *    proto = TCP|UDP
+ *    to = destination (sockaddr_union)
+ *    id = only used on tcp, it will force sending on connection "id" if id!=0 
+ *         and the connection exists, else it will send to "to" 
+ *        (useful for sending replies on  the same connection as the request
+ *         that generated them; use 0 if you don't want this)
+ * buf, len = buffer
  * returns: 0 if ok, -1 on error*/
-static inline int msg_send(    struct socket_info* send_sock, int proto,
-                                                       union sockaddr_union* to, int id,
-                                                       char* buf, int len)
+static inline int msg_send(struct dest_info* dst, char* buf, int len)
 {
        
-       if (proto==PROTO_UDP){
-               if (send_sock==0) send_sock=get_send_socket(0, to, proto);
-               if (send_sock==0){
+       if (dst->proto==PROTO_UDP){
+               if (dst->send_sock==0) 
+                       dst->send_sock=get_send_socket(0, &dst->to, dst->proto);
+               if (dst->send_sock==0){
                        LOG(L_ERR, "msg_send: ERROR: no sending socket found\n");
                        goto error;
                }
-               if (udp_send(send_sock, buf, len, to)==-1){
+               if (udp_send(dst, buf, len)==-1){
                        STATS_TX_DROPS;
                        LOG(L_ERR, "msg_send: ERROR: udp_send failed\n");
                        goto error;
                }
        }
 #ifdef USE_TCP
-       else if (proto==PROTO_TCP){
+       else if (dst->proto==PROTO_TCP){
                if (tcp_disable){
                        STATS_TX_DROPS;
                        LOG(L_WARN, "msg_send: WARNING: attempt to send on tcp and tcp"
                                        " support is disabled\n");
                        goto error;
                }else{
-                       if (tcp_send(proto, buf, len, to, id)<0){
+                       if (tcp_send(dst, buf, len)<0){
                                STATS_TX_DROPS;
                                LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
                                goto error;
@@ -116,14 +119,14 @@ static inline int msg_send(       struct socket_info* send_sock, int proto,
                }
        }
 #ifdef USE_TLS
-       else if (proto==PROTO_TLS){
+       else if (dst->proto==PROTO_TLS){
                if (tls_disable){
                        STATS_TX_DROPS;
                        LOG(L_WARN, "msg_send: WARNING: attempt to send on tls and tls"
                                        " support is disabled\n");
                        goto error;
                }else{
-                       if (tcp_send(proto, buf, len, to, id)<0){
+                       if (tcp_send(dst, buf, len)<0){
                                STATS_TX_DROPS;
                                LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
                                goto error;
@@ -133,7 +136,7 @@ static inline int msg_send( struct socket_info* send_sock, int proto,
 #endif /* USE_TLS */
 #endif /* USE_TCP */
        else{
-                       LOG(L_CRIT, "BUG: msg_send: unknown proto %d\n", proto);
+                       LOG(L_CRIT, "BUG: msg_send: unknown proto %d\n", dst->proto);
                        goto error;
        }
        return 0;
index 0b50268..279eecf 100644 (file)
--- a/ip_addr.h
+++ b/ip_addr.h
@@ -112,7 +112,7 @@ struct receive_info{
 
 struct dest_info{
        int proto;
-       int proto_reserved1; /* tcp stores the connection id here */ 
+       int id; /* tcp stores the connection id here */ 
        union sockaddr_union to;
        struct socket_info* send_sock;
 };
index 10195e2..88e1e1a 100644 (file)
@@ -82,8 +82,7 @@ int send_pr_buffer(   struct retr_buf *rb, void *buf, int len
                                        )
 {
        if (buf && len && rb )
-               return msg_send( rb->dst.send_sock, rb->dst.proto, &rb->dst.to,
-                                        rb->dst.proto_reserved1, buf, len);
+               return msg_send( &rb->dst, buf, len);
        else {
 #ifdef EXTRA_DEBUG
                LOG(L_CRIT, "ERROR: send_pr_buffer: sending an empty buffer"
index eb93683..61075a8 100644 (file)
@@ -293,7 +293,7 @@ int add_uac( struct cell *t, struct sip_msg *request, str *uri, str* next_hop,
        t->uac[branch].request.dst.to=to;
        t->uac[branch].request.dst.send_sock=send_sock;
        t->uac[branch].request.dst.proto=proto;
-       t->uac[branch].request.dst.proto_reserved1=0;
+       t->uac[branch].request.dst.id=0;
        t->uac[branch].request.buffer=shbuf;
        t->uac[branch].request.buffer_len=len;
        t->uac[branch].uri.s=t->uac[branch].request.buffer+
@@ -571,9 +571,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
        success_branch=0;
        for (i=first_branch; i<t->nr_of_outgoings; i++) {
                if (added_branches & (1<<i)) {
-                       if (run_onsend(p_msg,   t->uac[i].request.dst.send_sock,
-                                                                       t->uac[i].request.dst.proto,
-                                                                       &t->uac[i].request.dst.to,
+                       if (run_onsend(p_msg,   &t->uac[i].request.dst,
                                                                        t->uac[i].request.buffer,
                                                                        t->uac[i].request.buffer_len)==0)
                                continue; /* if onsend drop, try next branch */
index 4daa585..8fe2f31 100644 (file)
@@ -1002,7 +1002,7 @@ int init_rb( struct retr_buf *rb, struct sip_msg *msg)
                proto=via->proto;
        }
        rb->dst.proto=proto;
-       rb->dst.proto_reserved1=msg->rcv.proto_reserved1;
+       rb->dst.id=msg->rcv.proto_reserved1;
        /* turn off mhomed for generating replies -- they are ideally sent to where
           request came from to make life with NATs and other beasts easier
        */
index e783be0..f2b9263 100644 (file)
@@ -316,21 +316,20 @@ static char *build_local_ack(struct sip_msg* rpl, struct cell *trans, int branch
 static int send_local_ack(struct sip_msg* msg, str* next_hop,
                                                        char* ack, int ack_len)
 {
-       struct socket_info* send_sock;
-       union sockaddr_union to_su;
+       struct dest_info dst;
 
        if (!next_hop) {
                LOG(L_ERR, "send_local_ack: Invalid parameter value\n");
                return -1;
        }
 
-       send_sock = uri2sock(msg, next_hop, &to_su, PROTO_NONE);
-       if (!send_sock) {
+       dst.send_sock = uri2sock(msg, next_hop, &dst.to, PROTO_NONE);
+       if (!dst.send_sock) {
                LOG(L_ERR, "send_local_ack: no socket found\n");
                return -1;
        }
-
-       return msg_send(send_sock, send_sock->proto, &to_su, 0, ack, ack_len);
+       dst.id=0;
+       return msg_send(&dst, ack, ack_len);
 }
 
 
index 6a362ad..00c9a2a 100644 (file)
@@ -235,7 +235,7 @@ int t_uac(str* method, str* headers, str* body, dlg_t* dialog,
        request->dst.to = to_su;
        request->dst.send_sock = send_sock;
        request->dst.proto = send_sock->proto;
-       request->dst.proto_reserved1 = 0;
+       request->dst.id = 0;
 
        hi=dlg2hash(dialog);
        LOCK_HASH(hi);
index cdc6b1d..2527a34 100644 (file)
--- a/onsend.h
+++ b/onsend.h
@@ -54,17 +54,16 @@ extern struct onsend_info* p_onsend;
 /*
  * returns: 0 drop the message, >= ok, <0 error (but forward the message)
  * WARNING: buf must be 0 terminated (to allow regex matches on it) */
-static inline int run_onsend(struct sip_msg* orig_msg,
-                                                       struct socket_info* send_sock, int proto,
-                                                       union sockaddr_union* to, char* buf, int len)
+static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
+                                                               char* buf, int len)
 {
        struct onsend_info onsnd_info;
        int ret;
        
        ret=1;
        if (onsend_rt.rlist[DEFAULT_RT]){
-               onsnd_info.to=to;
-               onsnd_info.send_sock=send_sock;
+               onsnd_info.to=&dst->to;
+               onsnd_info.send_sock=dst->send_sock;
                onsnd_info.buf=buf;
                onsnd_info.len=len;
                p_onsend=&onsnd_info;
index 0e435a3..93f2121 100644 (file)
@@ -68,6 +68,7 @@
  *              EAGAIN; lots of bug fixes (andrei)
  *  2006-02-06  better tcp_max_connections checks, tcp_connections_no moved to
  *              shm (andrei)
+ *  2006-04-12  tcp_send() changed to use struct dest_info (andrei)
  */
 
 
@@ -730,10 +731,10 @@ void tcpconn_put(struct tcp_connection* c)
 
 
 /* finds a tcpconn & sends on it
+ * uses the dst members to, proto (TCP|TLS) and id
  * returns: number of bytes written (>=0) on success
  *          <0 on error */
-int tcp_send(int type, char* buf, unsigned len, union sockaddr_union* to,
-                               int id)
+int tcp_send(struct dest_info* dst, char* buf, unsigned len)
 {
        struct tcp_connection *c;
        struct tcp_connection *tmp;
@@ -743,27 +744,26 @@ int tcp_send(int type, char* buf, unsigned len, union sockaddr_union* to,
        long response[2];
        int n;
        
-       port=0;
-       if (to){
-               su2ip_addr(&ip, to);
-               port=su_getport(to);
-               c=tcpconn_get(id, &ip, port, tcp_con_lifetime); 
-       }else if (id){
-               c=tcpconn_get(id, 0, 0, tcp_con_lifetime);
+       port=su_getport(&dst->to);
+       if (port){
+               su2ip_addr(&ip, &dst->to);
+               c=tcpconn_get(dst->id, &ip, port, tcp_con_lifetime); 
+       }else if (dst->id){
+               c=tcpconn_get(dst->id, 0, 0, tcp_con_lifetime);
        }else{
                LOG(L_CRIT, "BUG: tcp_send called with null id & to\n");
                return -1;
        }
        
-       if (id){
+       if (dst->id){
                if (c==0) {
-                       if (to){
+                       if (port){
                                /* try again w/o id */
                                c=tcpconn_get(0, &ip, port, tcp_con_lifetime);
                                goto no_id;
                        }else{
                                LOG(L_ERR, "ERROR: tcp_send: id %d not found, dropping\n",
-                                               id);
+                                               dst->id);
                                return -1;
                        }
                }else goto get_fd;
@@ -772,7 +772,7 @@ no_id:
                if (c==0){
                        DBG("tcp_send: no open tcp connection found, opening new one\n");
                        /* create tcp connection */
-                       if ((c=tcpconn_connect(to, type))==0){
+                       if ((c=tcpconn_connect(&dst->to, dst->proto))==0){
                                LOG(L_ERR, "ERROR: tcp_send: connect failed\n");
                                return -1;
                        }
index 2d5ca3c..e12181d 100644 (file)
@@ -29,6 +29,7 @@
 #ifndef tcp_server_h
 #define tcp_server_h
 
+#include "ip_addr.h"
 
 
 /* "public" functions*/
@@ -36,8 +37,7 @@
 struct tcp_connection* tcpconn_get(int id, struct ip_addr* ip, int port, 
                                                                        int timeout);
 void tcpconn_put(struct tcp_connection* c);
-int tcp_send(int type, char* buf, unsigned len, union sockaddr_union* to,
-                       int id);
+int tcp_send(struct dest_info* dst, char* buf, unsigned len);
 
 int tcpconn_add_alias(int id, int port, int proto);
 
index ef7dcbe..6cf5aef 100644 (file)
@@ -36,6 +36,7 @@
  *              cleanups (andrei)
  *  2005-03-10  multicast options are now set for all the udp sockets (andrei)
  *  2005-06-26  failure to set mcast options is not an error anymore (andrei)
+ *  2006-04-12  udp_send() switched to struct dest_info (andrei)
  */
 
 
@@ -488,13 +489,15 @@ error:
 
 
 
-/* which socket to use? main socket or new one? */
-int udp_send(struct socket_info *source, char *buf, unsigned len,
-                                                                               union sockaddr_union*  to)
+/* send buf:len over udp to dst (uses only the to and send_sock dst members)
+ * returns the numbers of bytes sent on success (>=0) and -1 on error
+ */
+int udp_send(struct dest_info* dst, char *buf, unsigned len)
 {
 
        int n;
        int tolen;
+       struct ip_addr ip; /* used only on error, for debugging */
 
 #ifdef DBG_MSG_QA
        /* aborts on error, does nothing otherwise */
@@ -504,15 +507,16 @@ int udp_send(struct socket_info *source, char *buf, unsigned len,
        }
 #endif
 
-       tolen=sockaddru_len(*to);
+       tolen=sockaddru_len(dst->to);
 again:
-       n=sendto(source->socket, buf, len, 0, &to->s, tolen);
+       n=sendto(dst->send_sock->socket, buf, len, 0, &dst->to.s, tolen);
 #ifdef XL_DEBUG
        LOG(L_INFO, "INFO: send status: %d\n", n);
 #endif
        if (n==-1){
-               LOG(L_ERR, "ERROR: udp_send: sendto(sock,%p,%d,0,%p,%d): %s(%d)\n",
-                               buf,len,to,tolen,
+               su2ip_addr(&ip, &dst->to);
+               LOG(L_ERR, "ERROR: udp_send: sendto(sock,%p,%d,0,%s:%d,%d): %s(%d)\n",
+                               buf,len, ip_addr2a(&ip), su_getport(&dst->to), tolen,
                                strerror(errno),errno);
                if (errno==EINTR) goto again;
                if (errno==EINVAL) {
index a47cf6d..8a35498 100644 (file)
@@ -38,8 +38,7 @@
 
 
 int udp_init(struct socket_info* si);
-int udp_send(struct socket_info* source,char *buf, unsigned len,
-                               union sockaddr_union*  to);
+int udp_send(struct dest_info* dst, char *buf, unsigned len);
 int udp_rcv_loop();
 
 
index a593d2b..0a98fd1 100644 (file)
@@ -103,7 +103,7 @@ cmd:\n\
 arg:\n\
      string or number; to force a number to be interpreted as string \n\
      prefix it by \"s:\", e.g. s:1\n\
-Example:\n\
+Examples:\n\
         " NAME " -s unixs:/tmp/ser_unix system.listMethods\n\
         " NAME " -f \"pid: %v  desc: %v\\n\" -s udp:localhost:2047 core.ps \n\
         " NAME " ps  # uses default ctl socket \n\