udp_server.c
e60a9728
 /*
53c7e0f1
  * Copyright (C) 2001-2003 FhG Fokus
7dd0b342
  *
6a0f4382
  * This file is part of Kamailio, a free SIP server.
7dd0b342
  *
6a0f4382
  * Kamailio is free software; you can redistribute it and/or modify
7dd0b342
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
6a0f4382
  * Kamailio is distributed in the hope that it will be useful,
7dd0b342
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
049f64c2
  *
e60a9728
  */
 
7dd0b342
 
6a0f4382
 /** Kamailio core :: udp send and loop-receive functions.
22e7e32e
  * @file udp_server.c
  * @ingroup core
  * Module: @ref core
1d0661db
  */
 
3e429f5c
 #include <stdlib.h>
 #include <string.h>
e60a9728
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
1f2c924e
 #include <netinet/in_systm.h>
39546e5f
 #include <netinet/ip.h>
e60a9728
 #include <errno.h>
68a3fc65
 #include <arpa/inet.h>
853c176f
 #ifdef __linux__
 	#include <linux/types.h>
 	#include <linux/errqueue.h>
 #endif
e60a9728
 
 
 #include "udp_server.h"
22e7e32e
 #include "compiler_opt.h"
4e2fdd79
 #include "globals.h"
e60a9728
 #include "config.h"
 #include "dprint.h"
3e429f5c
 #include "receive.h"
dda9dab1
 #include "mem/mem.h"
4e2fdd79
 #include "ip_addr.h"
9188021a
 #include "cfg/cfg_struct.h"
178b21cc
 #include "events.h"
c573aa70
 #include "stun.h"
22e7e32e
 #ifdef USE_RAW_SOCKS
 #include "raw_sock.h"
 #endif /* USE_RAW_SOCKS */
 
e60a9728
 
c0656aad
 #ifdef DBG_MSG_QA
 /* message quality assurance -- frequently, bugs in ser have
    been indicated by zero characters or long whitespaces
    in generated messages; this debugging option aborts if
    any such message is sighted
 */
 static int dbg_msg_qa(char *buf, int len)
 {
 #define _DBG_WS_LEN 3
 #define _DBG_WS "   "
 
 	char *scan;
 	int my_len;
 	int space_cnt;
 	enum { QA_ANY, QA_SPACE, QA_EOL1 } state;
 
 
53c7e0f1
 	/* is there a zero character in there ? */	
c0656aad
 	if (memchr(buf, 0, len)) {
7540a139
 		LM_CRIT("message with 0 in it\n");
c0656aad
 		return 0;
 	}
 
 	my_len=len;
 	scan=buf;
 	state=QA_ANY;
 	space_cnt=0;
 
 	while(my_len) {
 		switch(*scan) {
 			case ' ':	if (state==QA_SPACE) {
 							space_cnt++;
 							if (space_cnt==4) {
e44f53c0
 								LM_CRIT("too many spaces\n");
c0656aad
 								return 0;
 							}
 						} else space_cnt=0;
 						state=QA_SPACE; 
 						break;
 
 			case '\r':	/* ignore */
 						space_cnt=0;
 						break;
 
 			case '\n': /* don't proceed to body on EoH */
 						if (state==QA_EOL1) goto qa_passed;
 						space_cnt=0;
 						state=QA_EOL1;
 						break;
 
 			default:	space_cnt=0;
 						state=QA_ANY;
 						break;
 		}
 		scan++;
 		my_len--;
 	}
 
 
 qa_passed:
 	return 1;
 }
 
 #endif
 
e60a9728
 
8eddd6f6
 int probe_max_receive_buffer( int udp_sock )
e60a9728
 {
e22bbdb8
 	int optval;
9c61e9f9
 	int ioptval;
 	unsigned int ioptvallen;
 	int foptval;
 	unsigned int foptvallen;
 	int voptval;
 	unsigned int voptvallen;
d24a2059
 	int phase=0;
 
 	/* jku: try to increase buffer size as much as we can */
 	ioptvallen=sizeof(ioptval);
 	if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &ioptval,
 		    &ioptvallen) == -1 )
 	{
7540a139
 		LM_ERR("getsockopt: %s\n", strerror(errno));
8eddd6f6
 		return -1;
d24a2059
 	}
 	if ( ioptval==0 ) 
 	{
7540a139
 		LM_DBG("SO_RCVBUF initially set to 0; resetting to %d\n",
d24a2059
 			BUFFER_INCREMENT );
 		ioptval=BUFFER_INCREMENT;
7540a139
 	} else LM_INFO("SO_RCVBUF is initially %d\n", ioptval );
53af8794
 	for (optval=ioptval; ;  ) {
d24a2059
 		/* increase size; double in initial phase, add linearly later */
 		if (phase==0) optval <<= 1; else optval+=BUFFER_INCREMENT;
e22bbdb8
 		if (optval > maxbuffer){
 			if (phase==1) break; 
e0a6ffa6
 			else { phase=1; optval >>=1; continue; }
 		}
7540a139
 		LM_DBG("trying SO_RCVBUF: %d\n", optval );
e22bbdb8
 		if (setsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF,
 			(void*)&optval, sizeof(optval)) ==-1){
af6fb476
 			/* Solaris returns -1 if asked size too big; Linux ignores */
7540a139
 			LM_DBG("SOL_SOCKET failed for %d, phase %d: %s\n", optval, phase, strerror(errno));
d24a2059
 			/* if setting buffer size failed and still in the aggressive
53c7e0f1
 			   phase, try less aggressively; otherwise give up 
d24a2059
 			*/
 			if (phase==0) { phase=1; optval >>=1 ; continue; } 
 			else break;
e22bbdb8
 		} 
d24a2059
 		/* verify if change has taken effect */
af6fb476
 		/* Linux note -- otherwise I would never know that; funny thing: Linux
 		   doubles size for which we asked in setsockopt
 		*/
d24a2059
 		voptvallen=sizeof(voptval);
 		if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &voptval,
 		    &voptvallen) == -1 )
 		{
7540a139
 			LM_ERR("getsockopt: %s\n", strerror(errno));
8eddd6f6
 			return -1;
d24a2059
 		} else {
7540a139
 			LM_DBG("setting SO_RCVBUF; set=%d,verify=%d\n", 
d24a2059
 				optval, voptval);
 			if (voptval<optval) {
7540a139
 				LM_DBG("setting SO_RCVBUF has no effect\n");
d24a2059
 				/* if setting buffer size failed and still in the aggressive
53c7e0f1
 				phase, try less aggressively; otherwise give up 
d24a2059
 				*/
e22bbdb8
 				if (phase==0) { phase=1; optval >>=1 ; continue; } 
 				else break;
8eddd6f6
 			} 
d24a2059
 		}
e22bbdb8
 	
d24a2059
 	} /* for ... */
 	foptvallen=sizeof(foptval);
 	if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &foptval,
 		    &foptvallen) == -1 )
 	{
7540a139
 		LM_ERR("getsockopt: %s\n", strerror(errno));
8eddd6f6
 		return -1;
d24a2059
 	}
7540a139
 	LM_INFO("SO_RCVBUF is finally %d\n", foptval );
d24a2059
 
8eddd6f6
 	return 0;
d24a2059
 
 	/* EoJKU */
8eddd6f6
 }
 
2ba73117
 
 #ifdef USE_MCAST
 
 /*
  * Setup multicast receiver
  */
 static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
 {
 	struct ip_mreq mreq;
 	struct ipv6_mreq mreq6;
 	
 	if (addr->s.sa_family==AF_INET){
 		memcpy(&mreq.imr_multiaddr, &addr->sin.sin_addr, 
 		       sizeof(struct in_addr));
 		mreq.imr_interface.s_addr = htonl(INADDR_ANY);
 		
 		if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,&mreq,
 			       sizeof(mreq))==-1){
7540a139
 			LM_ERR("setsockopt: %s\n", strerror(errno));
2ba73117
 			return -1;
 		}
 		
 	} else if (addr->s.sa_family==AF_INET6){
 		memcpy(&mreq6.ipv6mr_multiaddr, &addr->sin6.sin6_addr, 
 		       sizeof(struct in6_addr));
 		mreq6.ipv6mr_interface = 0;
d3d1486e
 #ifdef __OS_linux
2ba73117
 		if (setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6,
d3d1486e
 #else
 		if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6,
 #endif
2ba73117
 			       sizeof(mreq6))==-1){
7540a139
 			LM_ERR("setsockopt:%s\n", strerror(errno));
2ba73117
 			return -1;
 		}
 		
 	} else {
7540a139
 		LM_ERR("setup_mcast_rcvr: Unsupported protocol family\n");
2ba73117
 		return -1;
 	}
 	return 0;
 }
 
 #endif /* USE_MCAST */
 
 
36ef0329
 int udp_init(struct socket_info* sock_info)
8eddd6f6
 {
4e2fdd79
 	union sockaddr_union* addr;
e22bbdb8
 	int optval;
90c6c74a
 #ifdef USE_MCAST
 	unsigned char m_ttl, m_loop;
 #endif
741db913
 	addr=&sock_info->su;
 /*
e3dccdc9
 	addr=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
8eddd6f6
 	if (addr==0){
7540a139
 		LM_ERR("out of memory\n");
8eddd6f6
 		goto error;
 	}
741db913
 */
f2f969dd
 	sock_info->proto=PROTO_UDP;
6eacb2bc
 	if (init_su(addr, &sock_info->address, sock_info->port_no)<0){
7540a139
 		LM_ERR("could not init sockaddr_union\n");
4e2fdd79
 		goto error;
 	}
1d597ac3
 	
36ef0329
 	sock_info->socket = socket(AF2PF(addr->s.sa_family), SOCK_DGRAM, 0);
 	if (sock_info->socket==-1){
7540a139
 		LM_ERR("socket: %s\n", strerror(errno));
8eddd6f6
 		goto error;
 	}
 	/* set sock opts? */
 	optval=1;
36ef0329
 	if (setsockopt(sock_info->socket, SOL_SOCKET, SO_REUSEADDR ,
853c176f
 					(void*)&optval, sizeof(optval)) ==-1){
7540a139
 		LM_ERR("setsockopt: %s\n", strerror(errno));
853c176f
 		goto error;
 	}
39546e5f
 	/* tos */
fe09f315
 	optval = tos;
084be456
 	if (addr->s.sa_family==AF_INET){
 		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, 
 				sizeof(optval)) ==-1){
7540a139
 			LM_WARN("setsockopt tos: %s\n", strerror(errno));
084be456
 			/* continue since this is not critical */
 		}
 	} else if (addr->s.sa_family==AF_INET6){
 		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_TCLASS,
 					(void*)&optval, sizeof(optval)) ==-1) {
7540a139
 			LM_WARN("setsockopt v6 tos: %s\n", strerror(errno));
084be456
 			/* continue since this is not critical */
 		}
39546e5f
 	}
084be456
 
f3a26797
 #if defined (__OS_linux) && defined(UDP_ERRORS)
853c176f
 	optval=1;
 	/* enable error receiving on unconnected sockets */
 	if(setsockopt(sock_info->socket, SOL_IP, IP_RECVERR,
 					(void*)&optval, sizeof(optval)) ==-1){
7540a139
 		LM_ERR("setsockopt: %s\n", strerror(errno));
f3a26797
 		goto error;
 	}
 #endif
 #if defined (__OS_linux)
 	/* if pmtu_discovery=1 then set DF bit and do Path MTU discovery
 	 * disabled by default */
 	optval= (pmtu_discovery) ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
 	if(setsockopt(sock_info->socket, IPPROTO_IP, IP_MTU_DISCOVER,
 			(void*)&optval, sizeof(optval)) ==-1){
7540a139
 		LM_ERR("setsockopt: %s\n", strerror(errno));
8eddd6f6
 		goto error;
 	}
853c176f
 #endif
 
2ba73117
 #ifdef USE_MCAST
 	if ((sock_info->flags & SI_IS_MCAST) 
 	    && (setup_mcast_rcvr(sock_info->socket, addr)<0)){
 			goto error;
 	}
e6b442bd
 	/* set the multicast options */
 	if (addr->s.sa_family==AF_INET){
90c6c74a
 		m_loop=mcast_loopback;
e6b442bd
 		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_LOOP, 
90c6c74a
 						&m_loop, sizeof(m_loop))==-1){
7540a139
 			LM_WARN("setsockopt(IP_MULTICAST_LOOP): %s\n", strerror(errno));
741a9937
 			/* it's only a warning because we might get this error if the
 			  network interface doesn't support multicasting -- andrei */
e6b442bd
 		}
 		if (mcast_ttl>=0){
90c6c74a
 			m_ttl=mcast_ttl;
e6b442bd
 			if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_TTL,
90c6c74a
 						&m_ttl, sizeof(m_ttl))==-1){
7540a139
 				LM_WARN("setsockopt (IP_MULTICAST_TTL): %s\n", strerror(errno));
e6b442bd
 			}
 		}
 	} else if (addr->s.sa_family==AF_INET6){
 		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
 						&mcast_loopback, sizeof(mcast_loopback))==-1){
7540a139
 			LM_WARN("setsockopt (IPV6_MULTICAST_LOOP): %s\n", strerror(errno));
e6b442bd
 		}
 		if (mcast_ttl>=0){
 			if (setsockopt(sock_info->socket, IPPROTO_IP, IPV6_MULTICAST_HOPS,
 							&mcast_ttl, sizeof(mcast_ttl))==-1){
7540a139
 				LM_WARN("setssckopt (IPV6_MULTICAST_HOPS): %s\n", strerror(errno));
e6b442bd
 			}
 		}
 	} else {
7540a139
 		LM_ERR("Unsupported protocol family %d\n", addr->s.sa_family);
e6b442bd
 		goto error;
 	}
2ba73117
 #endif /* USE_MCAST */
8eddd6f6
 
36ef0329
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;
53531528
 	
741db913
 	if (bind(sock_info->socket,  &addr->s, sockaddru_len(*addr))==-1){
7540a139
 		LM_ERR("bind(%x, %p, %d) on %s: %s\n",
36ef0329
 				sock_info->socket, &addr->s, 
4d080f49
 				(unsigned)sockaddru_len(*addr),
36ef0329
 				sock_info->address_str.s,
 				strerror(errno));
 		if (addr->s.sa_family==AF_INET6)
7540a139
 			LM_ERR("might be caused by using a link local address, try site local or global\n");
e60a9728
 		goto error;
 	}
 
e3dccdc9
 /*	pkg_free(addr);*/
e60a9728
 	return 0;
 
 error:
e3dccdc9
 /*	if (addr) pkg_free(addr);*/
