📄 tcpip.h
字号:
finished with the packet. The packet length is returned in packetlen, which must be a valid int pointer. */u8 *build_tcp_raw(const struct in_addr *source, const struct in_addr *victim, int ttl, u16 ipid, u8 tos, bool df, u8* ipopt, int ipoptlen, u16 sport, u16 dport, u32 seq, u32 ack, u8 reserved, u8 flags, u16 window, u16 urp, u8 *options, int optlen, char *data, u16 datalen, u32 *packetlen);/* Builds a UDP packet (including an IP header) by packing the fields with the given information. It allocates a new buffer to store the packet contents, and then returns that buffer. The packet is not actually sent by this function. Caller must delete the buffer when finished with the packet. The packet length is returned in packetlen, which must be a valid int pointer. */u8 *build_udp_raw(struct in_addr *source, const struct in_addr *victim, int ttl, u16 ipid, u8 tos, bool df, u8* ipopt, int ipoptlen, u16 sport, u16 dport, char *data, u16 datalen, u32 *packetlen);/* Builds an ICMP packet (including an IP header) by packing the fields with the given information. It allocates a new buffer to store the packet contents, and then returns that buffer. The packet is not actually sent by this function. Caller must delete the buffer when finished with the packet. The packet length is returned in packetlen, which must be a valid int pointer. The id/seq will be converted to network byte order (if it differs from HBO) */u8 *build_icmp_raw(const struct in_addr *source, const struct in_addr *victim, int ttl, u16 ipid, u8 tos, bool df, u8* ipopt, int ipoptlen, u16 seq, unsigned short id, u8 ptype, u8 pcode, char *data, u16 datalen, u32 *packetlen);/* Builds an IGMP packet (including an IP header) by packing the fields with the given information. It allocates a new buffer to store the packet contents, and then returns that buffer. The packet is not actually sent by this function. Caller must delete the buffer when finished with the packet. The packet length is returned in packetlen, which must be a valid int pointer. */u8 *build_igmp_raw(const struct in_addr *source, const struct in_addr *victim, int ttl, u16 ipid, u8 tos, bool df, u8* ipopt, int ipoptlen, u8 ptype, u8 pcode, char *data, u16 datalen, u32 *packetlen);/* Builds an IP packet (including an IP header) by packing the fields with the given information. It allocates a new buffer to store the packet contents, and then returns that buffer. The packet is not actually sent by this function. Caller must delete the buffer when finished with the packet. The packet length is returned in packetlen, which must be a valid int pointer. */u8 *build_ip_raw(const struct in_addr *source, const struct in_addr *victim, u8 proto, int ttl, u16 ipid, u8 tos, bool df, u8* ipopt, int ipoptlen, char *data, u16 datalen, u32 *packetlen);/* Send a pre-built IPv4 packet */int send_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, unsigned int packetlen);/* Decoy versions of the raw packet sending functions ... */int send_tcp_raw_decoys( int sd, struct eth_nfo *eth, const struct in_addr *victim, int ttl, bool df, u8* ipopt, int ipoptlen, u16 sport, u16 dport, u32 seq, u32 ack, u8 reserved, u8 flags, u16 window, u16 urp, u8 *options, int optlen, char *data, u16 datalen);int send_udp_raw_decoys( int sd, struct eth_nfo *eth, const struct in_addr *victim, int ttl, u16 ipid, u8* ipops, int ip, u16 sport, u16 dport, char *data, u16 datalen);/* Calls pcap_open_live and spits out an error (and quits) if the call fails. So a valid pcap_t will always be returned. */pcap_t *my_pcap_open_live(const char *device, int snaplen, int promisc, int to_ms);// Returns whether the system supports pcap_get_selectable_fd() properlybool pcap_selectable_fd_valid();/* Call this instead of pcap_get_selectable_fd directly (or your code won't compile on Windows). On systems which don't seem to support the pcap_get_selectable_fd() function properly, returns -1, otherwise simply calls pcap_selectable_fd and returns the results. If you just want to test whether the function is supported, use pcap_selectable_fd_valid() instead. */int my_pcap_get_selectable_fd(pcap_t *p);// Returns whether the packet receive time value obtaned from libpcap// (and thus by readip_pcap()) should be considered valid. When// invalid (Windows and Amiga), readip_pcap returns the time you called it.bool pcap_recv_timeval_valid();/* Prints stats from a pcap descriptor (number of received and dropped packets). */void pcap_print_stats(int logt, pcap_t *pd);/* A simple function that caches the eth_t from dnet for one device, to avoid opening, closing, and re-opening it thousands of tims. If you give a different device, this function will close the first one. Thus this should never be used by programs that need to deal with multiple devices at once. In addition, you MUST NEVER eth_close() A DEVICE OBTAINED FROM THIS FUNCTION. Instead, you can call eth_close_cached() to close whichever device (if any) is cached. Returns NULL if it fails to open the device. */eth_t *eth_open_cached(const char *device);/* See the description for eth_open_cached */void eth_close_cached();/* A simple function I wrote to help in debugging, shows the important fields of a TCP packet*/int readtcppacket(const u8 *packet, int readdata);int readudppacket(const u8 *packet, int readdata);/* Convert an IP address to the device (IE ppp0 eth0) using that address. Dev passed in must be at least 32 bytes long */int ipaddr2devname( char *dev, const struct in_addr *addr );/* And vice versa */int devname2ipaddr(char *dev, struct in_addr *addr);/* Looks for an interface assigned to the given IP (ss), and returns the interface_info for the first one found. If non found, returns NULL */struct interface_info *getInterfaceByIP(struct sockaddr_storage *ss);/* Looks for an interface with the given name (iname), and returns the corresponding interface_info if found. Will accept a match of devname or devfullname. Returns NULL if none found */struct interface_info *getInterfaceByName(char *iname);/* Where the above 4 functions get their info */struct interface_info *getinterfaces(int *howmany);pcap_if_t *getpcapinterfaces();/* Parse the system routing table, converting each route into a sys_route entry. Returns an array of sys_routes. numroutes is set to the number of routes in the array. The routing table is only read the first time this is called -- later results are cached. The returned route array is sorted by netmask with the most specific matches first. */struct sys_route *getsysroutes(int *howmany);void sethdrinclude(int sd);void set_ttl(int sd, int ttl);/* Fill buf (up to buflen -- truncate if necessary but always terminate) with a short representation of the packet stats. Returns buf. Aborts if there is a problem. */char *getFinalPacketStats(char *buf, int buflen);/* This function tries to determine the target's ethernet MAC address from a received packet as follows: 1) If linkhdr is an ethernet header, grab the src mac (otherwise give up) 2) If overwrite is 0 and a MAC is already set for this target, give up. 3) If the packet source address is not the target, give up. 4) Use the routing table to try to determine rather target is directly connected to the src host running Nmap. If it is, set the MAC. This function returns 0 if it ends up setting the MAC, nonzero otherwise This function assumes that ip has already been verified as containing a complete IP header (or at least the first 20 bytes).*/ int setTargetMACIfAvailable(Target *target, struct link_header *linkhdr, struct ip *ip, int overwrite);/* This function ensures that the next hop MAC address for a target is filled in. This address is the target's own MAC if it is directly connected, and the next hop mac otherwise. Returns true if the address is set when the function ends, false if not. This function firt checks if it is already set, if not it tries the arp cache, and if that fails it sends an ARP request itself. This should be called after an ARP scan if many directly connected machines are involved. */bool setTargetNextHopMAC(Target *target);int islocalhost(const struct in_addr * const addr);int isipprivate(const struct in_addr * const addr);int unblock_socket(int sd);// Takes a protocol number like IPPROTO_TCP, IPPROTO_UDP, or// IPPROTO_IP and returns a ascii representation (or "unknown" if it// doesn't recognize the number). If uppercase is true, the returned// value will be in all uppercase letters. You can skip this// parameter to use lowercase.const char *proto2ascii(u8 proto, bool uppercase=false);/* Hex dump */int get_link_offset(char *device);/* If rcvdtime is non-null and a packet is returned, rcvd will be filled with the time that packet was captured from the wire by pcap. If linknfo is not NULL, lnknfo->headerlen and lnkinfo->header will be filled with the appropriate values. */char *readip_pcap(pcap_t *pd, unsigned int *len, long to_usec, struct timeval *rcvdtime, struct link_header *linknfo);/* Attempts to read one IPv4/Ethernet ARP reply packet from the pcap descriptor pd. If it receives one, fills in sendermac (must pass in 6 bytes), senderIP, and rcvdtime (can be NULL if you don't care) and returns 1. If it times out and reads no arp requests, returns 0. to_usec is the timeout period in microseconds. Use 0 to avoid blocking to the extent possible, and -1 to block forever. Returns -1 or exits if ther is an error. */int read_arp_reply_pcap(pcap_t *pd, u8 *sendermac, struct in_addr *senderIP, long to_usec, struct timeval *rcvdtime);/* Examines the given tcp packet and obtains the TCP timestamp option information if available. Note that the CALLER must ensure that "tcp" contains a valid header (in particular the th_off must be the true packet length and tcp must contain it). If a valid timestamp option is found in the header, nonzero is returned and the 'timestamp' and 'echots' parameters are filled in with the appropriate value (if non-null). Otherwise 0 is returned and the parameters (if non-null) are filled with 0. Remember that the correct way to check for errors is to look at the return value since a zero ts or echots could possibly be valid. */int gettcpopt_ts(struct tcp_hdr *tcp, u32 *timestamp, u32 *echots);/* Maximize the receive buffer of a socket descriptor (up to 500K) */void max_rcvbuf(int sd);/* Maximize the open file descriptor limit for this process go up to the max allowed */int max_sd();/* Convert a socket to blocking mode */int block_socket(int sd);/* Give broadcast permission to a socket */void broadcast_socket(int sd);/* Do a receive (recv()) on a socket and stick the results (upt to len) into buf . Give up after 'seconds'. Returns the number of bytes read (or -1 in the case of an error. It only does one recv (it will not keep going until len bytes are read). If timedout is not NULL, it will be set to zero (no timeout occured) or 1 (it did). */int recvtime(int sd, char *buf, int len, int seconds, int *timedout);/* Sets a pcap filter function -- makes SOCK_RAW reads easier */#ifndef WINIP_Hvoid set_pcap_filter(const char *device, pcap_t *pd, char *bpf, ...);#endif#endif /*TCPIP_H*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -