diff --git a/libnetutil/netutil.cc b/libnetutil/netutil.cc index 6f1938862..25463571f 100644 --- a/libnetutil/netutil.cc +++ b/libnetutil/netutil.cc @@ -1936,13 +1936,13 @@ static inline char* STRAPP(const char *fmt, ...) { * and returns a string containing an ASCII description of the options * found. The function returns a pointer to a static buffer that * subsequent calls will overwrite. On error, NULL is returned. */ -char *format_ip_options(u8* ipopt, int ipoptlen) { +char *format_ip_options(const u8* ipopt, int ipoptlen) { char ipstring[32]; int option_type = UNKNOWN;// option type int option_len = 0; // option length int option_pt = 0; // option pointer int option_fl = 0; // option flag - u8 *tptr; // temp pointer + const u8 *tptr; // temp pointer u32 *tint; // temp int int option_sta = 0; // option start offset @@ -3374,7 +3374,7 @@ int Sendto(const char *functionname, int sd, /* Send an IP packet over an ethernet handle. */ -int send_ip_packet_eth(struct eth_nfo *eth, u8 *packet, unsigned int packetlen) { +int send_ip_packet_eth(const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen) { eth_t *ethsd; u8 *eth_frame; int res; @@ -3398,7 +3398,7 @@ int send_ip_packet_eth(struct eth_nfo *eth, u8 *packet, unsigned int packetlen) /* Send an IP packet over a raw socket. */ -int send_ip_packet_sd(int sd, u8 *packet, unsigned int packetlen) { +int send_ip_packet_sd(int sd, const u8 *packet, unsigned int packetlen) { struct sockaddr_in sock; struct ip *ip = (struct ip *) packet; struct tcp_hdr *tcp; @@ -3455,7 +3455,8 @@ int send_ip_packet_sd(int sd, u8 *packet, unsigned int packetlen) { /* Sends the supplied pre-built IPv4 packet. The packet is sent through * the raw socket "sd" if "eth" is NULL. Otherwise, it gets sent at raw * ethernet level. */ -int send_ip_packet_eth_or_sd(int sd, struct eth_nfo *eth, u8 *packet, unsigned int packetlen){ +int send_ip_packet_eth_or_sd(int sd, const struct eth_nfo *eth, const u8 *packet, + unsigned int packetlen) { if(eth) return send_ip_packet_eth(eth, packet, packetlen); else @@ -3468,7 +3469,7 @@ int send_ip_packet_eth_or_sd(int sd, struct eth_nfo *eth, u8 *packet, unsigned i * Minimal MTU for IPv4 is 68 and maximal IPv4 header size is 60 * which gives us a right to cut TCP header after 8th byte * (shouldn't we inflate the header to 60 bytes too?) */ -int send_frag_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, +int send_frag_ip_packet(int sd, const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen, u32 mtu) { struct ip *ip = (struct ip *) packet; int headerlen = ip->ip_hl * 4; // better than sizeof(struct ip) @@ -3529,7 +3530,7 @@ int send_frag_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, */ /* Send an IPv6 packet over an Ethernet handle. */ -static int send_ipv6_eth(struct eth_nfo *eth, const u8 *packet, unsigned int packetlen) { +static int send_ipv6_eth(const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen) { eth_t *ethsd; struct eth_hdr *eth_frame; u8 *copy; @@ -3769,7 +3770,7 @@ bail: #endif /* For now, the sd argument is ignored. */ -int send_ipv6_packet_eth_or_sd(int sd, struct eth_nfo *eth, const u8 *packet, unsigned int packetlen) { +int send_ipv6_packet_eth_or_sd(int sd, const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen) { if (eth != NULL) { return send_ipv6_eth(eth, packet, packetlen); } else { diff --git a/libnetutil/netutil.h b/libnetutil/netutil.h index 14fc8c4d0..1ed45c40d 100644 --- a/libnetutil/netutil.h +++ b/libnetutil/netutil.h @@ -389,7 +389,7 @@ int isipprivate(const struct in_addr *const addr); * and returns a string containing an ASCII description of the options * found. The function returns a pointer to a static buffer that * subsequent calls will overwrite. On error, NULL is returned. */ -char *format_ip_options(u8* ipopt, int ipoptlen); +char *format_ip_options(const u8* ipopt, int ipoptlen); /* Returns a buffer of ASCII information about an IP packet that may * look like "TCP 127.0.0.1:50923 > 127.0.0.1:3 S ttl=61 id=39516 @@ -435,23 +435,23 @@ int route_dst(const struct sockaddr_storage * const dst, struct route_nfo *rnfo, const char *device, const struct sockaddr_storage *spoofss); /* Send an IP packet over a raw socket. */ -int send_ip_packet_sd(int sd, u8 *packet, unsigned int packetlen); +int send_ip_packet_sd(int sd, const u8 *packet, unsigned int packetlen); /* Send an IP packet over an ethernet handle. */ -int send_ip_packet_eth(struct eth_nfo *eth, u8 *packet, unsigned int packetlen); +int send_ip_packet_eth(const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen); /* Sends the supplied pre-built IPv4 packet. The packet is sent through * the raw socket "sd" if "eth" is NULL. Otherwise, it gets sent at raw * ethernet level. */ -int send_ip_packet_eth_or_sd(int sd, struct eth_nfo *eth, u8 *packet, unsigned int packetlen); +int send_ip_packet_eth_or_sd(int sd, const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen); /* Sends an IPv4 packet. */ -int send_ipv6_packet_eth_or_sd(int sd, struct eth_nfo *eth, const u8 *packet, unsigned int len); +int send_ipv6_packet_eth_or_sd(int sd, const struct eth_nfo *eth, const u8 *packet, unsigned int len); /* Create and send all fragments of a pre-built IPv4 packet. * Minimal MTU for IPv4 is 68 and maximal IPv4 header size is 60 * which gives us a right to cut TCP header after 8th byte */ -int send_frag_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, +int send_frag_ip_packet(int sd, const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen, u32 mtu); /* Wrapper for system function sendto(), which retries a few times when diff --git a/tcpip.cc b/tcpip.cc index fc39b2e03..2b402e271 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -453,7 +453,7 @@ struct addrinfo *resolve_all(char *hostname, int pf) /* Send a pre-built IPv4 packet. Handles fragmentation and whether to send with an ethernet handle or a socket. */ -static int send_ipv4_packet(int sd, struct eth_nfo *eth, u8 *packet, +static int send_ipv4_packet(int sd, const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen) { struct ip *ip = (struct ip *) packet; int res; @@ -474,8 +474,8 @@ static int send_ipv4_packet(int sd, struct eth_nfo *eth, u8 *packet, return res; } -static int send_ipv6_packet(int sd, struct eth_nfo *eth, const u8 *packet, - unsigned int packetlen) { +static int send_ipv6_packet(int sd, const struct eth_nfo *eth, const u8 *packet, + unsigned int packetlen){ int res; res = send_ipv6_packet_eth_or_sd(sd, eth, packet, packetlen); @@ -485,7 +485,7 @@ static int send_ipv6_packet(int sd, struct eth_nfo *eth, const u8 *packet, return res; } -int send_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, +int send_ip_packet(int sd, const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen) { struct ip *ip = (struct ip *) packet; @@ -752,7 +752,7 @@ u8 *build_tcp_raw_ipv6(const struct in6_addr *source, } /* You need to call sethdrinclude(sd) on the sending sd before calling this */ -int send_tcp_raw(int sd, struct eth_nfo *eth, +int send_tcp_raw(int sd, const struct eth_nfo *eth, const struct in_addr *source, const struct in_addr *victim, int ttl, bool df, u8 *ipops, int ipoptlen, u16 sport, u16 dport, u32 seq, @@ -776,7 +776,7 @@ int send_tcp_raw(int sd, struct eth_nfo *eth, return res; } -int send_tcp_raw_decoys(int sd, struct eth_nfo *eth, +int send_tcp_raw_decoys(int sd, const struct eth_nfo *eth, const struct in_addr *victim, int ttl, bool df, u8 *ipopt, int ipoptlen, @@ -871,7 +871,7 @@ u8 *build_udp_raw_ipv6(const struct in6_addr *source, return ipv6; } -int send_udp_raw(int sd, struct eth_nfo *eth, +int send_udp_raw(int sd, const struct eth_nfo *eth, struct in_addr *source, const struct in_addr *victim, int ttl, u16 ipid, u8 *ipopt, int ipoptlen, @@ -891,7 +891,7 @@ int send_udp_raw(int sd, struct eth_nfo *eth, return res; } -int send_udp_raw_decoys(int sd, struct eth_nfo *eth, +int send_udp_raw_decoys(int sd, const struct eth_nfo *eth, const struct in_addr *victim, int ttl, u16 ipid, u8 *ipops, int ipoptlen, diff --git a/tcpip.h b/tcpip.h index 83b7789a9..5c638ff50 100644 --- a/tcpip.h +++ b/tcpip.h @@ -421,7 +421,7 @@ unsigned short in_cksum(u16 *ptr,int nbytes); /* Send a pre-built IPv4 or IPv6 packet */ -int send_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, +int send_ip_packet(int sd, const struct eth_nfo *eth, const u8 *packet, unsigned int packetlen); /* Builds an IP packet (including an IP header) by packing the fields @@ -466,7 +466,7 @@ u8 *build_tcp_raw_ipv6(const struct in6_addr *source, /* Build and send a raw tcp packet. If TTL is -1, a partially random (but likely large enough) one is chosen */ -int send_tcp_raw( int sd, struct eth_nfo *eth, +int send_tcp_raw( int sd, const struct eth_nfo *eth, const struct in_addr *source, const struct in_addr *victim, int ttl, bool df, u8* ipopt, int ipoptlen, @@ -475,7 +475,7 @@ int send_tcp_raw( int sd, struct eth_nfo *eth, u8 *options, int optlen, char *data, u16 datalen); -int send_tcp_raw_decoys( int sd, struct eth_nfo *eth, +int send_tcp_raw_decoys( int sd, const struct eth_nfo *eth, const struct in_addr *victim, int ttl, bool df, u8* ipopt, int ipoptlen, @@ -502,14 +502,14 @@ u8 *build_udp_raw_ipv6(const struct in6_addr *source, u8 hoplimit, u16 sport, u16 dport, char *data, u16 datalen, u32 *packetlen); -int send_udp_raw( int sd, struct eth_nfo *eth, +int send_udp_raw( int sd, const struct eth_nfo *eth, struct in_addr *source, const struct in_addr *victim, int ttl, u16 ipid, u8* ipopt, int ipoptlen, u16 sport, u16 dport, char *data, u16 datalen); -int send_udp_raw_decoys( int sd, struct eth_nfo *eth, +int send_udp_raw_decoys( int sd, const struct eth_nfo *eth, const struct in_addr *victim, int ttl, u16 ipid, u8* ipops, int ip,