e60a9728
 	return -1;
 }
 
 
 
 int udp_rcv_loop()
 {
3e429f5c
 	unsigned len;
dda9dab1
 #ifdef DYN_BUF
22d4aa5d
 	char* buf;
dda9dab1
 #else
b2dec9c6
 	static char buf [BUF_SIZE+1];
dda9dab1
 #endif
5260ef32
 	char *tmp;
4e2fdd79
 	union sockaddr_union* from;
9c61e9f9
 	unsigned int fromlen;
f2f969dd
 	struct receive_info ri;
e60a9728
 
dda9dab1
 
e3dccdc9
 	from=(union sockaddr_union*) pkg_malloc(sizeof(union sockaddr_union));
e60a9728
 	if (from==0){
7540a139
 		LM_ERR("out of memory\n");
e60a9728
 		goto error;
 	}
741db913
 	memset(from, 0 , sizeof(union sockaddr_union));
f2f969dd
 	ri.bind_address=bind_address; /* this will not change, we do it only once*/
 	ri.dst_port=bind_address->port_no;
 	ri.dst_ip=bind_address->address;
 	ri.proto=PROTO_UDP;
 	ri.proto_reserved1=ri.proto_reserved2=0;
9188021a
 
 	/* initialize the config framework */
 	if (cfg_child_init()) goto error;
 
e60a9728
 	for(;;){
dda9dab1
 #ifdef DYN_BUF
6bd84753
 		buf=pkg_malloc(BUF_SIZE+1);
 		if (buf==0){
7540a139
 			LM_ERR("could not allocate receive buffer\n");
6bd84753
 			goto error;
 		}
dda9dab1
 #endif
741db913
 		fromlen=sockaddru_len(bind_address->su);
36ef0329
 		len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s,
 											&fromlen);
e60a9728
 		if (len==-1){
5260ef32
 			if (errno==EAGAIN){
e44f53c0
 				LM_DBG("packet with bad checksum received\n");
5260ef32
 				continue;
 			}
7540a139
 			LM_ERR("recvfrom:[%d] %s\n", errno, strerror(errno));
5260ef32
 			if ((errno==EINTR)||(errno==EWOULDBLOCK)|| (errno==ECONNREFUSED))
6984881e
 				continue; /* goto skip;*/
e60a9728
 			else goto error;
 		}
8fc80c33
 		/* we must 0-term the messages, receive_msg expects it */
610cb10e
 		buf[len]=0; /* no need to save the previous char */
577f13b5
 
5260ef32
 		ri.src_su=*from;
 		su2ip_addr(&ri.src_ip, from);
 		ri.src_port=su_getport(from);
 
178b21cc
 		if(unlikely(sr_event_enabled(SREV_NET_DGRAM_IN)))
 		{
 			void *sredp[3];
 			sredp[0] = (void*)buf;
 			sredp[1] = (void*)(&len);
 			sredp[2] = (void*)(&ri);
 			if(sr_event_exec(SREV_NET_DGRAM_IN, (void*)sredp)<0) {
 				/* data handled by callback - continue to next packet */
 				continue;
 			}
 		}
577f13b5
 #ifndef NO_ZERO_CHECKS
c573aa70
 		if (!unlikely(sr_event_enabled(SREV_STUN_IN)) || (unsigned char)*buf != 0x00) {
 			if (len<MIN_UDP_PACKET) {
 				tmp=ip_addr2a(&ri.src_ip);
e44f53c0
 				LM_DBG("probing packet received from %s %d\n", tmp, htons(ri.src_port));
c573aa70
 				continue;
 			}
577f13b5
 		}
35ab13d8
 /* historically, zero-terminated packets indicated a bug in clients
  * that calculated wrongly packet length and included string-terminating
  * zero; today clients exist with legitimate binary payloads and we
  * shall not check for zero-terminated payloads
  */
 #ifdef TRASH_ZEROTERMINATED_PACKETS
577f13b5
 		if (buf[len-1]==0) {
5260ef32
 			tmp=ip_addr2a(&ri.src_ip);
7540a139
 			LM_WARN("upstream bug - 0-terminated packet from %s %d\n",
5260ef32
 					tmp, htons(ri.src_port));
577f13b5
 			len--;
 		}
 #endif
96227c65
 #endif
f354fb0e
 #ifdef DBG_MSG_QA
 		if (!dbg_msg_qa(buf, len)) {
7540a139
 			LM_WARN("an incoming message didn't pass test,"
e3fc93f4
 						"  drop it: %.*s\n", len, buf );
f354fb0e
 			continue;
 		}
 #endif
5260ef32
 		if (ri.src_port==0){
 			tmp=ip_addr2a(&ri.src_ip);
7540a139
 			LM_INFO("dropping 0 port packet from %s\n", tmp);
5260ef32
 			continue;
 		}
f2f969dd
 		
38c052a7
 		/* update the local config */
 		cfg_update();
c573aa70
 		if (unlikely(sr_event_enabled(SREV_STUN_IN)) && (unsigned char)*buf == 0x00) {
 			/* stun_process_msg releases buf memory if necessary */
 			if ((stun_process_msg(buf, len, &ri)) != 0) {
 				continue; /* some error occurred */
 			}
 		} else {
 			/* receive_msg must free buf too!*/
 			receive_msg(buf, len, &ri);
 		}
1b1b19d8
 		
b2dec9c6
 	/* skip: do other stuff */
e60a9728
 		
 	}
