--- syslog_deluxe.c.orig Fri Jun 22 12:08:55 2007 +++ syslog_deluxe.c Fri Jun 22 12:46:18 2007 @@ -24,6 +24,11 @@ */ +/* This is the *BSD adaptation...will it work? +Rocco Lucia http://alice.iscanet.com/~rlucia/devel/patches/syslog_deluxe.diff + +*/ + #include #include #include @@ -31,8 +36,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -45,15 +52,15 @@ char message[] = {"telnetd[4489]: connection from devil@hell.org.universe\n"}; struct raw_pkt_hdr { - struct iphdr ip; /* This is Linux-style iphdr. - Use BSD-style struct ip if you want */ + struct ip ip; /* ..and this is BSD way */ + struct udphdr udp; }; struct raw_pkt_hdr* pkt; void die(char *); -unsigned long int get_ip_addr(char*); +in_addr_t get_ip_addr(char*); unsigned short checksum(unsigned short*,char); int main(int argc,char** argv){ @@ -80,23 +87,21 @@ packet_len = sizeof(struct raw_pkt_hdr)+strlen(message)+4; pkt = calloc((size_t)1,(size_t)packet_len); -pkt->ip.version = IPVERSION; -pkt->ip.ihl = sizeof(struct iphdr) >> 2; -pkt->ip.tos = 0; -pkt->ip.tot_len = htons(packet_len); -pkt->ip.id = htons(getpid() & 0xFFFF); -pkt->ip.frag_off = 0; -pkt->ip.ttl = 0x40; -pkt->ip.protocol = IPPROTO_UDP; -pkt->ip.check = 0; -pkt->ip.saddr = get_ip_addr(argv[1]); -pkt->ip.daddr = sa.sin_addr.s_addr; -pkt->ip.check = checksum((unsigned short*)pkt,sizeof(struct iphdr)); - -pkt->udp.source = htons(514); -pkt->udp.dest = htons(514); -pkt->udp.len = htons(packet_len - sizeof(struct iphdr)); -pkt->udp.check = 0; /* If you feel like screwing around with pseudo-headers +pkt->ip.ip_v = IPVERSION; +pkt->ip.ip_hl = sizeof(struct ip) >> 2; +pkt->ip.ip_tos = 0; +pkt->ip.ip_len = htons(packet_len); +pkt->ip.ip_id = 0; +pkt->ip.ip_off = 0; +pkt->ip.ip_ttl = 0x40; +pkt->ip.ip_p = IPPROTO_UDP; +pkt->ip.ip_sum = 0; +pkt->ip.ip_src.s_addr = get_ip_addr(argv[1]); +pkt->ip.ip_dst.s_addr = sa.sin_addr.s_addr; +pkt->ip.ip_sum = checksum((unsigned short*)pkt,sizeof(struct ip)); + +pkt->udp.uh_ulen = htons(packet_len - sizeof(struct ip)); +pkt->udp.uh_sum = 0; /* If you feel like screwing around with pseudo-headers and stuff, you may of course calculate UDP checksum as well. I chose to leave it zero, it's usually OK */ @@ -120,12 +125,12 @@ exit(1); } -unsigned long int get_ip_addr(char* str){ +in_addr_t get_ip_addr(char* str){ struct hostent *hostp; -unsigned long int addr; +struct in_addr addr; -if( (addr = inet_addr(str)) == -1){ +if( (addr.s_addr = inet_addr(str)) == -1){ if( (hostp = gethostbyname(str))) return *(unsigned long int*)(hostp->h_addr); else { @@ -133,7 +138,7 @@ exit(1); } } -return addr; +return addr.s_addr; } unsigned short checksum(unsigned short* addr,char len){ @@ -148,4 +153,3 @@ return ~sum; } -