int tcp_conn_alloc(struct tcp_conn **tcp, const struct sa *peer, tcp_estab_h *eh, tcp_recv_h *rh, tcp_close_h *ch, void *arg) { struct tcp_conn *tc; int err; if (!tcp || !sa_isset(peer, SA_ALL)) return EINVAL; tc = conn_alloc(NULL, eh, rh, ch, arg); if (!tc) return ENOMEM; TInetAddr ia(sa_in(peer), sa_port(peer)); err = tc->ctc->Open(ia); if (err) goto out; *tcp = tc; out: if (err) { DEBUG_WARNING("conn_alloc: %J (%s)\n", peer, strerror(err)); mem_deref(tc); } return err; }
int tcp_conn_bind(struct tcp_conn *tc, const struct sa *local) { if (!tc || !tc->ctc || !local) return EINVAL; TInetAddr ia(sa_in(local), sa_port(local)); return tc->ctc->Bind(ia); }
int tcp_sock_bind(struct tcp_sock *ts, const struct sa *local) { if (!ts || !ts->cts || !local) return EINVAL; TInetAddr ia(sa_in(local), sa_port(local)); return ts->cts->Bind(ia); }
int tcp_conn_connect(struct tcp_conn *tc, const struct sa *peer) { if (!tc || !tc->ctc || !sa_isset(peer, SA_ALL)) return EINVAL; tc->active = true; TInetAddr ia(sa_in(peer), sa_port(peer)); return tc->ctc->Connect(ia); }
int udp_sock::listen(const struct sa *local) { TInetAddr ia(sa_in(local), sa_port(local)); const TInt ret = cus->iSocket.Bind(ia); if (KErrNone != ret) return kerr2errno(ret); cus->StartReceiving(); return 0; }
static bool net_rt_handler(const char *ifname, const struct sa *dst, int dstlen, const struct sa *gw, void *arg) { (void)dstlen; (void)arg; if (sa_af(dst) != AF_INET) return false; if (sa_in(dst) == 0) { natpmp_srv = *gw; sa_set_port(&natpmp_srv, NATPMP_PORT); info("natpmp: found default gateway %j on interface '%s'\n", gw, ifname); return true; } return false; }
int udp_sock::send(const struct sa *dst, struct mbuf *mb) { struct sa hdst; TRequestStatus stat; int err = 0; DEBUG_INFO("udp_sock::send %u bytes to %J\n", mbuf_get_left(mb), dst); /* Check for error in e.g. connected state */ if (cerr) { err = cerr; cerr = 0; /* clear error */ return err; } /* call helpers in reverse order */ struct le *le = list_tail(&helpers); while (le) { struct udp_helper *uh; uh = (struct udp_helper *)le->data; le = le->prev; if (dst != &hdst) { sa_cpy(&hdst, dst); dst = &hdst; } if (uh->sendh(&err, &hdst, mb, uh->arg) || err) return err; } TInetAddr ia(sa_in(dst), sa_port(dst)); const TPtrC8 buf_tx(mb->buf + mb->pos, mb->end - mb->pos); if (conn) { cus->iSocket.Connect(ia, stat); User::WaitForRequest(stat); if (KErrNone != stat.Int()) { DEBUG_WARNING("udp_sock::send Connect: kerr=%d\n", stat.Int()); if (KErrGeneral == stat.Int()) return ECONNREFUSED; } #if 0 /* TODO: Cause Access-Violation in WINS emulator! */ cus->iSocket.Send(buf_tx, 0, stat); #else cus->iSocket.SendTo(buf_tx, ia, 0, stat); #endif } else { cus->iSocket.SendTo(buf_tx, ia, 0, stat); } User::WaitForRequest(stat); return kerr2errno(stat.Int()); }