Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (17 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/networking/libiproute/libnetlink.c

    r821 r1765  
     1/* vi: set sw=4 ts=4: */
    12/*
    23 * libnetlink.c RTnetlink service routines.
     
    1112 */
    1213
     14#include <sys/socket.h>
     15#include <sys/uio.h>
     16
    1317#include "libbb.h"
    14 #include <sys/socket.h>
    15 
    16 #include <errno.h>
    17 #include <string.h>
    18 #include <time.h>
    19 #include <unistd.h>
    20 
    21 #include <sys/uio.h>
    22 
    2318#include "libnetlink.h"
    2419
     
    2823}
    2924
    30 int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
     25int xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/)
    3126{
    3227    socklen_t addr_len;
     
    3429    memset(rth, 0, sizeof(rth));
    3530
    36     rth->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
    37     if (rth->fd < 0) {
    38         bb_perror_msg("Cannot open netlink socket");
    39         return -1;
    40     }
     31    rth->fd = xsocket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
    4132
    4233    memset(&rth->local, 0, sizeof(rth->local));
    4334    rth->local.nl_family = AF_NETLINK;
    44     rth->local.nl_groups = subscriptions;
    45 
    46     if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) {
    47         bb_perror_msg("Cannot bind netlink socket");
    48         return -1;
    49     }
     35    /*rth->local.nl_groups = subscriptions;*/
     36
     37    xbind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local));
    5038    addr_len = sizeof(rth->local);
    51     if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) {
    52         bb_perror_msg("Cannot getsockname");
    53         return -1;
    54     }
    55     if (addr_len != sizeof(rth->local)) {
    56         bb_error_msg("Wrong address length %d", addr_len);
    57         return -1;
    58     }
    59     if (rth->local.nl_family != AF_NETLINK) {
    60         bb_error_msg("Wrong address family %d", rth->local.nl_family);
    61         return -1;
    62     }
     39    if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0)
     40        bb_perror_msg_and_die("cannot getsockname");
     41    if (addr_len != sizeof(rth->local))
     42        bb_error_msg_and_die("wrong address length %d", addr_len);
     43    if (rth->local.nl_family != AF_NETLINK)
     44        bb_error_msg_and_die("wrong address family %d", rth->local.nl_family);
    6345    rth->seq = time(NULL);
    6446    return 0;
    6547}
    6648
    67 int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
     49int xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
    6850{
    6951    struct {
     
    8365    req.g.rtgen_family = family;
    8466
    85     return sendto(rth->fd, (void*)&req, sizeof(req), 0, (struct sockaddr*)&nladdr, sizeof(nladdr));
     67    return xsendto(rth->fd, (void*)&req, sizeof(req),
     68                 (struct sockaddr*)&nladdr, sizeof(nladdr));
    8669}
    8770
     
    9376    nladdr.nl_family = AF_NETLINK;
    9477
    95     return sendto(rth->fd, buf, len, 0, (struct sockaddr*)&nladdr, sizeof(nladdr));
     78    return xsendto(rth->fd, buf, len, (struct sockaddr*)&nladdr, sizeof(nladdr));
    9679}
    9780
     
    120103}
    121104
    122 int rtnl_dump_filter(struct rtnl_handle *rth,
    123              int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
    124              void *arg1,
    125              int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
    126              void *arg2)
    127 {
    128     char    buf[8192];
     105static int rtnl_dump_filter(struct rtnl_handle *rth,
     106        int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
     107        void *arg1/*,
     108        int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
     109        void *arg2*/)
     110{
     111    char buf[8192];
    129112    struct sockaddr_nl nladdr;
    130113    struct iovec iov = { buf, sizeof(buf) };
     
    164147                h->nlmsg_pid != rth->local.nl_pid ||
    165148                h->nlmsg_seq != rth->dump) {
    166                 if (junk) {
     149/*              if (junk) {
    167150                    err = junk(&nladdr, h, arg2);
    168                     if (err < 0) {
     151                    if (err < 0)
    169152                        return err;
    170                     }
    171                 }
     153                } */
    172154                goto skip_it;
    173155            }
     
    187169            }
    188170            err = filter(&nladdr, h, arg1);
    189             if (err < 0) {
     171            if (err < 0)
    190172                return err;
    191             }
    192173
    193174skip_it:
     
    195176        }
    196177        if (msg.msg_flags & MSG_TRUNC) {
    197             bb_error_msg("Message truncated");
     178            bb_error_msg("message truncated");
    198179            continue;
    199180        }
    200181        if (status) {
    201             bb_error_msg_and_die("!!!Remnant of size %d", status);
    202         }
    203     }
     182            bb_error_msg_and_die("remnant of size %d!", status);
     183        }
     184    }
     185}
     186
     187int xrtnl_dump_filter(struct rtnl_handle *rth,
     188        int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
     189        void *arg1)
     190{
     191    int ret = rtnl_dump_filter(rth, filter, arg1/*, NULL, NULL*/);
     192    if (ret < 0)
     193        bb_error_msg_and_die("dump terminated");
     194    return ret;
    204195}
    205196
     
    234225
    235226    if (status < 0) {
    236         bb_perror_msg("Cannot talk to rtnetlink");
     227        bb_perror_msg("cannot talk to rtnetlink");
    237228        return -1;
    238229    }
     
    265256            if (l<0 || len>status) {
    266257                if (msg.msg_flags & MSG_TRUNC) {
    267                     bb_error_msg("Truncated message");
     258                    bb_error_msg("truncated message");
    268259                    return -1;
    269260                }
    270                 bb_error_msg_and_die("!!!malformed message: len=%d", len);
     261                bb_error_msg_and_die("malformed message: len=%d!", len);
    271262            }
    272263
     
    304295            }
    305296
    306             bb_error_msg("Unexpected reply!!!");
     297            bb_error_msg("unexpected reply!");
    307298
    308299            status -= NLMSG_ALIGN(len);
     
    310301        }
    311302        if (msg.msg_flags & MSG_TRUNC) {
    312             bb_error_msg("Message truncated");
     303            bb_error_msg("message truncated");
    313304            continue;
    314305        }
    315306        if (status) {
    316             bb_error_msg_and_die("!!!Remnant of size %d", status);
    317         }
    318     }
    319 }
    320 
    321 int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
     307            bb_error_msg_and_die("remnant of size %d!", status);
     308        }
     309    }
     310}
     311
     312int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
    322313{
    323314    int len = RTA_LENGTH(4);
     
    348339}
    349340
    350 int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)
     341int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data)
    351342{
    352343    int len = RTA_LENGTH(4);
     
    390381    }
    391382    if (len) {
    392         bb_error_msg("!!!Deficit %d, rta_len=%d", len, rta->rta_len);
    393     }
    394     return 0;
    395 }
     383        bb_error_msg("deficit %d, rta_len=%d!", len, rta->rta_len);
     384    }
     385    return 0;
     386}
Note: See TracChangeset for help on using the changeset viewer.