Annotation of embedaddon/coova-chilli/src/net.h, revision 1.1.1.1
1.1 misho 1: /*
2: * net library functions
3: * Copyright (c) 2008 David Bird <david@coova.com>
4: *
5: * The contents of this file may be used under the terms of the GNU
6: * General Public License Version 2, provided that the above copyright
7: * notice and this permission notice is included in all copies or
8: * substantial portions of the software.
9: *
10: */
11:
12:
13: #ifndef _NET_H
14: #define _NET_H
15:
16: #include "system.h"
17: #include "pkt.h"
18:
19: typedef struct _net_interface {
20: uint8_t idx;
21:
22: /* hardware/link */
23: uint16_t protocol;
24: uint8_t hwaddr[PKT_ETH_ALEN];
25: char devname[IFNAMSIZ+1];
26: int devflags;
27: int ifindex;
28: int mtu;
29:
30: /* network/address */
31: struct in_addr address;
32: struct in_addr gateway;
33: struct in_addr netmask;
34: struct in_addr broadcast;
35:
36: /* socket/descriptor */
37: int fd;
38:
39: uint8_t flags;
40: #define NET_PROMISC (1<<0)
41: #define NET_USEMAC (1<<1)
42: #define NET_ETHHDR (1<<2)
43: } net_interface;
44:
45:
46: #define net_sflags(n,f) dev_set_flags((n)->devname, (f))
47: #define net_gflags(n) dev_get_flags((n)->devname, &(n)->devflags)
48:
49: int net_open(net_interface *netif);
50: int net_open_eth(net_interface *netif);
51: int net_reopen(net_interface *netif);
52: int net_init(net_interface *netif, char *ifname, uint16_t protocol, int promisc, uint8_t *mac);
53: int net_route(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask, int delete);
54:
55: ssize_t net_read(net_interface *netif, void *d, size_t slen);
56: ssize_t net_write(net_interface *netif, void *d, size_t slen);
57:
58: #define fd_zero(fds) FD_ZERO((fds));
59: #define fd_set(fd,fds) if ((fd) > 0) FD_SET((fd), (fds))
60: #define fd_isset(fd,fds) ((fd) > 0) && FD_ISSET((fd), (fds))
61: #define fd_max(fd,max) (max) = (max) > (fd) ? (max) : (fd)
62:
63: #define net_maxfd(this,max) (max) = (max) > (this)->fd ? (max) : (this)->fd
64: #define net_fdset(this,fds) if ((this)->fd > 0) FD_SET((this)->fd, (fds))
65: #define net_isset(this,fds) ((this)->fd > 0) && FD_ISSET((this)->fd, (fds))
66: #define net_close(this) if ((this)->fd > 0) close((this)->fd); (this)->fd=0
67: #define net_add_route(dst,gw,mask) net_route(dst,gw,mask,0)
68: #define net_del_route(dst,gw,mask) net_route(dst,gw,mask,1)
69:
70: int dev_set_flags(char const *dev, int flags);
71: int dev_get_flags(char const *dev, int *flags);
72: int dev_set_addr(char const *devname, struct in_addr *addr,
73: struct in_addr *gateway, struct in_addr *netmask);
74:
75: int net_set_address(net_interface *netif, struct in_addr *address,
76: struct in_addr *gateway, struct in_addr *netmask);
77:
78: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>