udp_gen.c
上传用户:bobuwen
上传日期:2007-01-07
资源大小:10k
文件大小:1k
- /* RAW socket utility routine:
- *
- * Write out a UDP header.
- * shadows@whitefang.com
- * Thamer Al-Herbish
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <netinet/in_systm.h>
- #include <netinet/udp.h>
- #include <unistd.h>
- #include <strings.h>
- void udp_gen(char *packet,unsigned short sport,
- unsigned short dport,unsigned short length)
- {
- struct udphdr *udp;
-
- udp = (struct udphdr *)packet;
- #if !defined(LINUX)
- udp->uh_sport = htons(sport);
- udp->uh_dport = htons(dport);
- udp->uh_ulen = htons(length);
- udp->uh_sum = 0;
-
- #else /* LINUX */
- udp->source = htons(sport);
- udp->dest = htons(dport);
- udp->len = htons(length);
- udp->check = 0;
- #endif /* LINUX */
-
- return;
- }