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/types.h>
15 #include <linux/module.h>
20 #include <net/route.h>
21 #include <net/tcp_states.h>
23 int ip4_datagram_connect(struct sock
*sk
, struct sockaddr
*uaddr
, int addr_len
)
25 struct inet_sock
*inet
= inet_sk(sk
);
26 struct sockaddr_in
*usin
= (struct sockaddr_in
*) uaddr
;
33 if (addr_len
< sizeof(*usin
))
36 if (usin
->sin_family
!= AF_INET
)
41 oif
= sk
->sk_bound_dev_if
;
43 if (ipv4_is_multicast(usin
->sin_addr
.s_addr
)) {
47 saddr
= inet
->mc_addr
;
49 err
= ip_route_connect(&rt
, usin
->sin_addr
.s_addr
, saddr
,
50 RT_CONN_FLAGS(sk
), oif
,
52 inet
->sport
, usin
->sin_port
, sk
, 1);
54 if (err
== -ENETUNREACH
)
55 IP_INC_STATS_BH(sock_net(sk
), IPSTATS_MIB_OUTNOROUTES
);
59 if ((rt
->rt_flags
& RTCF_BROADCAST
) && !sock_flag(sk
, SOCK_BROADCAST
)) {
64 inet
->saddr
= rt
->rt_src
; /* Update source address */
66 inet
->rcv_saddr
= rt
->rt_src
;
67 inet
->daddr
= rt
->rt_dst
;
68 inet
->dport
= usin
->sin_port
;
69 sk
->sk_state
= TCP_ESTABLISHED
;
72 sk_dst_set(sk
, &rt
->u
.dst
);
76 EXPORT_SYMBOL(ip4_datagram_connect
);