comparison tcp-accept.c @ 641:2b1bb792cd4d dropbear-tfm

- Update tfm changes to current default tip
author Matt Johnston <matt@ucc.asn.au>
date Mon, 21 Nov 2011 19:52:28 +0800
parents abf040aedd44
children dfdb9d9189ff
comparison
equal deleted inserted replaced
640:76097ec1a29a 641:2b1bb792cd4d
59 } 59 }
60 60
61 if (getnameinfo((struct sockaddr*)&addr, len, ipstring, sizeof(ipstring), 61 if (getnameinfo((struct sockaddr*)&addr, len, ipstring, sizeof(ipstring),
62 portstring, sizeof(portstring), 62 portstring, sizeof(portstring),
63 NI_NUMERICHOST | NI_NUMERICSERV) != 0) { 63 NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
64 m_close(fd);
64 return; 65 return;
65 } 66 }
66 67
67 if (send_msg_channel_open_init(fd, tcpinfo->chantype) == DROPBEAR_SUCCESS) { 68 if (send_msg_channel_open_init(fd, tcpinfo->chantype) == DROPBEAR_SUCCESS) {
68 unsigned char* addr = NULL; 69 unsigned char* addr = NULL;
79 /* address that was connected, port that was connected */ 80 /* address that was connected, port that was connected */
80 addr = tcpinfo->listenaddr; 81 addr = tcpinfo->listenaddr;
81 port = tcpinfo->listenport; 82 port = tcpinfo->listenport;
82 } 83 }
83 84
85 if (addr == NULL) {
86 addr = "localhost";
87 }
84 buf_putstring(ses.writepayload, addr, strlen(addr)); 88 buf_putstring(ses.writepayload, addr, strlen(addr));
85 buf_putint(ses.writepayload, port); 89 buf_putint(ses.writepayload, port);
86 90
87 /* originator ip */ 91 /* originator ip */
88 buf_putstring(ses.writepayload, ipstring, strlen(ipstring)); 92 buf_putstring(ses.writepayload, ipstring, strlen(ipstring));
102 char portstring[NI_MAXSERV]; 106 char portstring[NI_MAXSERV];
103 int socks[DROPBEAR_MAX_SOCKS]; 107 int socks[DROPBEAR_MAX_SOCKS];
104 struct Listener *listener = NULL; 108 struct Listener *listener = NULL;
105 int nsocks; 109 int nsocks;
106 char* errstring = NULL; 110 char* errstring = NULL;
107 /* listen_spec = NULL indicates localhost */
108 const char* listen_spec = NULL;
109 111
110 TRACE(("enter listen_tcpfwd")) 112 TRACE(("enter listen_tcpfwd"))
111 113
112 /* first we try to bind, so don't need to do so much cleanup on failure */ 114 /* first we try to bind, so don't need to do so much cleanup on failure */
113 snprintf(portstring, sizeof(portstring), "%d", tcpinfo->listenport); 115 snprintf(portstring, sizeof(portstring), "%d", tcpinfo->listenport);
114 116
115 /* a listenaddr of "" will indicate all interfaces */ 117 nsocks = dropbear_listen(tcpinfo->listenaddr, portstring, socks,
116 if (opts.listen_fwd_all
117 && (strcmp(tcpinfo->listenaddr, "localhost") != 0) ) {
118 listen_spec = tcpinfo->listenaddr;
119 }
120
121 nsocks = dropbear_listen(listen_spec, portstring, socks,
122 DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd); 118 DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd);
123 if (nsocks < 0) { 119 if (nsocks < 0) {
124 dropbear_log(LOG_INFO, "TCP forward failed: %s", errstring); 120 dropbear_log(LOG_INFO, "TCP forward failed: %s", errstring);
125 m_free(errstring); 121 m_free(errstring);
126 TRACE(("leave listen_tcpfwd: dropbear_listen failed")) 122 TRACE(("leave listen_tcpfwd: dropbear_listen failed"))