3 * Linux INET implementation
6 * Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #include <linux/config.h>
15 #include <linux/types.h>
16 #include <linux/module.h>
21 #include <net/route.h>
22 #include <net/tcp_states.h>
24 int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
26 struct inet_sock *inet = inet_sk(sk);
27 struct sockaddr_in *usin = (struct sockaddr_in *) uaddr;
34 if (addr_len < sizeof(*usin))
37 if (usin->sin_family != AF_INET)
42 oif = sk->sk_bound_dev_if;
44 if (MULTICAST(usin->sin_addr.s_addr)) {
48 saddr = inet->mc_addr;
50 err = ip_route_connect(&rt, usin->sin_addr.s_addr, saddr,
51 RT_CONN_FLAGS(sk), oif,
53 inet->sport, usin->sin_port, sk);
56 if ((rt->rt_flags & RTCF_BROADCAST) && !sock_flag(sk, SOCK_BROADCAST)) {
61 inet->saddr = rt->rt_src; /* Update source address */
63 inet->rcv_saddr = rt->rt_src;
64 inet->daddr = rt->rt_dst;
65 inet->dport = usin->sin_port;
66 sk->sk_state = TCP_ESTABLISHED;
69 sk_dst_set(sk, &rt->u.dst);
73 EXPORT_SYMBOL(ip4_datagram_connect);