OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [userland/] [route/] [lib/] [sockets.c] - Blame information for rev 745

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/* sockets.c. Rewriten by Andi Kleen. Subject to the GPL. */
2
 
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.  */
8
 
9
#include <sys/socket.h>
10
#include <stdio.h>
11
#include <unistd.h>
12
 
13
#include "config.h"
14
#include "sockets.h"
15
#include "intl.h"
16
#include "util.h"
17
#include "net-support.h"
18
 
19
#ifndef EMBED
20
int skfd = -1;                  /* generic raw socket desc.     */
21
#endif
22
 
23
int sockets_open(int family)
24
{
25
    struct aftype **aft;
26
    int sfd = -1;
27
    static int force = -1;
28
 
29
    if (force < 0) {
30
        force = 0;
31
        if (kernel_version() < KRELEASE(2, 1, 0))
32
            force = 1;
33
        if (access("/proc/net", R_OK))
34
            force = 1;
35
    }
36
    for (aft = aftypes; *aft; aft++) {
37
        struct aftype *af = *aft;
38
        int type = SOCK_DGRAM;
39
        if (af->af == AF_UNSPEC)
40
            continue;
41
        if (family && family != af->af)
42
            continue;
43
        if (af->fd != -1) {
44
            sfd = af->fd;
45
            continue;
46
        }
47
        /* Check some /proc file first to not stress kmod */
48
        if (!family && !force && af->flag_file) {
49
            if (access(af->flag_file, R_OK))
50
                continue;
51
        }
52
#if HAVE_AFNETROM
53
        if (af->af == AF_NETROM)
54
            type = SOCK_SEQPACKET;
55
#endif
56
        af->fd = socket(af->af, type, 0);
57
        if (af->fd >= 0)
58
            sfd = af->fd;
59
    }
60
    if (sfd < 0)
61
        fprintf(stderr, _("No usable address families found.\n"));
62
    return sfd;
63
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.