]>
git.proxmox.com Git - mirror_frr.git/blob - lib/network.c
3 * Copyright (C) 1997 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "lib_errors.h"
27 /* Read nbytes from fd and store into ptr. */
28 int readn(int fd
, uint8_t *ptr
, int nbytes
)
36 nread
= read(fd
, ptr
, nleft
);
47 return nbytes
- nleft
;
50 /* Write nbytes from ptr to fd. */
51 int writen(int fd
, const uint8_t *ptr
, int nbytes
)
59 nwritten
= write(fd
, ptr
, nleft
);
62 if (!ERRNO_IO_RETRY(errno
))
71 return nbytes
- nleft
;
74 int set_nonblocking(int fd
)
78 /* According to the Single UNIX Spec, the return value for F_GETFL
81 flags
= fcntl(fd
, F_GETFL
);
83 flog_err(EC_LIB_SYSTEM_CALL
,
84 "fcntl(F_GETFL) failed for fd %d: %s", fd
,
85 safe_strerror(errno
));
88 if (fcntl(fd
, F_SETFL
, (flags
| O_NONBLOCK
)) < 0) {
89 flog_err(EC_LIB_SYSTEM_CALL
,
90 "fcntl failed setting fd %d non-blocking: %s", fd
,
91 safe_strerror(errno
));
97 int set_cloexec(int fd
)
100 flags
= fcntl(fd
, F_GETFD
, 0);
105 if (fcntl(fd
, F_SETFD
, flags
) == -1)
110 float htonf(float host
)
115 memcpy(&lu1
, &host
, sizeof(uint32_t));
117 memcpy(&convert
, &lu2
, sizeof(uint32_t));
121 float ntohf(float net
)