1 /* sockets.c. Rewriten by Andi Kleen. Subject to the GPL. */
3 /* philb 14/11/98: we now stash the socket file descriptor inside
4 the `aftype' structure rather than keeping it in a pile of separate
5 variables. This is necessary so that "ifconfig eth0 broadcast ..."
6 issues ioctls to the right socket for the address family in use;
7 picking one at random doesn't always work. */
9 #include <sys/socket.h>
17 #include "net-support.h"
19 int skfd
= -1; /* generic raw socket desc. */
21 int sockets_open(int family
)
25 static int force
= -1;
29 if (kernel_version() < KRELEASE(2, 1, 0))
31 if (access("/proc/net", R_OK
))
34 for (aft
= aftypes
; *aft
; aft
++) {
35 struct aftype
*af
= *aft
;
36 int type
= SOCK_DGRAM
;
37 if (af
->af
== AF_UNSPEC
)
39 if (family
&& family
!= af
->af
)
45 /* Check some /proc file first to not stress kmod */
46 if (!family
&& !force
&& af
->flag_file
) {
47 if (access(af
->flag_file
, R_OK
))
51 if (af
->af
== AF_NETROM
)
52 type
= SOCK_SEQPACKET
;
56 type
= SOCK_SEQPACKET
;
58 af
->fd
= socket(af
->af
, type
, 0);
63 fprintf(stderr
, _("No usable address families found.\n"));