51eadd0c
 	/*
e3dccdc9
 	if (from) pkg_free(from);
e60a9728
 	return 0;
51eadd0c
 	*/
e60a9728
 	
 error:
e3dccdc9
 	if (from) pkg_free(from);
e60a9728
 	return -1;
 }
 
 
 
92044adc
 
e6a2b12e
 /* 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)
577f13b5
 {
 
 	int n;
741db913
 	int tolen;
e6a2b12e
 	struct ip_addr ip; /* used only on error, for debugging */
22e7e32e
 #ifdef USE_RAW_SOCKS
 	int mtu;
 #endif /* USE_RAW_SOCKS */
577f13b5
 
 #ifdef DBG_MSG_QA
 	/* aborts on error, does nothing otherwise */
f354fb0e
 	if (!dbg_msg_qa( buf, len )) {
7540a139
 		LM_ERR("dbg_msg_qa failed\n");
f354fb0e
 		abort();
 	}
577f13b5
 #endif
22e7e32e
 #ifdef USE_RAW_SOCKS
 	if (likely( ! (raw_udp4_send_sock >= 0 &&
 					cfg_get(core, core_cfg, udp4_raw) &&
 					dst->send_sock->address.af == AF_INET) )) {
 #endif /* USE_RAW_SOCKS */
 		/* normal send over udp socket */
 		tolen=sockaddru_len(dst->to);
e60a9728
 again:
22e7e32e
 		n=sendto(dst->send_sock->socket, buf, len, 0, &dst->to.s, tolen);
18abd66c
 #ifdef XL_DEBUG
7540a139
 		LM_INFO("send status: %d\n", n);
18abd66c
 #endif
22e7e32e
 		if (unlikely(n==-1)){
 			su2ip_addr(&ip, &dst->to);
7540a139
 			LM_ERR("sendto(sock,%p,%u,0,%s:%d,%d): %s(%d)\n",
 					buf,len, ip_addr2a(&ip),
22e7e32e
 					su_getport(&dst->to), tolen, strerror(errno), errno);
 			if (errno==EINTR) goto again;
 			if (errno==EINVAL) {
7540a139
 				LM_CRIT("invalid sendtoparameters\n"
22e7e32e
 				"one possible reason is the server is bound to localhost and\n"
 				"attempts to send to the net\n");
 			}
 		}
 #ifdef USE_RAW_SOCKS
 	} else {
 		/* send over a raw socket */
 		mtu = cfg_get(core, core_cfg, udp4_raw_mtu);
 raw_again:
 		n=raw_iphdr_udp4_send(raw_udp4_send_sock, buf, len,
 								&dst->send_sock->su,
 								&dst->to,
 								mtu);
 		if (unlikely(n==-1)){
 			su2ip_addr(&ip, &dst->to);
7540a139
 			LM_ERR("raw_iphdr_udp4_send(%d,%p,%u,...,%s:%d,%d): %s(%d)\n",
 					raw_udp4_send_sock, buf,len, ip_addr2a(&ip),
22e7e32e
 					su_getport(&dst->to), mtu, strerror(errno), errno);
 			if (errno==EINTR) goto raw_again;
d3b31abd
 		}
e60a9728
 	}
22e7e32e
 #endif /* USE_RAW_SOCKS */
e60a9728
 	return n;
 }