#if (HAVE_CONFIG_H)
#include "../include/config.h"
#endif
#include "libnet.h"
#include <assert.h>
int
main(int argc, char *argv[])
{
libnet_t *l;
int r;
char *device = "eth0";
char errbuf[LIBNET_ERRBUF_SIZE];
libnet_ptag_t ip_ptag = 0;
libnet_ptag_t eth_ptag = 0;
int pkt1_payload = 10;
uint8_t* pkt1 = NULL;
uint32_t pkt1_sz = 0;
struct libnet_ipv4_hdr* h1;
int pkt2_payload = 2;
uint8_t* pkt2 = NULL;
uint32_t pkt2_sz = 0;
struct libnet_ipv4_hdr* h2;
l = libnet_init( LIBNET_RAW4, device, errbuf);
assert(l);
printf("Packet 1:\n");
u_long dst_ip;
char* dst = "224.1.1.1";
if ((dst_ip = libnet_name2addr4(l, dst, LIBNET_RESOLVE)) == -1)
{
fprintf(stderr, "Bad destination IP address: %s\n", dst);
exit(EXIT_FAILURE);
}
u_long src_ip;
char* src = "192.168.100.10";
if ((src_ip = libnet_name2addr4(l, src, LIBNET_RESOLVE)) == -1)
{
fprintf(stderr, "Bad destination IP address: %s\n", dst);
exit(EXIT_FAILURE);
}
int ret = libnet_build_igmp(IGMP_V2_MEMBERSHIP_REPORT, 0, 0, dst_ip, NULL, 0, l, 0);
if(ret == -1)
{
printf("build failed\n");
}
/*
* Write it to the wire.
*/
r = libnet_build_ipv4(
LIBNET_IPV4_H + LIBNET_IGMP_H , /* length */
0, /* TOS */
0x42, /* IP ID */
0, /* IP Frag */
64, /* TTL */
IPPROTO_IGMP, /* protocol */
0, /* checksum */
src_ip, /* source IP */
dst_ip, /* destination IP */
NULL, /* payload */
0, /* payload size */
l, /* libnet handle */
0);
if (r == -1)
{
fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
goto bad;
}
printf("begin write\n");
r = libnet_write(l);
if (r == -1)
{
fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
goto bad;
}
else
{
fprintf(stderr, "Wrote %d byte IP packet; check the wire.\n", r);
}
libnet_destroy(l);
return (EXIT_SUCCESS);
bad:
libnet_destroy(l);
return (EXIT_FAILURE);
}
#include "../include/config.h"
#endif
#include "libnet.h"
#include <assert.h>
int
main(int argc, char *argv[])
{
libnet_t *l;
int r;
char *device = "eth0";
char errbuf[LIBNET_ERRBUF_SIZE];
libnet_ptag_t ip_ptag = 0;
libnet_ptag_t eth_ptag = 0;
int pkt1_payload = 10;
uint8_t* pkt1 = NULL;
uint32_t pkt1_sz = 0;
struct libnet_ipv4_hdr* h1;
int pkt2_payload = 2;
uint8_t* pkt2 = NULL;
uint32_t pkt2_sz = 0;
struct libnet_ipv4_hdr* h2;
l = libnet_init( LIBNET_RAW4, device, errbuf);
assert(l);
printf("Packet 1:\n");
u_long dst_ip;
char* dst = "224.1.1.1";
if ((dst_ip = libnet_name2addr4(l, dst, LIBNET_RESOLVE)) == -1)
{
fprintf(stderr, "Bad destination IP address: %s\n", dst);
exit(EXIT_FAILURE);
}
u_long src_ip;
char* src = "192.168.100.10";
if ((src_ip = libnet_name2addr4(l, src, LIBNET_RESOLVE)) == -1)
{
fprintf(stderr, "Bad destination IP address: %s\n", dst);
exit(EXIT_FAILURE);
}
int ret = libnet_build_igmp(IGMP_V2_MEMBERSHIP_REPORT, 0, 0, dst_ip, NULL, 0, l, 0);
if(ret == -1)
{
printf("build failed\n");
}
/*
* Write it to the wire.
*/
r = libnet_build_ipv4(
LIBNET_IPV4_H + LIBNET_IGMP_H , /* length */
0, /* TOS */
0x42, /* IP ID */
0, /* IP Frag */
64, /* TTL */
IPPROTO_IGMP, /* protocol */
0, /* checksum */
src_ip, /* source IP */
dst_ip, /* destination IP */
NULL, /* payload */
0, /* payload size */
l, /* libnet handle */
0);
if (r == -1)
{
fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
goto bad;
}
printf("begin write\n");
r = libnet_write(l);
if (r == -1)
{
fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
goto bad;
}
else
{
fprintf(stderr, "Wrote %d byte IP packet; check the wire.\n", r);
}
libnet_destroy(l);
return (EXIT_SUCCESS);
bad:
libnet_destroy(l);
return (EXIT_FAILURE);
}