xilnet库的头文件都在%EDK%/sw/lib/sw_services/xilnet_v2_00_a/src/include/文件夹下,我们在文件中经常看到的被引用的头文件写成 #include <net/xilsock.h> 这种样子,意思就是说包含进include中net文件夹下面的xilsock.h头文件,以此类推。
另外,分析一下在xilnet中最常用的一个位域:
struct xilsock_socket {
int type;
int domain;
int proto;
// status of socket
unsigned char listen:1;
unsigned char bound:1;
unsigned char accept:1;
unsigned char connect:1;
unsigned char free:1;
unsigned char closing:1;
unsigned char closed:1;
union {
struct xilnet_tcp_conn *tcp_conn;
struct xilnet_udp_conn *udp_conn;
} conn;
还有一个数组:
#define NO_OF_XILSOCKS (MAX_TCP_CONNS+MAX_UDP_CONNS)
extern struct xilsock_socket xilsock_sockets[NO_OF_XILSOCKS];
(这个数组声明为extern,因此在自己的程序中会经常被用到)
另外还有一个结构体是经常要用的:
struct xilsock_buf {
unsigned char *buf;
int size;
};
值得注意的是有一个函数在EDK OS and Libraries Reference Guide中没有提到,可是在xilsock.h中被声明了,而且也很常用:
extern int xilsock_listen(int, int);
其它常用函数还包括:
extern int xilsock_init(void);
extern void xilsock_rel_socket(int);
extern int xilsock_socket(int, int, int);
extern int xilsock_bind(int, struct sockaddr*, int);
extern int xilsock_accept(int, struct sockaddr*, int*);
extern int xilsock_recv(int, unsigned char*, unsigned int);
extern int xilsock_recvfrom(int, unsigned char*, unsigned int, struct sockaddr* from, unsigned int *fromlen);
extern int xilsock_sendto(int, unsigned char*, unsigned int, struct sockaddr* to, unsigned int tolen);
extern int xilsock_send(int, unsigned char*, unsigned int);
extern void xilsock_close(int);
// Ethernet functions
extern int xilnet_eth_recv_frame(unsigned char *, int);
extern int xilnet_eth_send_frame(unsigned char *, int, unsigned char*, void*, unsigned short);
extern void xilnet_eth_update_hw_tbl(unsigned char *, int);
extern void xilnet_add_hw_tbl_entry(unsigned char *, unsigned char *);
extern int xilnet_eth_get_hw_addr(unsigned char *);
extern void xilnet_eth_init_hw_addr_tbl(void);
extern int xilnet_eth_find_old_entry(void);
还用诸如ARP functions、TCP/UDP/ICMP functions等函数也都声明成了extern,可以直接调用。
几个extern类型的常用数组、变量:
/* buffers for sending and receiving packets */
extern unsigned char recvbuf[];
extern unsigned char sendbuf[];
extern unsigned char mb_ip_addr[IP_VERSION];
extern unsigned char mb_hw_addr[ETH_ADDR_LEN];
extern int xilsock_status_flag;