?? net.h
字號:
/* * File: net.h * * An interface to the UDP/IP/Ethernet levels of a network stack. * * See Also * net.c -- an implemenation exposing the net.h interface. * * Copyright (C) 2002 RidgeRun, Inc. * Author: RidgeRun, Inc <skranz@ridgerun.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 675 Mass Ave, Cambridge, MA 02139, USA. * * Please report all bugs/problems to the author or <support@dsplinux.net> * * key: RRGPLCR (do not remove) * */#include "ether.h"#ifndef NET_H#define NET_H// Network Byte Order; page 69 "Internetworking With TCP/IP (3rd edition, vol 1)"#ifdef CPU_BIG_ENDIAN# define ntohl(x) (x)# define htonl(x) (x)# define ntohs(x) (x)# define htons(x) (x)#endif// Network Byte Order; page 69 "Internetworking With TCP/IP (3rd edition, vol 1)"#ifdef CPU_LITTLE_ENDIAN# define ntohl(x) __swap_32(x)# define htonl(x) __swap_32(x)# define ntohs(x) __swap_16(x)# define htons(x) __swap_16(x)#endif// Ethernet Packet Format; page 29 "Internetworking With TCP/IP (3rd edition, vol 1)"typedef struct { unsigned char dest_addr[6]; unsigned char src_addr[6]; unsigned short frame_type;} __attribute__ ((packed)) ether_hdr_t; // total bytes 14// IP Datagram Format; page 92 "Internetworking With TCP/IP (3rd edition, vol 1)"typedef struct { unsigned char vers_hlen; unsigned char serv_type; unsigned short tot_len; unsigned short ident; unsigned short flags_fragoffset; unsigned char timetolive; unsigned char protocol; unsigned short hdr_chksum; unsigned long src_IP_addr; unsigned long dest_IP_addr;} __attribute__ ((packed)) ip_hdr_t; // total bytes 20// UDP Datagram Format; page 181 "Internetworking With TCP/IP (3rd edition, vol 1)"typedef struct { unsigned short src_port; unsigned short dest_port; unsigned short tot_len; unsigned short chksum;} __attribute__ ((packed)) udp_hdr_t; // total bytes 8extern void udp_submit(submit_mode mode, // in unsigned short src_port, // in (local device port number). unsigned short dest_port, // in (remote server port number) char *device_IP, // in char *server_IP, // in char *device_MAC, // in, can be NULL only if our chipset has built in MAC. char *server_MAC, // in, can be NULL only if our net stack has ARP. void *datagram, // in/out unsigned short *num_bytes, // in/out unsigned short *reply_port);// out. // --udp_submit-- // Used by clients to send/receive datagrams to/from the // netstack which encompasses UDP/IP/EtherDrv. The // underlying implementation will construct and prepend // the necessary frame headers onto the front of the // client supplied datagram. For this reason it is // important that the client arrange that the bytes // directly proceeding the the *datagram buffer be // allocated and available for the udp_submit // function. sizeof(udp_hdr_t) + sizeof(ip_hdr_t) + // sizeof(ether_hdr_t) bytes.extern void net_init(void); // --net_init-- // Should be called once to initialize the underlying // implementation prior to using any of the supplied routines.#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -